Skip to content

Commit 45dd8f4

Browse files
author
buoyantair
committed
Update packages, make the project neat and add help command
1 parent ad52a41 commit 45dd8f4

File tree

10 files changed

+2051
-1248
lines changed

10 files changed

+2051
-1248
lines changed

dist/commands/help.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const discord_js_1 = require("discord.js");
4+
function handleHelp(match, message) {
5+
const SEPERATOR = "================================================\n";
6+
let description = "Hello! I'm Plex, your friendly coderplex bot! Heres some commands to help along the way ;)\n";
7+
description += SEPERATOR;
8+
description += "**`!help`** -> Summons this message!\n";
9+
description += "**`!poll QUESTION`** -> Start a poll in agreement or disagreemnt of something! Additionally, you can make use of the **`--options`** flag to give custom for people to choose! for example:```!poll Next meetup location? --options 91springboards; swecha; IIIT```\n";
10+
description += SEPERATOR;
11+
const embedOptions = {
12+
title: "Coderplex Help",
13+
description,
14+
};
15+
const embed = new discord_js_1.RichEmbed(embedOptions);
16+
message.channel.send(embed);
17+
}
18+
exports.default = handleHelp;

dist/commands/poll.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,28 @@ const NUMBER_EMOJIES = [
2424
constants_1.EMOJI_FOUR,
2525
constants_1.EMOJI_FIVE,
2626
];
27-
function pollCommand(match, message) {
27+
function handlePoll(match, message) {
2828
return __awaiter(this, void 0, void 0, function* () {
29+
const hasQuestion = match[2] !== undefined;
30+
if (!hasQuestion) {
31+
yield message.channel.send(":panda_face: :raised_hand: Please enter a question after !poll, the format is `!poll QUESTION`, checkout `!help` for details.");
32+
return;
33+
}
2934
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
35+
const pollQuestion = hasOptions === true
36+
? match[2].match(/(.+)--options.+/i)[1].trim()
37+
: match[2].trim(); // Extract question from the match
38+
const pollOptions = hasOptions &&
39+
match[2]
40+
.match(/--options\s+?(.+)/i)[1]
41+
.split(";")
42+
.slice(0, 5); // Extract poll options
3243
// const pollTimeout: number = parseInt(match[2], 10);
33-
const pollDescription = hasOptions ? pollOptions.reduce((acc, curr, currIndex) => {
34-
return acc += `${NUMBER_SYMBOLS[currIndex]} - ${curr}\n`;
35-
}, "") : "";
44+
const pollDescription = hasOptions
45+
? pollOptions.reduce((acc, curr, currIndex) => {
46+
return (acc += `${NUMBER_SYMBOLS[currIndex]} - ${curr}\n`);
47+
}, "")
48+
: "";
3649
const embedOptions = {
3750
title: pollQuestion,
3851
description: pollDescription,
@@ -46,8 +59,7 @@ function pollCommand(match, message) {
4659
* add emojies!
4760
*/
4861
function addEmoji() {
49-
botMessage.react(NUMBER_EMOJIES[currIndex])
50-
.then(() => {
62+
botMessage.react(NUMBER_EMOJIES[currIndex]).then(() => {
5163
currIndex++;
5264
if (currIndex < pollOptions.length) {
5365
addEmoji();
@@ -57,8 +69,8 @@ function pollCommand(match, message) {
5769
addEmoji();
5870
}
5971
else {
60-
const yesReaction = yield botMessage.react(constants_1.THUMBS_UP);
61-
const noReaction = yield botMessage.react(constants_1.THUMBS_DOWN);
72+
yield botMessage.react(constants_1.THUMBS_UP);
73+
yield botMessage.react(constants_1.THUMBS_DOWN);
6274
}
6375
if (message.deletable) {
6476
message.delete();
@@ -69,4 +81,4 @@ function pollCommand(match, message) {
6981
}
7082
});
7183
}
72-
exports.default = pollCommand;
84+
exports.default = handlePoll;

dist/events/handleNewMember.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
function handleNewMember(newUser) {
12+
return __awaiter(this, void 0, void 0, function* () {
13+
const dmChannel = yield newUser.createDM();
14+
const guildChannel = newUser.guild.channels.find("name", "introductions");
15+
if (!dmChannel || !guildChannel) {
16+
return;
17+
}
18+
let dmWelcomeMessage = `Welcome to Coderplex, <@${newUser.id}>!\n`;
19+
dmWelcomeMessage +=
20+
"Coderplex is a non-profit organization that is working towards improving the state of tech in Hyderabad,\n";
21+
dmWelcomeMessage +=
22+
"by building an active and vibrant developer community which provides support, motivation,\n";
23+
dmWelcomeMessage +=
24+
"confidence and opportunities to all it’s members, so that each of them can progress in their careers\n";
25+
dmWelcomeMessage += "as software developers and engineers.\n";
26+
dmWelcomeMessage += "\n";
27+
dmWelcomeMessage += "Please introduce yourself in #introductions channel !\n";
28+
dmWelcomeMessage +=
29+
"Talk about your goals, interests, and views on different technologies out there!\n";
30+
dmWelcomeMessage += "\n";
31+
dmWelcomeMessage +=
32+
"Download the official Discord mobile app at https://discordapp.com/download to stay connected with the community and get notified on latest updates!!";
33+
dmWelcomeMessage += "\n";
34+
dmWelcomeMessage +=
35+
"Ask for help in respective channels! Participate in the community and most of all, learn and have fun!";
36+
let chWelcomeMessage = `Welcome to Coderplex, <@${newUser.id}>!\n`;
37+
chWelcomeMessage += "Please introduce yourself to the community!";
38+
dmChannel.send(dmWelcomeMessage);
39+
guildChannel.send(chWelcomeMessage);
40+
});
41+
}
42+
exports.default = handleNewMember;

dist/main.js

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1010
Object.defineProperty(exports, "__esModule", { value: true });
1111
const discord_js_1 = require("discord.js");
1212
const dotenv_1 = require("dotenv");
13+
const handleNewMember_1 = require("./events/handleNewMember");
1314
const poll_1 = require("./commands/poll");
15+
const help_1 = require("./commands/help");
1416
dotenv_1.config();
1517
const Canister = new discord_js_1.Client();
18+
// Once the bot is ready, log to the console :)
1619
Canister.on("ready", () => {
1720
console.log("I am ready!");
1821
});
19-
Canister.on("guildMemberAdd", (newUser) => __awaiter(this, void 0, void 0, function* () {
20-
const dmChannel = yield newUser.createDM();
21-
const guildChannel = newUser.guild.channels.find("name", "introductions");
22-
if (!dmChannel || !guildChannel) {
23-
return;
24-
}
25-
let dmWelcomeMessage = `Welcome to Coderplex, <@${newUser.id}>!\n`;
26-
dmWelcomeMessage += "Coderplex is a non-profit organization that is working towards improving the state of tech in Hyderabad,\n";
27-
dmWelcomeMessage += "by building an active and vibrant developer community which provides support, motivation,\n";
28-
dmWelcomeMessage += "confidence and opportunities to all it’s members, so that each of them can progress in their careers\n";
29-
dmWelcomeMessage += "as software developers and engineers.\n";
30-
dmWelcomeMessage += "\n";
31-
dmWelcomeMessage += "Please introduce yourself in #introductions !\n";
32-
dmWelcomeMessage += "Talk about your goals, interests, and views on different technologies out there!\n";
33-
dmWelcomeMessage += "\n";
34-
dmWelcomeMessage += "Download the official Discord mobile app at https://discordapp.com/download to stay connected with the community and get notified on latest updates!!";
35-
dmWelcomeMessage += "\n";
36-
dmWelcomeMessage += "Ask for help in respective channels! Participate in the community and most of all, learn and have fun!";
37-
let chWelcomeMessage = `Welcome to Coderplex, <@${newUser.id}>!\n`;
38-
chWelcomeMessage += "Please introduce yourself to the community!";
39-
dmChannel.send(dmWelcomeMessage);
40-
guildChannel.send(chWelcomeMessage);
41-
}));
22+
Canister.on("guildMemberAdd", handleNewMember_1.default);
4223
Canister.on("message", (message) => __awaiter(this, void 0, void 0, function* () {
43-
const commandMatch = message.content.match(/!(poll|help)\s+?(.+)/i); // \s+?(\d)
24+
const commandMatch = message.content.match(/^!(poll|help)(\s+?(.+))?/i); // \s+?(\d)
25+
console.log(commandMatch);
4426
if (commandMatch && commandMatch.index !== -1) {
4527
switch (commandMatch[1]) {
4628
case "poll":
4729
poll_1.default(commandMatch, message);
4830
break;
31+
case "help":
32+
help_1.default(commandMatch, message);
33+
break;
4934
}
5035
}
5136
}));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy