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:
parent
d2083bea53
commit
23c16f7832
|
@ -5,28 +5,37 @@ import utils from "../utils.ts";
|
||||||
import { LogTypes as LT } from "../utils.enums.ts";
|
import { LogTypes as LT } from "../utils.enums.ts";
|
||||||
import { EmojiConf } from "../mod.d.ts";
|
import { EmojiConf } from "../mod.d.ts";
|
||||||
|
|
||||||
export const emoji = (message: DiscordenoMessage, command: string) => {
|
const allEmojiAliases: 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)}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Send the needed emoji1
|
config.emojis.forEach((emoji: EmojiConf) => {
|
||||||
message.send(`<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}>`).catch(e => {
|
allEmojiAliases.push(...emoji.aliases)
|
||||||
utils.log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
});
|
||||||
});
|
|
||||||
// And attempt to delete if needed
|
export const emoji = (message: DiscordenoMessage, command: string) => {
|
||||||
if (emoji.deleteSender) {
|
// shortcut
|
||||||
message.delete().catch(e => {
|
if (allEmojiAliases.indexOf(command)) {
|
||||||
utils.log(LT.WARN, `Failed to delete message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
|
// 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;
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,23 +33,23 @@ export const constantCmds = {
|
||||||
title: "Available API Commands:",
|
title: "Available API Commands:",
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "[[api help",
|
name: `\`${config.prefix}api help\``,
|
||||||
value: "This command",
|
value: "This command",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[api status",
|
name: `\`${config.prefix}api status\``,
|
||||||
value: "Shows the current status of the API for this guild",
|
value: "Shows the current status of the API for this guild",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[api allow/enable",
|
name: `\`${config.prefix}api allow/enable\``,
|
||||||
value: "Allows API Rolls to be sent to this guild",
|
value: "Allows API Rolls to be sent to this guild",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[api block/disable",
|
name: `\`${config.prefix}api block/disable\``,
|
||||||
value: "Blocks API Rolls from being sent to this guild",
|
value: "Blocks API Rolls from being sent to this guild",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[api delete",
|
name: `\`${config.prefix}api delete\``,
|
||||||
value: "Deletes this guild from The Artificer's database",
|
value: "Deletes this guild from The Artificer's database",
|
||||||
inline: true
|
inline: true
|
||||||
}
|
}
|
||||||
|
@ -83,48 +83,48 @@ export const constantCmds = {
|
||||||
title: "The Artificer's Available Commands:",
|
title: "The Artificer's Available Commands:",
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "[[?",
|
name: `\`${config.prefix}?\``,
|
||||||
value: "This command",
|
value: "This command",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[rollhelp or [[??",
|
name: `\`${config.prefix}rollhelp\` or \`${config.prefix}??\``,
|
||||||
value: "Details on how to use the roll command, listed as `[[xdy...]]` below",
|
value: `Details on how to use the roll command, listed as \`${config.prefix}xdy...${config.postfix}\` below`,
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[api [subcommand]",
|
name: `\`${config.prefix}api [subcommand]\``,
|
||||||
value: "Administrative tools for the bots's API, run [[api help for more details",
|
value: `Administrative tools for the bots's API, run \`${config.prefix}api help\` for more details`,
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[ping",
|
name: `\`${config.prefix}ping\``,
|
||||||
value: "Pings the bot to check connectivity",
|
value: "Pings the bot to check connectivity",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[info",
|
name: `\`${config.prefix}info\``,
|
||||||
value: "Prints some information and links relating to the bot",
|
value: "Prints some information and links relating to the bot",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[privacy",
|
name: `\`${config.prefix}privacy\``,
|
||||||
value: "Prints some information about the Privacy Policy",
|
value: "Prints some information about the Privacy Policy",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[version",
|
name: `\`${config.prefix}version\``,
|
||||||
value: "Prints the bots version",
|
value: "Prints the bots version",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[popcat",
|
name: `\`${config.prefix}popcat\``,
|
||||||
value: "Popcat",
|
value: "Popcat",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[report [text]",
|
name: `\`${config.prefix}report [text]\``,
|
||||||
value: "Report a command that failed to run",
|
value: "Report a command that failed to run",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[stats",
|
name: `\`${config.prefix}stats\``,
|
||||||
value: "Statistics on the bot",
|
value: "Statistics on the bot",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "[[xdydzracsq!]] ...",
|
name: `\`${config.prefix}xdydzracsq!${config.postfix}\` ...`,
|
||||||
value: "Rolls all configs requested, you may repeat the command multiple times in the same message (just ensure you close each roll with ]]), run [[?? for more details",
|
value: `Rolls all configs requested, you may repeat the command multiple times in the same message (just ensure you close each roll with \`${config.postfix}\`), run \`${config.prefix}??\` for more details`,
|
||||||
inline: true
|
inline: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -151,7 +151,7 @@ export const constantCmds = {
|
||||||
title: "Privacy Policy",
|
title: "Privacy Policy",
|
||||||
fields: [{
|
fields: [{
|
||||||
name: "The Artificer does not track or collect user information via Discord.",
|
name: "The Artificer does not track or collect user information via Discord.",
|
||||||
value: `The only user submitted information that is stored is submitted via the \`[[report\` command. This information is only stored for a short period of time in a location that only the Developer of The Artificer can see.
|
value: `The only user submitted information that is stored is submitted via the \`${config.prefix}report\` command. This information is only stored for a short period of time in a location that only the Developer of The Artificer can see.
|
||||||
|
|
||||||
For more details, please check out the Privacy Policy on the GitHub [here](https://github.com/Burn-E99/TheArtificer/blob/master/PRIVACY.md).
|
For more details, please check out the Privacy Policy on the GitHub [here](https://github.com/Burn-E99/TheArtificer/blob/master/PRIVACY.md).
|
||||||
|
|
||||||
|
@ -196,63 +196,63 @@ export const constantCmds = {
|
||||||
|
|
||||||
This command also can fully solve math equations with parenthesis.`
|
This command also can fully solve math equations with parenthesis.`
|
||||||
}, {
|
}, {
|
||||||
name: "[[xdydzracsq!]] ...",
|
name: `\`${config.prefix}xdydzracsq!${config.postfix}\` ...`,
|
||||||
value: "Rolls all configs requested, you may repeat the command multiple times in the same message (just ensure you close each roll with ]])",
|
value: `Rolls all configs requested, you may repeat the command multiple times in the same message (just ensure you close each roll with \`${config.postfix}\`)`,
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "x [Optional]",
|
name: "`x` [Optional]",
|
||||||
value: "Number of dice to roll, if omitted, 1 is used",
|
value: "Number of dice to roll, if omitted, 1 is used",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "dy [Required]",
|
name: "`dy` [Required]",
|
||||||
value: "Size of dice to roll, d20 = 20 sided die",
|
value: "Size of dice to roll, `d20` = 20 sided die",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "dz or dlz [Optional]",
|
name: "`dz` or `dlz` [Optional]",
|
||||||
value: "Drops the lowest `z` dice, cannot be used with kz",
|
value: "Drops the lowest `z` dice, cannot be used with `kz`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "kz or khz [Optional]",
|
name: "`kz` or `khz` [Optional]",
|
||||||
value: "Keeps the highest `z` dice, cannot be used with dz",
|
value: "Keeps the highest `z` dice, cannot be used with `dz`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "dhz [Optional]",
|
name: "`dhz` [Optional]",
|
||||||
value: "Drops the highest `z` dice, cannot be used with kz",
|
value: "Drops the highest `z` dice, cannot be used with `kz`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "klz [Optional]",
|
name: "`klz` [Optional]",
|
||||||
value: "Keeps the lowest `z` dice, cannot be used with dz",
|
value: "Keeps the lowest `z` dice, cannot be used with `dz`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "ra [Optional]",
|
name: "`ra` [Optional]",
|
||||||
value: "Rerolls any rolls that match `a`, r3 will reroll any dice that land on 3, throwing out old rolls",
|
value: "Rerolls any rolls that match `a`, `r3` will reroll any dice that land on 3, throwing out old rolls",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "csq or cs=q [Optional]",
|
name: "`csq` or `cs=q` [Optional]",
|
||||||
value: "Changes crit score to `q`",
|
value: "Changes crit score to `q`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "cs<q [Optional]",
|
name: "`cs<q` [Optional]",
|
||||||
value: "Changes crit score to be less than or equal to `q`",
|
value: "Changes crit score to be less than or equal to `q`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "cs>q [Optional]",
|
name: "`cs>q` [Optional]",
|
||||||
value: "Changes crit score to be greater than or equal to `q`",
|
value: "Changes crit score to be greater than or equal to `q`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "cfq or cf=q [Optional]",
|
name: "`cfq` or `cf=q` [Optional]",
|
||||||
value: "Changes crit fail to `q`",
|
value: "Changes crit fail to `q`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "cf<q [Optional]",
|
name: "`cf<q` [Optional]",
|
||||||
value: "Changes crit fail to be less than or equal to `q`",
|
value: "Changes crit fail to be less than or equal to `q`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "cf>q [Optional]",
|
name: "`cf>q` [Optional]",
|
||||||
value: "Changes crit fail to be greater than or equal to `q`",
|
value: "Changes crit fail to be greater than or equal to `q`",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "! [Optional]",
|
name: "`!` [Optional]",
|
||||||
value: "Exploding, rolls another dy for every crit roll",
|
value: "Exploding, rolls another dy for every crit roll",
|
||||||
inline: true
|
inline: true
|
||||||
}
|
}
|
||||||
|
@ -264,29 +264,29 @@ export const constantCmds = {
|
||||||
name: "Details",
|
name: "Details",
|
||||||
value: `This command also has some useful flags that can used. These flags simply need to be placed after all rolls in the message.
|
value: `This command also has some useful flags that can used. These flags simply need to be placed after all rolls in the message.
|
||||||
|
|
||||||
Examples: \`[[d20]] -nd\`, \`[[d20]] -nd -s\``
|
Examples: \`${config.prefix}d20${config.postfix} -nd\`, \`${config.prefix}d20${config.postfix} -nd -s\``
|
||||||
}, {
|
}, {
|
||||||
name: "-nd",
|
name: "`-nd`",
|
||||||
value: "No Details - Suppresses all details of the requested roll",
|
value: "No Details - Suppresses all details of the requested roll",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "-s",
|
name: "`-s`",
|
||||||
value: "Spoiler - Spoilers all details of the requested roll",
|
value: "Spoiler - Spoilers all details of the requested roll",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "-m",
|
name: "`-m`",
|
||||||
value: "Maximize Roll - Rolls the theoretical maximum roll, cannot be used with -n",
|
value: "Maximize Roll - Rolls the theoretical maximum roll, cannot be used with -n",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "-n",
|
name: "`-n`",
|
||||||
value: "Nominal Roll - Rolls the theoretical nominal roll, cannot be used with -m",
|
value: "Nominal Roll - Rolls the theoretical nominal roll, cannot be used with -m",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "-gm @user1 @user2 @usern",
|
name: "`-gm @user1 @user2 @usern`",
|
||||||
value: "GM Roll - Rolls the requested roll in GM mode, suppressing all publicly shown results and details and sending the results directly to the specified GMs",
|
value: "GM Roll - Rolls the requested roll in GM mode, suppressing all publicly shown results and details and sending the results directly to the specified GMs",
|
||||||
inline: true
|
inline: true
|
||||||
}, {
|
}, {
|
||||||
name: "-o a or -o d",
|
name: "`-o a` or `-o d`",
|
||||||
value: "Order Roll - Rolls the requested roll and orders the results in the requested direction",
|
value: "Order Roll - Rolls the requested roll and orders the results in the requested direction",
|
||||||
inline: true
|
inline: true
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ export const generateRollError = (errorType: string, errorMsg: string) => ({
|
||||||
title: "Roll command encountered the following error:",
|
title: "Roll command encountered the following error:",
|
||||||
fields: [{
|
fields: [{
|
||||||
name: errorType,
|
name: errorType,
|
||||||
value: `${errorMsg}\n\nPlease try again. If the error is repeated, please report the issue using the \`[[report\` command.`
|
value: `${errorMsg}\n\nPlease try again. If the error is repeated, please report the issue using the \`${config.prefix}report\` command.`
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* December 21, 2020
|
* December 21, 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import config from "../config.ts";
|
||||||
import { RollSet, SolvedStep, SolvedRoll, ReturnData } from "./solver.d.ts";
|
import { RollSet, SolvedStep, SolvedRoll, ReturnData } from "./solver.d.ts";
|
||||||
import { LogTypes as LT } from "./utils.enums.ts";
|
import { LogTypes as LT } from "./utils.enums.ts";
|
||||||
import utils from "./utils.ts";
|
import utils from "./utils.ts";
|
||||||
|
@ -1013,7 +1014,7 @@ const parseRoll = (fullCmd: string, localPrefix: string, localPostfix: string, m
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
utils.log(LT.ERROR, `Undangled Error: ${errorName}, ${errorDetails}`);
|
utils.log(LT.ERROR, `Undangled Error: ${errorName}, ${errorDetails}`);
|
||||||
errorMsg = `Unhandled Error: ${solverError.message}\nCheck input and try again, if issue persists, please use \`[[report\` to alert the devs of the issue`;
|
errorMsg = `Unhandled Error: ${solverError.message}\nCheck input and try again, if issue persists, please use \`${config.prefix}report\` to alert the devs of the issue`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue