diff --git a/README.md b/README.md
index 17e8eb6..761246c 100644
--- a/README.md
+++ b/README.md
@@ -26,22 +26,29 @@ crafted with ♥ by your friends on th
- **Common Commands**
- - `#kzjack help` - Get everything what Jack can do
- - `#kzjack meme` - Jack sends you a crazyyyy meme
- - `#kzjack joke` - Bored? Wait for jack to send you a joke, perfect joke indeed.
- - `#kzjack shrink ` - Shrink a looooong URL using [KZILLA.XYZ](https://kzilla.xyz/)
+ - **`#kzjack help` - Get everything what Jack can do**
+ - **`#kzjack meme` - Jack sends you a crazyyyy meme**
+ - **`#kzjack joke` - Bored? Wait for jack to send you a joke, perfect joke indeed.**
+ - **`#kzjack shrink ` - Shrink a looooong URL using [KZILLA.XYZ](https://kzilla.xyz/)**
+ - **Example:** `#kzjack shrink https://srmkzilla.net`
- **Text Channel Commands**
- - `#kzjack membercount` - Get members count for the channel
+ - **`#kzjack membercount` - Get members count for the channel**
- **Moderators Channel Commands**
- - `#kzjack flush` -Flush all cache
- - `#kzjack certificate ` - Start a certificate thread
- - `#kzjack announce here|everyone > {} ` - Announcements
- - `#kzjack poll create {} [[],[ ],[ ]]` - Start a Poll
- - `#kzjack poll result ` - Get Poll Results
+ - **`#kzjack flush` -Flush all cache**
+ - **`#kzjack certificate ` - Start a certificate thread**
+ - `#kzjack certificate my-event`
+ - **`#kzjack announce here|everyone > <#channel> {} ` - Announcements**
+ - **Example:** `#kzjack announce #announcements {Hello World!} How are you?`
+ - **Example:** `#kzjack announce here #announcements {Hello World!} How are you?`
+ - **Example:** `#kzjack announce everyone #announcements {Hello World!} How are you?`
+ - **`#kzjack poll create <#channel> {} [[],[ ],[ ]]` - Start a Poll**
+ - **Example:** `#kzjack poll create #polls {Who's the best?} [[Jack],[Yvette]]`
+ - **`#kzjack poll result ` - Get Poll Results**
+ - **Example:** `#kzjack poll result s3cRe7ID`
## Installation 🔧
diff --git a/index.ts b/index.ts
index 878d3ed..5fe9831 100644
--- a/index.ts
+++ b/index.ts
@@ -10,6 +10,8 @@ import { initDbClient, initEventDbClient } from "./src/utils/database";
import { initCache, refreshKeys } from "./src/utils/nodecache";
import { handleMemberJoin, handleMemberLeave } from "./src/helper/memberLogs";
import { serverLogger } from "./src/utils/logger";
+import { checkForAccessByRoles } from "./src/helper/roleAuth";
+import { incomingMessageSchema } from "./src/models/incomingMessage";
/******************************************
Initialize Server
*******************************************/
@@ -34,13 +36,24 @@ async function createServer() {
*******************************************/
if (!message.author.bot) {
if (message.content.split(" ")[0] == COMMANDS.prefix) {
+ const messageType: incomingMessageSchema = {
+ channelType: message.channel.type,
+ incomingUser: {
+ username: message.author.username,
+ discriminator: message.author.discriminator,
+ id: message.author.id,
+ isMod: await checkForAccessByRoles(message.member, [
+ `${process.env.OPERATOR_ROLE_ID}`,
+ ]),
+ },
+ };
switch (message.channel.type) {
/******************************************
Text channel
*******************************************/
case "text": {
//check for our command
- handleIncomingChannelCommand(message);
+ handleIncomingChannelCommand(message, messageType);
break;
}
@@ -48,7 +61,7 @@ async function createServer() {
DM channel
*******************************************/
case "dm": {
- handleIncomingDMCommand(message);
+ handleIncomingDMCommand(message, messageType);
break;
}
default: {
diff --git a/src/controllers/incomingMessageHandler.ts b/src/controllers/incomingMessageHandler.ts
index 964c861..0dfaeae 100644
--- a/src/controllers/incomingMessageHandler.ts
+++ b/src/controllers/incomingMessageHandler.ts
@@ -5,40 +5,41 @@ import { handleJokes, handleMemes } from "../helper/jokes";
import { handleShrinkURLMessage } from "../helper/kzillaXYZ";
import { handleGetMemberCount } from "../helper/memberCount";
import { getEvent } from "../utils/nodecache";
-import { COMMANDS, CONSTANTS } from "../utils/constants";
+import { COMMANDS, CONSTANTS, ERRORS } from "../utils/constants";
import { serverLogger } from "../utils/logger";
import { flushCache } from "../helper/flushCache";
import { createPoll, getResult } from "../helper/polls";
-import {
- getHelpMessage,
- invalidCommand,
- internalError,
-} from "../utils/messages";
+import { createBasicEmbed, getHelpMessage } from "../utils/messages";
import { sendDirectMessageToUser } from "./sendMessageHandler";
+import { incomingMessageSchema } from "../models/incomingMessage";
/**
- * Handles all incoming commands in channel
+ * Handles all incoming commands in a text channel
*
- * @param {Message} incomingMessage
+ * @param {Message} incomingMessage The incoming message
+ * @param {incomingMessageSchema} messageType The incoming message type
*/
-export async function handleIncomingChannelCommand(incomingMessage: Message) {
+export async function handleIncomingChannelCommand(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
const messageCommand = incomingMessage.content.split(" ")[1];
switch (messageCommand) {
case COMMANDS.certificate: {
- getCertificateChannelMessage(incomingMessage);
+ getCertificateChannelMessage(incomingMessage, messageType);
break;
}
case COMMANDS.shrinkURL: {
- handleShrinkURLMessage(incomingMessage);
+ handleShrinkURLMessage(incomingMessage, messageType);
break;
}
case COMMANDS.membercount: {
- handleGetMemberCount(incomingMessage);
+ handleGetMemberCount(incomingMessage, messageType);
break;
}
case COMMANDS.announce: {
- handleAnnouncements(incomingMessage);
+ handleAnnouncements(incomingMessage, messageType);
serverLogger(
"success",
incomingMessage.content.split(" ").splice(0, 5),
@@ -47,73 +48,89 @@ export async function handleIncomingChannelCommand(incomingMessage: Message) {
break;
}
case COMMANDS.joke: {
- handleJokes(incomingMessage);
+ handleJokes(incomingMessage, messageType);
break;
}
case COMMANDS.memes: {
- handleMemes(incomingMessage);
+ handleMemes(incomingMessage, messageType);
break;
}
case COMMANDS.cacheflush: {
- flushCache(incomingMessage);
+ flushCache(incomingMessage, messageType);
break;
}
case COMMANDS.createPoll: {
if (incomingMessage.content.split(" ")[2] == "create")
- createPoll(incomingMessage);
- else getResult(incomingMessage);
+ createPoll(incomingMessage, messageType);
+ else getResult(incomingMessage, messageType);
break;
}
case COMMANDS.help: {
- incomingMessage.channel.send(getHelpMessage());
+ incomingMessage.channel.send(getHelpMessage(messageType));
serverLogger("success", incomingMessage.content, "Help Message");
break;
}
default:
- incomingMessage.channel.send(invalidCommand());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_COMMAND, "ERROR")
+ );
serverLogger("user-error", incomingMessage.content, "Invalid Command");
break;
}
} catch (err) {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
+ );
}
}
/**
* Handles all incoming commands in Direct Message
*
- * @param {Message} incomingMessage
+ * @param {Message} incomingMessage The incoming message
+ * @param {incomingMessageSchema} messageType The incoming message type
*/
-export function handleIncomingDMCommand(incomingMessage: Message) {
+export function handleIncomingDMCommand(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
const messageCommand = incomingMessage.content.split(" ")[1];
switch (messageCommand) {
case COMMANDS.shrinkURL: {
- handleShrinkURLMessage(incomingMessage);
+ handleShrinkURLMessage(incomingMessage, messageType);
break;
}
case COMMANDS.help: {
- incomingMessage.channel.send(getHelpMessage());
+ incomingMessage.channel.send(getHelpMessage(messageType));
serverLogger("success", incomingMessage.content, "Help Message");
break;
}
case COMMANDS.joke: {
- handleJokes(incomingMessage);
+ handleJokes(incomingMessage, messageType);
break;
}
case COMMANDS.memes: {
- handleMemes(incomingMessage);
+ handleMemes(incomingMessage, messageType);
break;
}
default:
- incomingMessage.channel.send(invalidCommand());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_COMMAND, "ERROR")
+ );
serverLogger("user-error", incomingMessage.content, "Invalid Command");
break;
}
} catch (err) {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
+ );
}
}
@@ -140,7 +157,7 @@ export async function handleIncomingReaction(
user,
message,
event.slug,
- CONSTANTS.certificateUserDirectMessage(event.name)
+ CONSTANTS.certificateUserDirectMessage(event.name, user.username)
);
}
}
diff --git a/src/controllers/sendMessageHandler.ts b/src/controllers/sendMessageHandler.ts
index 101bc9f..be5d03a 100644
--- a/src/controllers/sendMessageHandler.ts
+++ b/src/controllers/sendMessageHandler.ts
@@ -1,10 +1,9 @@
import { Message, MessageReaction, User } from "discord.js";
-import { createBasicEmbed, internalError } from "../utils/messages";
+import { createBasicEmbed } from "../utils/messages";
import { ERRORS } from "../utils/constants";
import { certificateEmojifilter } from "../utils/filters";
import { handleIncomingReaction } from "./incomingMessageHandler";
import { serverLogger } from "../utils/logger";
-import { eventSchema } from "../models/event";
import { getEvent } from "../utils/nodecache";
import { certificateDMHandler } from "../helper/certificate";
import { emailSchema } from "../models/email";
@@ -32,9 +31,7 @@ export async function sendDirectMessageToUser(
return true;
} catch (err) {
serverLogger("user-error", dm.content, "Malformed Email");
- dm.channel.send(
- createBasicEmbed("Invalid Email!", ERRORS.INVALID_EMAIL, "ERROR")
- );
+ dm.channel.send(createBasicEmbed(ERRORS.INVALID_EMAIL, "ERROR"));
return false;
}
},
@@ -49,7 +46,16 @@ export async function sendDirectMessageToUser(
});
} catch (err) {
serverLogger("error", message, "DM Blocked");
- message.channel.send(ERRORS.DM_BLOCKED(user));
+ message.channel.send(
+ `<@${user.id}>`,
+ createBasicEmbed(
+ {
+ title: ERRORS.DM_BLOCKED.title,
+ message: ERRORS.DM_BLOCKED.message(user),
+ },
+ "ERROR"
+ )
+ );
}
}
@@ -78,10 +84,12 @@ export async function sendReactableMessage(
);
eventCollector.on("collect", (reaction: MessageReaction, user: User) => {
- handleIncomingReaction(user, reaction, event.slug, message);
+ handleIncomingReaction(user, reaction, event.slug, reaction.message);
});
} catch (err) {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ createBasicEmbed(ERRORS.INTERNAL_ERROR("dm"), "ERROR")
+ );
}
}
diff --git a/src/helper/announcement.ts b/src/helper/announcement.ts
index c742845..b4d5d8a 100644
--- a/src/helper/announcement.ts
+++ b/src/helper/announcement.ts
@@ -1,26 +1,22 @@
import { Message, TextChannel, NewsChannel } from "discord.js";
import { serverLogger } from "../utils/logger";
-import {
- announcementMessage,
- invalidChannel,
- invalidCommand,
- unauthorizedUser,
-} from "../utils/messages";
-import { checkForAccessByRoles } from "../helper/roleAuth";
-import { COMMANDS } from "../utils/constants";
+import { announcementMessage, createBasicEmbed } from "../utils/messages";
+import { COMMANDS, ERRORS } from "../utils/constants";
+import { incomingMessageSchema } from "../models/incomingMessage";
/**
* Handles all announcements
*
* @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
*/
-export async function handleAnnouncements(incomingMessage: Message) {
+export async function handleAnnouncements(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
- const isAllowed = await checkForAccessByRoles(incomingMessage.member, [
- `${process.env.OPERATOR_ROLE_ID}`,
- ]);
- if (isAllowed) {
+ if (messageType.incomingUser.isMod) {
const regex = new RegExp(
`^${COMMANDS.prefix} ${COMMANDS.announce}( here | everyone | )<#.+> \{.*\} (.|\n)+$`,
"g"
@@ -72,7 +68,10 @@ export async function handleAnnouncements(incomingMessage: Message) {
incomingMessage.content.split(" ").splice(0, 5),
"Invalid command"
);
- incomingMessage.channel.send(invalidCommand());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_COMMAND, "ERROR")
+ );
}
} else {
serverLogger(
@@ -80,10 +79,16 @@ export async function handleAnnouncements(incomingMessage: Message) {
incomingMessage.content.split(" ").splice(0, 5),
"Unauthorized User"
);
- incomingMessage.channel.send(unauthorizedUser());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.UNAUTHORIZED_USER, "ERROR")
+ );
}
} catch (err) {
- incomingMessage.channel.send(invalidChannel());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_CHANNEL, "ERROR")
+ );
serverLogger(
"user-error",
incomingMessage.content.split(" ").splice(0, 5),
diff --git a/src/helper/certificate.ts b/src/helper/certificate.ts
index 399d265..de660eb 100644
--- a/src/helper/certificate.ts
+++ b/src/helper/certificate.ts
@@ -3,19 +3,16 @@ import * as Jimp from "jimp";
import { join } from "path";
import {
getYourCertificateChannelMessage,
- internalError,
- unauthorizedUser,
- invalidCommand,
- eventDoesNotExist,
+ createBasicEmbed,
} from "../utils/messages";
-import { CONSTANTS } from "../utils/constants";
+import { CONSTANTS, ERRORS } from "../utils/constants";
import { getUserCertificate } from "../service/certificate-service";
import { sendReactableMessage } from "../controllers/sendMessageHandler";
-import { checkForAccessByRoles } from "./roleAuth";
import { serverLogger } from "../utils/logger";
import { getDbClient } from "../utils/database";
import { eventSchema } from "../models/event";
import { setEvent } from "../utils/nodecache";
+import { incomingMessageSchema } from "../models/incomingMessage";
/**
* Handles all certificate message in DM (email)
@@ -37,7 +34,9 @@ export async function certificateDMHandler(
return serviceExecuted;
} catch (err) {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ createBasicEmbed(ERRORS.INTERNAL_ERROR("dm"), "ERROR")
+ );
return true;
}
}
@@ -45,17 +44,21 @@ export async function certificateDMHandler(
* Handles certificate thread start message
*
* @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
*/
-export async function getCertificateChannelMessage(incomingMessage: Message) {
+export async function getCertificateChannelMessage(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
- const isAllowed = await checkForAccessByRoles(incomingMessage.member, [
- `${process.env.OPERATOR_ROLE_ID}`,
- ]);
- if (isAllowed) {
+ if (messageType.incomingUser.isMod) {
const eventSlug = incomingMessage.content.split(/ +/)[2];
if (!eventSlug) {
serverLogger("user-error", incomingMessage.content, "Invalid Command");
- return incomingMessage.channel.send(invalidCommand());
+ return incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_COMMAND, "ERROR")
+ );
}
const db = await (await getDbClient()).db().collection("events");
const event = await db.findOne({ slug: eventSlug });
@@ -65,7 +68,10 @@ export async function getCertificateChannelMessage(incomingMessage: Message) {
incomingMessage.content,
"Event Does Not Exist"
);
- return incomingMessage.channel.send(eventDoesNotExist());
+ return incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.EVENT_DNE, "ERROR")
+ );
}
if (!(await setEvent(event))) throw "Cannot set nodeCache Key!";
await sendReactableMessage(
@@ -76,11 +82,17 @@ export async function getCertificateChannelMessage(incomingMessage: Message) {
);
} else {
serverLogger("user-error", incomingMessage.content, "Unauthorized User");
- incomingMessage.channel.send(unauthorizedUser());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.UNAUTHORIZED_USER, "ERROR")
+ );
}
} catch (err) {
serverLogger("internal-error", "Error", err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
+ );
}
}
diff --git a/src/helper/flushCache.ts b/src/helper/flushCache.ts
index b70607c..6efc21b 100644
--- a/src/helper/flushCache.ts
+++ b/src/helper/flushCache.ts
@@ -1,15 +1,21 @@
import { Message } from "discord.js";
import { refreshKeys } from "../utils/nodecache";
-import { flushSuccessMessage, unauthorizedUser } from "../utils/messages";
+import { createBasicEmbed, flushSuccessMessage } from "../utils/messages";
import { serverLogger } from "../utils/logger";
import { checkForAccessByRoles } from "./roleAuth";
+import { incomingMessageSchema } from "../models/incomingMessage";
+import { ERRORS } from "../utils/constants";
/**
* Handles flushing the cache
*
* @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
*/
-export const flushCache = async (incomingMessage: Message) => {
+export const flushCache = async (
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) => {
const isAllowed = await checkForAccessByRoles(incomingMessage.member, [
`${process.env.OPERATOR_ROLE_ID}`,
]);
@@ -19,6 +25,9 @@ export const flushCache = async (incomingMessage: Message) => {
serverLogger("success", incomingMessage.content, "Cache Flush Keys");
} else {
serverLogger("user-error", incomingMessage.content, "Unauthorized User");
- incomingMessage.channel.send(unauthorizedUser());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.UNAUTHORIZED_USER, "ERROR")
+ );
}
};
diff --git a/src/helper/jokes.ts b/src/helper/jokes.ts
index 4bc8ef9..76b3722 100644
--- a/src/helper/jokes.ts
+++ b/src/helper/jokes.ts
@@ -1,29 +1,71 @@
import axios from "axios";
-import { Message } from "discord.js";
-import { CONSTANTS } from "../utils/constants";
+import { Message, MessageEmbed } from "discord.js";
+import { incomingMessageSchema } from "../models/incomingMessage";
+import { COLORS, CONSTANTS, ERRORS } from "../utils/constants";
import { serverLogger } from "../utils/logger";
-import { internalError } from "../utils/messages";
+import { createBasicEmbed } from "../utils/messages";
-export async function handleJokes(incomingMessage: Message) {
+/**
+ * Handle joke commands.
+ * Send some jokes on the server.
+ * @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
+ */
+export async function handleJokes(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
const { data } = await axios.get(CONSTANTS.JOKES_URL_ENDPOINT);
console.log(data);
- incomingMessage.channel.send(data[0].setup + data[0].punchline);
+ incomingMessage.channel.send(
+ createBasicEmbed(
+ {
+ title: "Hahaha! Here's a joke for you 🤡!",
+ message: `**${data[0].setup}**\n*${data[0].punchline}*`,
+ },
+ "INFO"
+ )
+ );
} catch (err) {
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
+ );
serverLogger("error", incomingMessage.content, err);
}
}
-export async function handleMemes(incomingMessage: Message) {
+/**
+ * Handle memes commands.
+ * Send some memes on the server.
+ * @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
+ */
+export async function handleMemes(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
const { data } = await axios.get(CONSTANTS.MEMES_URL_ENDPOINT);
console.log(data);
- incomingMessage.channel.send(data.title, {
- files: [data.url],
- });
+ incomingMessage.channel.send(
+ new MessageEmbed()
+ .setTitle("LMAOOO! Here's a meme for you 🤣!")
+ .setDescription(`**${data.title}**`)
+ .setColor(COLORS.INFO)
+ .setImage(data.url)
+ .setTimestamp()
+ .setFooter(
+ "Powered by SRMKZILLA and hamster-charged batteries",
+ "https://srmkzilla.net/assets/img/kzilla.png"
+ )
+ );
} catch (err) {
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
+ );
serverLogger("error", incomingMessage.content, err);
}
}
diff --git a/src/helper/kzillaXYZ.ts b/src/helper/kzillaXYZ.ts
index 30a1b61..c315ee7 100644
--- a/src/helper/kzillaXYZ.ts
+++ b/src/helper/kzillaXYZ.ts
@@ -1,12 +1,9 @@
import axios from "axios";
import { Message } from "discord.js";
-import {
- internalError,
- invalidURL,
- shrinkedURLMessage,
-} from "../utils/messages";
-import { CONSTANTS, ERRORS } from "../utils/constants";
+import { createBasicEmbed, shrinkedURLMessage } from "../utils/messages";
+import { COLORS, CONSTANTS, ERRORS } from "../utils/constants";
import { serverLogger } from "../utils/logger";
+import { incomingMessageSchema } from "../models/incomingMessage";
/**
* Shrinks looong URL using KZILLA.XYZ
@@ -26,8 +23,12 @@ export async function shrinkURL(longUrl: string) {
* Handles commands for shrinking message
*
* @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
*/
-export async function handleShrinkURLMessage(incomingMessage: Message) {
+export async function handleShrinkURLMessage(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
const longURL = incomingMessage.content.split(" ")[2];
if (longURL) {
@@ -40,15 +41,24 @@ export async function handleShrinkURLMessage(incomingMessage: Message) {
);
} else {
serverLogger("user-error", incomingMessage.content, "No URL");
- incomingMessage.channel.send(ERRORS.URL_MISSING);
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.URL_MISSING, "ERROR")
+ );
}
} catch (err) {
if (err.isAxiosError && err.response.status == 400) {
serverLogger("user-error", incomingMessage.content, "Malformed URL");
- incomingMessage.channel.send(invalidURL());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_URL, "ERROR")
+ );
} else {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.UNAUTHORIZED_USER, "ERROR")
+ );
}
}
}
diff --git a/src/helper/memberCount.ts b/src/helper/memberCount.ts
index 2607312..350982d 100644
--- a/src/helper/memberCount.ts
+++ b/src/helper/memberCount.ts
@@ -1,22 +1,18 @@
import { Message } from "discord.js";
+import { incomingMessageSchema } from "../models/incomingMessage";
import { serverLogger } from "../utils/logger";
-import { internalError } from "../utils/messages";
-import { membersCountMessage } from "../utils/messages";
+import { createBasicEmbed, membersCountMessage } from "../utils/messages";
+import { ERRORS } from "../utils/constants";
/**
* Handles all incoming members count command in channel
- *
- * @param {Message} incomingMessage
- */
-export async function handleGetMemberCount(incomingMessage: Message) {
- getMemberCount(incomingMessage);
-}
-
-/**
* Get members count in channel
- *
* @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
*/
-export async function getMemberCount(incomingMessage: Message) {
+export async function handleGetMemberCount(
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) {
try {
const members = await incomingMessage.guild?.members.fetch({
force: true,
@@ -37,6 +33,9 @@ export async function getMemberCount(incomingMessage: Message) {
);
} catch (err) {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
+ );
}
}
diff --git a/src/helper/memberLogs.ts b/src/helper/memberLogs.ts
index 549a33d..2201918 100644
--- a/src/helper/memberLogs.ts
+++ b/src/helper/memberLogs.ts
@@ -6,6 +6,8 @@ import {
} from "discord.js";
import { serverLogger } from "../utils/logger";
import { updateUserJoinOrLeave } from "../service/user-service";
+import { createBasicEmbed } from "../utils/messages";
+import { ERRORS, INFO } from "../utils/constants";
export function handleMemberJoin(
member: GuildMember,
@@ -16,9 +18,11 @@ export function handleMemberJoin(
(ch: any) => ch.id === process.env.LOGGER_CHANNEL_ID
) as TextChannel;
if (!channel) return;
- channel.send(`Welcome to the server, ${member.toString()}`);
+ channel.send(
+ createBasicEmbed(INFO.MEMBER_JOIN(member as GuildMember), "SUCCESS")
+ );
member.send(
- `Hello ${member.toString()} ,\nI am Jack, SRMKZILLA's discord assistant.\nWe at SRMKZILLA welcome you to SRMKZILLA - Official Mozilla Campus Club, a lovely community of developers.\nEveryone here has one goal - to learn new and exciting things. \nTo that effect, please do not hesitate to ask any doubts or share an interesting piece of information. If you have any issues with, how things are running, do ping up any **@Moderator** or **@Jack Developer**. We are always here to help you and everyone have a magical experience.\n\nCheckout out ${client?.channels.cache
+ `Hello ${member.toString()} ,\nI am **Jack**, **SRMKZILLA's discord assistant.**\nWe at SRMKZILLA welcome you to **SRMKZILLA - Official Mozilla Campus Club**, a lovely community of developers.\nEveryone here has one goal - to learn new and exciting things. \nTo that effect, please do not hesitate to ask any doubts or share an interesting piece of information. If you have any issues with, how things are running, do ping up any **@Admin** or **@Jack Developer**. We are always here to help you and everyone have a magical experience.\n\nCheckout out ${client?.channels.cache
.get("793838431277023252")
?.toString()} to get started!\n- Sent from **SRMKZILLA - Official Mozilla Campus Club**`
);
@@ -37,7 +41,9 @@ export function handleMemberLeave(
(ch: any) => ch.id === process.env.LOGGER_CHANNEL_ID
) as TextChannel;
if (!channel) return;
- channel.send(`${member.toString()} left the server :(`);
+ channel.send(
+ createBasicEmbed(ERRORS.MEMBER_LEAVE(member as GuildMember), "ERROR")
+ );
updateUserJoinOrLeave(member as GuildMember, "leave");
} catch (err) {
serverLogger("error", "InternalError", err);
diff --git a/src/helper/polls.ts b/src/helper/polls.ts
index 5d25e00..cb210ed 100644
--- a/src/helper/polls.ts
+++ b/src/helper/polls.ts
@@ -1,38 +1,33 @@
-import {
- Message,
- MessageEmbed,
- MessageReaction,
- TextChannel,
- User,
-} from "discord.js";
+import { Message, MessageReaction, TextChannel, User } from "discord.js";
import { pollSchema } from "../models/poll";
import {
createPollMessage,
createPollResult,
- internalError,
+ createBasicEmbed,
} from "../utils/messages";
import { getPoll, refreshKeys, setPoll } from "../utils/nodecache";
import { nanoid } from "nanoid";
import { checkForAccessByRoles } from "./roleAuth";
import { serverLogger } from "../utils/logger";
import { getDiscordBot } from "../utils/discord";
-import {
- unauthorizedUser,
- invalidCommand,
- createBasicEmbed,
-} from "../utils/messages";
-import { COMMANDS, CONSTANTS } from "../utils/constants";
+import { COMMANDS, CONSTANTS, ERRORS } from "../utils/constants";
import { getDbClient } from "../utils/database";
import { pollEmojiFilter } from "../utils/filters";
+import { incomingMessageSchema } from "../models/incomingMessage";
-export const createPoll = async (incomingMessage: Message) => {
- const isAllowed = await checkForAccessByRoles(incomingMessage.member, [
- `${process.env.OPERATOR_ROLE_ID}`,
- ]);
+/**
+ *Handles create poll command
+ * @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
+ */
+export const createPoll = async (
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) => {
const pollRegex = new RegExp(
`^${COMMANDS.prefix} ${COMMANDS.createPoll} create (<#.+?>) ({.*?}) (\\[.*\\])$`
);
- if (isAllowed) {
+ if (messageType.incomingUser.isMod) {
try {
if (pollRegex.test(incomingMessage.content)) {
const tokens = incomingMessage.content.match(
@@ -46,15 +41,18 @@ export const createPoll = async (incomingMessage: Message) => {
if (optionsArray.length > 9) {
return incomingMessage.channel.send(
createBasicEmbed(
- "Invalid arguments!",
- `
+ {
+ title: "Invalid arguments!",
+ message:
+ `
Maximum number of options supported: **9**
**Syntax for Poll Command:**\n
` +
- "`" +
- COMMANDS.prefix +
- ` ${COMMANDS.createPoll} create {} [[],[ ],[ ],[ ]]` +
- "`",
+ "`" +
+ COMMANDS.prefix +
+ ` ${COMMANDS.createPoll} create {} [[],[ ],[ ],[ ]]` +
+ "`",
+ },
"ERROR"
)
);
@@ -79,15 +77,27 @@ export const createPoll = async (incomingMessage: Message) => {
incomingMessage.content.split(" ").splice(0, 5),
"Invalid command"
);
- incomingMessage.channel.send(invalidCommand());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_COMMAND, "ERROR")
+ );
}
} catch (err) {
serverLogger("internal-error", "Internal Error", err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(
+ ERRORS.INTERNAL_ERROR(messageType.channelType),
+ "ERROR"
+ )
+ );
}
} else {
serverLogger("user-error", incomingMessage.content, "Unauthorized User");
- incomingMessage.channel.send(unauthorizedUser());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.UNAUTHORIZED_USER, "ERROR")
+ );
}
};
@@ -106,7 +116,9 @@ const addPoll = async (incomingMessage: Message, poll: pollSchema) => {
await pollMessage.react(option.emoji);
})
);
- const pollCollector = pollMessage.createReactionCollector(pollEmojiFilter);
+ const pollCollector = pollMessage.createReactionCollector(pollEmojiFilter, {
+ dispose: true,
+ });
pollCollector.on("collect", async (reaction: MessageReaction, user: User) => {
const { result } = await db.updateOne(
{ pollID: poll.pollID, "options.emoji": reaction.emoji.name },
@@ -118,19 +130,45 @@ const addPoll = async (incomingMessage: Message, poll: pollSchema) => {
);
if (!(result.ok == 1)) throw "MongoDB Query Error: Failed to Add Reaction";
});
+ pollCollector.on("remove", async (reaction: MessageReaction, user: User) => {
+ const { result } = await db.updateOne(
+ { pollID: poll.pollID, "options.emoji": reaction.emoji.name },
+ {
+ $pull: {
+ "options.$.reactions": `${user.username}#${user.discriminator}`,
+ },
+ }
+ );
+ if (!(result.ok == 1)) throw "MongoDB Query Error: Failed to Add Reaction";
+ });
incomingMessage.channel.send(
createBasicEmbed(
- "**New Poll Created! :white_check_mark:**",
- "**Poll ID:** `" +
- poll.pollID +
- "`\n**Time of Creation:** " +
- poll.timestamp,
+ {
+ title: "**New Poll Created! :white_check_mark:**",
+ message:
+ "**Check Results:** `" +
+ COMMANDS.prefix +
+ " " +
+ COMMANDS.createPoll +
+ " result " +
+ poll.pollID +
+ "`\n**Time of Creation:** " +
+ poll.timestamp,
+ },
"INFO"
)
);
};
-export const getResult = async (incomingMessage: Message) => {
+/**
+ * Handles poll result command
+ * @param {Message} incomingMessage
+ * @param {incomingMessageSchema} messageType
+ */
+export const getResult = async (
+ incomingMessage: Message,
+ messageType: incomingMessageSchema
+) => {
const isAllowed = await checkForAccessByRoles(incomingMessage.member, [
`${process.env.OPERATOR_ROLE_ID}`,
]);
@@ -148,11 +186,7 @@ export const getResult = async (incomingMessage: Message) => {
const poll = await getPoll(pollID);
if (!poll)
return incomingMessage.channel.send(
- createBasicEmbed(
- "Poll ID invalid!",
- "Please check your Poll ID, or maybe even your command syntax!",
- "ERROR"
- )
+ createBasicEmbed(ERRORS.INVALID_POLL, "ERROR")
);
incomingMessage.channel.send(createPollResult(poll));
} else {
@@ -161,14 +195,26 @@ export const getResult = async (incomingMessage: Message) => {
incomingMessage.content.split(" ").splice(0, 5),
"Invalid command"
);
- incomingMessage.channel.send(invalidCommand());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.INVALID_COMMAND, "ERROR")
+ );
}
} catch (err) {
serverLogger("internal-error", "Internal Error", err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(
+ ERRORS.INTERNAL_ERROR(messageType.channelType),
+ "ERROR"
+ )
+ );
}
} else {
serverLogger("user-error", incomingMessage.content, "Unauthorized User");
- incomingMessage.channel.send(unauthorizedUser());
+ incomingMessage.channel.send(
+ `<@${messageType.incomingUser.id}>`,
+ createBasicEmbed(ERRORS.UNAUTHORIZED_USER, "ERROR")
+ );
}
};
diff --git a/src/models/incomingMessage.ts b/src/models/incomingMessage.ts
new file mode 100644
index 0000000..384fab0
--- /dev/null
+++ b/src/models/incomingMessage.ts
@@ -0,0 +1,11 @@
+export interface incomingMessageSchema {
+ //incoming user properties
+ incomingUser: {
+ isMod: boolean;
+ username: string;
+ discriminator: string;
+ id: string;
+ };
+ //channel types
+ channelType: "dm" | "text" | "news";
+}
diff --git a/src/models/poll.ts b/src/models/poll.ts
index ec48ace..97b3f40 100644
--- a/src/models/poll.ts
+++ b/src/models/poll.ts
@@ -1,11 +1,12 @@
export interface pollSchema {
- title: string; // title of the poll
- pollID: string; // unique id of poll
+ title: string; // title of the poll
+ pollID: string; // unique id of poll
channelID: string; // channel on which the poll is going
- options: Array<{ // options array of the poll
+ options: Array<{
+ // options array of the poll
value: string;
emoji: string;
reactions: Array;
}>;
- timestamp: Date | string; // chann
+ timestamp: Date | string; // poll creation timestamp
}
diff --git a/src/service/certificate-service.ts b/src/service/certificate-service.ts
index cf81273..d476999 100644
--- a/src/service/certificate-service.ts
+++ b/src/service/certificate-service.ts
@@ -1,15 +1,9 @@
import { Message } from "discord.js";
import { generateCertificate } from "../helper/certificate";
import { Email } from "../models/email";
-import {
- certificateMessage,
- internalError,
- waitCertificateMessage,
- certificateNotAccessible,
- createBasicEmbed,
-} from "../utils/messages";
+import { certificateMessage, createBasicEmbed } from "../utils/messages";
import { getDbClient } from "../utils/database";
-import { ERRORS } from "../utils/constants";
+import { ERRORS, INFO } from "../utils/constants";
import { channelLogger, serverLogger } from "../utils/logger";
import { getEvent } from "../utils/nodecache";
@@ -22,7 +16,7 @@ export async function getUserCertificate(
const event = await getEvent(eventSlug);
if (!event) throw "eventKey Not Found in NodeCache!";
if (event.enabled) {
- incomingMessage.channel.send(waitCertificateMessage());
+ incomingMessage.channel.send(createBasicEmbed(INFO.WAIT, "INFO"));
const dbClient = await getDbClient();
const found = await dbClient
.db()
@@ -58,22 +52,22 @@ export async function getUserCertificate(
"Certificate Not Found"
);
incomingMessage.channel.send(
- createBasicEmbed(
- "Certificate Not Found!",
- ERRORS.CERTIFICATE_NOT_FOUND,
- "ERROR"
- )
+ createBasicEmbed(ERRORS.CERTIFICATE_NOT_FOUND, "ERROR")
);
return false;
}
} else {
- incomingMessage.channel.send(certificateNotAccessible());
+ incomingMessage.channel.send(
+ createBasicEmbed(ERRORS.CERT_NOT_ACCESS, "ERROR")
+ );
serverLogger("user-error", incomingMessage.content, `Certificate N/A`);
return true;
}
} catch (err) {
serverLogger("error", incomingMessage.content, err);
- incomingMessage.channel.send(internalError());
+ incomingMessage.channel.send(
+ createBasicEmbed(ERRORS.INTERNAL_ERROR("dm"), "ERROR")
+ );
return true;
}
}
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index 057cecc..f836bb3 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -1,14 +1,102 @@
-import { User, MessageEmbed } from "discord.js";
+import { User, MessageEmbed, GuildMember } from "discord.js";
+import { config } from "dotenv";
+config();
+
+/**
+ * Error Messages
+ */
export const ERRORS = {
- DM_BLOCKED: (user: User) =>
- `**Oopsie!** <@${user.id}>, it seems your **DM is blocked**. Please **change the settings** and request again!`,
- CERTIFICATE_NOT_FOUND:
- "**Oops!** A wide search across our records, but we couldn't trace your data. Our insights say you weren't able to register for the event. Hope to see you soon next time!",
- EMAIL_MISSING: "Invalid Command! Type `#kzjack help` for a list of commands",
- INVALID_EMAIL: "Oops! The email is malformed or invalid. Please try again!",
- URL_MISSING: "Invalid Command! Type `#kzjack help` for a list of commands",
+ DM_BLOCKED: {
+ title: "DM Blocked!",
+ message: (user: User) => {
+ return `**Oopsie!** <@${user.id}>, it seems your **DM is blocked**. Please **change the settings** and request again!`;
+ },
+ },
+ CERTIFICATE_NOT_FOUND: {
+ title: "Certificate Not Found!",
+ message:
+ "**Oops!** A wide search across our records, but we couldn't trace your data. Our insights say you weren't able to register for the event. Hope to see you soon next time!",
+ },
+ URL_MISSING: {
+ title: "URL Missing!",
+ message: "Invalid Command! Type `#kzjack help` for a list of commands",
+ },
+ INVALID_EMAIL: {
+ title: "Invalid Email!",
+ message:
+ "Oops! The e-mail seems to be invalid or malformed! Please try again!",
+ },
+ INVALID_COMMAND: {
+ title: "Oopsie! I didn't get that",
+ message:
+ "Oops! It seems you have entered an invalid command.\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ EVENT_DNE: {
+ title: "Event Does Not Exist!",
+ message:
+ "Oops! It seems you have entered an invalid slug for an event! Double check your inputs!\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ INTERNAL_ERROR: (messageType: "dm" | "text" | "news") => {
+ return {
+ title: "Uhu! I encountered an error",
+ message:
+ "Error 500! Our hamsters encountered a bug. Seek out to any" +
+ (messageType == "dm"
+ ? "** @Moderator **"
+ : `<@${process.env.OPERATOR_ROLE_ID}`) +
+ "for support, if you need one.\n\n**Help**\nType `#kzjack help` for a list of commands",
+ };
+ },
+ UNAUTHORIZED_USER: {
+ title: "Wait! This area is not accessible.",
+ message:
+ "Oops! You are not authorized to use this command. Please contact any moderator for the same.\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ INVALID_URL: {
+ title: "Malformed URL",
+ message:
+ "Whoooop! It seems you entered an invalid or malformed URL\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ INVALID_CHANNEL: {
+ title: "Invalid Channel Name",
+ message:
+ "Oops! It seems you have entered an invalid channel name. Please enter a valid one and try again!\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ CERT_NOT_ACCESS: {
+ title: "Ooops! Service Unavailable as the event hasn't ended yet!",
+ message:
+ "Please do join us at the event to explore awesomeness!\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ INVALID_POLL: {
+ title: "Poll ID invalid!",
+ message:
+ "Please check your Poll ID, or maybe even your command syntax!\n\n**Help**\nType `#kzjack help` for a list of commands",
+ },
+ MEMBER_LEAVE: (member: GuildMember) => {
+ return {
+ title: `A member left the server 🥺!`,
+ message: `<@${member.id}> left the server. Sorry to see you go!`,
+ };
+ },
+};
+
+export const INFO = {
+ WAIT: {
+ title: "Things worth having are worth waiting for! 😉",
+ message: "Please wait while we fetch a certificate for you! ⏲️",
+ },
+ MEMBER_JOIN: (member: GuildMember) => {
+ return {
+ title: `A new member joined the server 🥳!`,
+ message: `<@${member.id}> joined the server! Welcome home!`,
+ };
+ },
};
+
+/**
+ * Commands
+ */
export const COMMANDS = {
prefix: "#kzjack",
shrinkURL: "shrink",
@@ -22,17 +110,20 @@ export const COMMANDS = {
createPoll: "poll",
};
+/**
+ * Constant variables
+ */
export const CONSTANTS = {
thumbsUpEmoji: "👍",
pollReactions: ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣"],
jackLogo: "https://srmkzilla.net/static/jack_logo.png",
- certificateUserDirectMessage: (eventName: string) =>
+ certificateUserDirectMessage: (eventName: string, username: string) =>
new MessageEmbed()
.setTitle(`${eventName} Certificates`)
.setColor(COLORS.INFO)
.setDescription(
`
- **Yayy!** You've made it to the end of ${eventName}! 🥳
+ **Yayy @${username}!** You've made it to the end of ${eventName}! 🥳
**Thank you for attending!**
For your hard work, we would like to provide **certificates!** 🏆\n\n
`
diff --git a/src/utils/messages.ts b/src/utils/messages.ts
index 8abd342..5df632f 100644
--- a/src/utils/messages.ts
+++ b/src/utils/messages.ts
@@ -1,6 +1,7 @@
import { MessageEmbed } from "discord.js";
import { COLORS, CONSTANTS } from "./constants";
import { pollSchema } from "../models/poll";
+import { incomingMessageSchema } from "../models/incomingMessage";
export const getYourCertificateChannelMessage = (eventName: string) => {
return new MessageEmbed()
@@ -36,31 +37,8 @@ export const certificateMessage = async (cert: Buffer) => {
.attachFiles([{ attachment: cert, name: "certificate.jpeg" }]);
};
-export const waitCertificateMessage = () => {
- return new MessageEmbed()
- .setTitle("Things worth having are worth waiting for")
- .setColor(COLORS.INFO)
- .setDescription(`Please wait while we fetch a certificate for you!`)
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-export const certificateNotAccessible = () => {
- return new MessageEmbed()
- .setTitle("Ooops! Service Unavailable as the event hasn't ended yet!")
- .setColor(COLORS.ERROR)
- .setDescription(`Please do join us at the event to explore awesomeness!`)
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-
-export const getHelpMessage = () => {
- return new MessageEmbed()
+export const getHelpMessage = (messageType: incomingMessageSchema) => {
+ let message = new MessageEmbed()
.setTitle("Hi, This is Jack")
.setThumbnail(CONSTANTS.jackLogo)
.setColor(COLORS.INFO)
@@ -74,10 +52,6 @@ export const getHelpMessage = () => {
name: "Shrink URLs using KZILLA.XYZ",
value: "`#kzjack shrink `",
},
- {
- name: "Members Count",
- value: "`#kzjack membercount`",
- },
{
name: "Tell me a joke",
value: "`#kzjack joke`",
@@ -85,11 +59,23 @@ export const getHelpMessage = () => {
{
name: "Send Memes",
value: "`#kzjack meme`",
- },
+ }
+ );
+ if (
+ messageType.channelType === "text" ||
+ messageType.channelType === "news"
+ ) {
+ message.addFields({
+ name: "Members Count",
+ value: "`#kzjack membercount`",
+ });
+ }
+ if (messageType.incomingUser.isMod) {
+ message.addFields(
{
name: "Announcements [Only Mods]",
value:
- "`#kzjack announce here|everyone > {} `",
+ "`#kzjack announce here|everyone > <#channel> {} `",
},
{
name: "Start Certificates Thread [Only Mods]",
@@ -102,99 +88,21 @@ export const getHelpMessage = () => {
{
name: "Start a Poll (Upto 9 options) [Only Mods]",
value:
- "`#kzjack poll create {} [[],[ ],[ ],[ ]]`",
+ "`#kzjack poll create <#channel> {} [[],[ ],[ ],[ ]]`",
},
{
name: "Get Poll Results [Only Mods]",
value: "`#kzjack poll result `",
}
- )
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-export const invalidCommand = () => {
- return new MessageEmbed()
- .setTitle("Oopsie! I didn't get that")
- .setColor(COLORS.ERROR)
- .setDescription(`Oops! It seems you have entered an invalid command.`)
- .addFields({
- name: "Help",
- value: "Type `#kzjack help` for a list of commands",
- })
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
);
-};
-
-export const eventDoesNotExist = () => {
- return new MessageEmbed()
- .setTitle("Event Does Not Exist!")
- .setColor(COLORS.ERROR)
- .setDescription(
- `Oops! It seems you have entered an invalid slug for an event! Double check your inputs!`
- )
- .addFields({
- name: "Help",
- value: "Type `#kzjack help` for a list of commands",
- })
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-
-export const unauthorizedUser = () => {
- return new MessageEmbed()
- .setTitle("Wait! This area is not accessible.")
- .setColor(COLORS.ERROR)
- .setDescription(
- `Oops! You are not authorized to use this command. Please contact any moderator for the same.`
- )
- .addFields({
- name: "Help",
- value: "Type `#kzjack help` for a list of commands",
- })
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-
-export const invalidURL = () => {
- return new MessageEmbed()
- .setTitle("Malformed URL")
- .setColor(COLORS.ERROR)
- .setDescription(`Whoooop! It seems you entered an invalid or malformed URL`)
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-
-export const internalError = () => {
- return new MessageEmbed()
- .setTitle("Uhu! I encountered an error")
- .setColor(COLORS.ERROR)
- .setDescription(
- `Error 500! Our hamsters encountered a bug. Seek out to any <@&778861665826766868> or <@&761273035931516968> for support, if you need one. Type \`#kzjack\` for help`
- )
- .addFields({
- name: "Help",
- value: "Type `#kzjack help` for a list of commands",
- })
+ }
+ message
.setTimestamp()
.setFooter(
"Powered by SRMKZILLA and hamster-charged batteries",
"https://srmkzilla.net/assets/img/kzilla.png"
);
+ return message;
};
export const shrinkedURLMessage = (data: any) => {
@@ -257,20 +165,6 @@ export const membersCountMessage = (membersCount: number, botCount: number) => {
);
};
-export const invalidChannel = () => {
- return new MessageEmbed()
- .setTitle("Invalid Channel Name")
- .setColor(COLORS.ERROR)
- .setDescription(
- `Oops! It seems you have entered an invalid channel name. Please enter a valid one and try again!`
- )
- .setTimestamp()
- .setFooter(
- "Powered by SRMKZILLA and hamster-charged batteries",
- "https://srmkzilla.net/assets/img/kzilla.png"
- );
-};
-
export const announcementMessage = (title: string, message: string) => {
if (title == "null") {
return new MessageEmbed()
@@ -295,14 +189,13 @@ export const announcementMessage = (title: string, message: string) => {
};
export const createBasicEmbed = (
- title: string,
- message: string,
+ msg: { title: string; message: string },
level: "SUCCESS" | "INFO" | "ERROR" | "ANNOUNCEMENT"
) => {
return new MessageEmbed()
.setColor(COLORS[level])
- .setTitle(title)
- .setDescription(message)
+ .setTitle(msg.title)
+ .setDescription(msg.message)
.setTimestamp()
.setFooter(
"Powered by SRMKZILLA and hamster-charged batteries",