Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38aae90

Browse files
committed
Welcome new members
1 parent ae12a98 commit 38aae90

File tree

7 files changed

+4334
-16
lines changed

7 files changed

+4334
-16
lines changed

dist/commands/poll.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ const NUMBER_EMOJIES = [
2626
];
2727
function pollCommand(match, message) {
2828
return __awaiter(this, void 0, void 0, function* () {
29-
const hasOptions = new RegExp("--options", "i").test(match[1]);
30-
const pollQuestion = hasOptions === true ? match[1].match(/(.+)--options.+/i)[1].trim() : match[1].trim(); // Extract question from the match
31-
const pollOptions = hasOptions && match[1].match(/--options\s+?(.+)/i)[1].split(";").slice(0, 5); // Extract poll options
29+
const hasOptions = new RegExp("--options", "i").test(match[2]);
30+
const pollQuestion = hasOptions === true ? match[2].match(/(.+)--options.+/i)[1].trim() : match[2].trim(); // Extract question from the match
31+
const pollOptions = hasOptions && match[2].match(/--options\s+?(.+)/i)[1].split(";").slice(0, 5); // Extract poll options
3232
// const pollTimeout: number = parseInt(match[2], 10);
3333
const pollDescription = hasOptions ? pollOptions.reduce((acc, curr, currIndex) => {
3434
return acc += `${NUMBER_SYMBOLS[currIndex]} - ${curr}\n`;
@@ -43,7 +43,7 @@ function pollCommand(match, message) {
4343
if (hasOptions && pollOptions.length > 0) {
4444
let currIndex = 0;
4545
/**
46-
* Asynchronously add emojies!
46+
* add emojies!
4747
*/
4848
function addEmoji() {
4949
botMessage.react(NUMBER_EMOJIES[currIndex])

dist/constants/constants.js

Whitespace-only changes.

dist/main.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,43 @@ const Canister = new discord_js_1.Client();
1414
Canister.on("ready", () => {
1515
console.log("I am ready!");
1616
});
17+
Canister.on("guildMemberAdd", (newUser) => {
18+
const channel = newUser.guild.channels.find("name", "general");
19+
console.log(channel.name);
20+
if (!channel) {
21+
return;
22+
}
23+
let welcomeMessage = `Welcome to Coderplex, <@${newUser.id}>!\n`;
24+
welcomeMessage += "Coderplex is a non-profit organization that is working towards improving the state of tech in Hyderabad,\n";
25+
welcomeMessage += "by building an active and vibrant developer community which provides support, motivation,\n";
26+
welcomeMessage += "confidence and opportunities to all it’s members, so that each of them can progress in their careers\n";
27+
welcomeMessage += "as software developers and engineers.\n";
28+
welcomeMessage += "\n";
29+
welcomeMessage += "Please introduce yourself in #introductions !\n";
30+
welcomeMessage += "Talk about your goals, interests, and views on different technologies out there!\n";
31+
welcomeMessage += "\n";
32+
welcomeMessage += "Ask for help in respective channels! Participate in the community and most of all, learn and have fun!";
33+
welcomeMessage += "\n";
34+
// channel.send(`
35+
// Welcome to Coderplex, <@${newUser.id}>!
36+
// Coderplex is a non-profit organization that is working towards improving the state of tech in Hyderabad,
37+
// by building an active and vibrant developer community which provides support, motivation,
38+
// confidence and opportunities to all it’s members, so that each of them can progress in their careers
39+
// as software developers and engineers.
40+
// Please introduce yourself in #introductions !
41+
// Talk about your goals, interests, and views on different technologies out there!
42+
// Ask for help in respective channels! Participate in the community and most of all, learn and have fun!
43+
// `);
44+
channel.send(welcomeMessage);
45+
});
1746
Canister.on("message", (message) => __awaiter(this, void 0, void 0, function* () {
18-
const pollMatch = message.content.match(/!poll\s+?(.+)/i); // \s+?(\d)
47+
const pollMatch = message.content.match(/!(poll|help)\s+?(.+)/i); // \s+?(\d)
1948
if (pollMatch && pollMatch.index !== -1) {
20-
poll_1.default(pollMatch, message);
49+
switch (pollMatch[1]) {
50+
case "poll":
51+
poll_1.default(pollMatch, message);
52+
break;
53+
}
2154
}
2255
}));
2356
Canister.login(process.env.BOT_TOKEN);

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"repository": "https://github.com/buoyantair/canister.git",
66
"author": "buoyantair <[email protected]>",
77
"license": "MIT",
8-
"engines": {
9-
"node": "8.6.0"
10-
},
118
"scripts": {
129
"start": "nodemon ./dist/main.js",
1310
"build": "gulp watch",

src/commands/poll.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ const NUMBER_EMOJIES: string[] = [
3838
];
3939

4040
async function pollCommand(match: any[], message: Message) {
41-
const hasOptions: boolean = new RegExp("--options", "i").test(match[1]);
42-
const pollQuestion: string = hasOptions === true ? match[1].match(/(.+)--options.+/i)[1].trim() : match[1].trim(); // Extract question from the match
43-
const pollOptions: string[] = hasOptions && match[1].match(/--options\s+?(.+)/i)[1].split(";").slice(0, 5); // Extract poll options
41+
const hasOptions: boolean = new RegExp("--options", "i").test(match[2]);
42+
const pollQuestion: string = hasOptions === true ? match[2].match(/(.+)--options.+/i)[1].trim() : match[2].trim(); // Extract question from the match
43+
const pollOptions: string[] = hasOptions && match[2].match(/--options\s+?(.+)/i)[1].split(";").slice(0, 5); // Extract poll options
4444
// const pollTimeout: number = parseInt(match[2], 10);
4545
const pollDescription: string = hasOptions ? pollOptions.reduce((acc: string, curr: string, currIndex: number) => {
4646
return acc += `${NUMBER_SYMBOLS[currIndex]} - ${curr}\n`;
@@ -58,7 +58,7 @@ async function pollCommand(match: any[], message: Message) {
5858
if (hasOptions && pollOptions.length > 0) {
5959
let currIndex: number = 0;
6060
/**
61-
* Asynchronously add emojies!
61+
* add emojies!
6262
*/
6363
function addEmoji() {
6464
botMessage.react(NUMBER_EMOJIES[currIndex])

src/main.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, Message } from "discord.js";
1+
import { Client, Message, GuildMember, TextChannel, GuildChannel } from "discord.js";
22

33
import pollCommand from "./commands/poll";
44

@@ -8,10 +8,48 @@ Canister.on("ready", () => {
88
console.log("I am ready!");
99
});
1010

11+
Canister.on("guildMemberAdd", (newUser: GuildMember) => {
12+
const channel: TextChannel = newUser.guild.channels.find("name", "general") as TextChannel;
13+
console.log(channel.name);
14+
if (!channel) {
15+
return;
16+
}
17+
18+
let welcomeMessage = `Welcome to Coderplex, <@${newUser.id}>!\n`;
19+
welcomeMessage += "Coderplex is a non-profit organization that is working towards improving the state of tech in Hyderabad,\n";
20+
welcomeMessage += "by building an active and vibrant developer community which provides support, motivation,\n";
21+
welcomeMessage += "confidence and opportunities to all it’s members, so that each of them can progress in their careers\n";
22+
welcomeMessage += "as software developers and engineers.\n";
23+
welcomeMessage += "\n";
24+
welcomeMessage += "Please introduce yourself in #introductions !\n";
25+
welcomeMessage += "Talk about your goals, interests, and views on different technologies out there!\n";
26+
welcomeMessage += "\n";
27+
welcomeMessage += "Ask for help in respective channels! Participate in the community and most of all, learn and have fun!";
28+
welcomeMessage += "\n";
29+
// channel.send(`
30+
// Welcome to Coderplex, <@${newUser.id}>!
31+
// Coderplex is a non-profit organization that is working towards improving the state of tech in Hyderabad,
32+
// by building an active and vibrant developer community which provides support, motivation,
33+
// confidence and opportunities to all it’s members, so that each of them can progress in their careers
34+
// as software developers and engineers.
35+
36+
// Please introduce yourself in #introductions !
37+
// Talk about your goals, interests, and views on different technologies out there!
38+
39+
// Ask for help in respective channels! Participate in the community and most of all, learn and have fun!
40+
// `);
41+
42+
channel.send(welcomeMessage);
43+
});
44+
1145
Canister.on("message", async (message: Message) => {
12-
const pollMatch = message.content.match(/!poll\s+?(.+)/i); // \s+?(\d)
46+
const pollMatch = message.content.match(/!(poll|help)\s+?(.+)/i); // \s+?(\d)
1347
if (pollMatch && pollMatch.index !== -1) {
14-
pollCommand(pollMatch, message);
48+
switch (pollMatch[1]) {
49+
case "poll":
50+
pollCommand(pollMatch, message);
51+
break;
52+
}
1553
}
1654
});
1755
Canister.login(process.env.BOT_TOKEN);

0 commit comments

Comments
 (0)