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:
@@ -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;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user