1
1
mirror of https://github.com/Burn-E99/TheArtificer.git synced 2026-06-04 09:03:50 -04:00

Optimized emoji command, made all command responsess more dynamic

Emoji command should be significantly more optimized by rejecting non-emojis much faster
Bot will now respond with the prefix/postfix set in the config instead of assuming the prefix/postfix are always [[/]]
This commit is contained in:
Ean Milligan (Bastion)
2022-05-05 02:19:19 -04:00
parent d2083bea53
commit 23c16f7832
3 changed files with 82 additions and 72 deletions

View File

@@ -5,28 +5,37 @@ import utils from "../utils.ts";
import { LogTypes as LT } from "../utils.enums.ts";
import { EmojiConf } from "../mod.d.ts";
export const emoji = (message: DiscordenoMessage, command: string) => {
// Start looping thru the possible emojis
config.emojis.some((emoji: EmojiConf) => {
utils.log(LT.LOG, `Checking if command was emoji ${JSON.stringify(emoji)}`);
// If a match gets found
if (emoji.aliases.indexOf(command || "") > -1) {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("emojis");`).catch(e => {
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
});
const allEmojiAliases: string[] = [];
// Send the needed emoji1
message.send(`<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}>`).catch(e => {
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
// And attempt to delete if needed
if (emoji.deleteSender) {
message.delete().catch(e => {
utils.log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
config.emojis.forEach((emoji: EmojiConf) => {
allEmojiAliases.push(...emoji.aliases)
});
export const emoji = (message: DiscordenoMessage, command: string) => {
// shortcut
if (allEmojiAliases.indexOf(command)) {
// Start looping thru the possible emojis
config.emojis.some((emoji: EmojiConf) => {
utils.log(LT.LOG, `Checking if command was emoji ${JSON.stringify(emoji)}`);
// If a match gets found
if (emoji.aliases.indexOf(command || "") > -1) {
// Light telemetry to see how many times a command is being run
dbClient.execute(`CALL INC_CNT("emojis");`).catch(e => {
utils.log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
});
// Send the needed emoji1
message.send(`<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}>`).catch(e => {
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
// And attempt to delete if needed
if (emoji.deleteSender) {
message.delete().catch(e => {
utils.log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
});
}
return true;
}
return true;
}
});
});
}
};