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

Sonar Cleanup - Phase 1

This commit is contained in:
Ean Milligan (Bastion)
2022-05-22 15:29:59 -04:00
parent 46d6014ed5
commit 891a36a9ba
10 changed files with 59 additions and 52 deletions

View File

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

View File

@@ -530,13 +530,16 @@ export const generateApiFailed = (args: string) => ({
}],
});
export const generateApiStatus = (banned: boolean, active: boolean) => ({
embeds: [{
color: infoColor1,
title: `The Artificer's API is ${config.api.enable ? 'currently enabled' : 'currently disabled'}.`,
description: banned ? 'API rolls are banned from being used in this guild.\n\nThis will not be reversed.' : `API rolls are ${active ? 'allowed' : 'blocked from being used'} in this guild.`,
}],
});
export const generateApiStatus = (banned: boolean, active: boolean) => {
const apiStatus = active ? 'allowed' : 'blocked from being used';
return {
embeds: [{
color: infoColor1,
title: `The Artificer's API is ${config.api.enable ? 'currently enabled' : 'currently disabled'}.`,
description: banned ? 'API rolls are banned from being used in this guild.\n\nThis will not be reversed.' : `API rolls are ${apiStatus} in this guild.`,
}]
};
};
export const generateApiSuccess = (args: string) => ({
embeds: [{

View File

@@ -32,10 +32,10 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
const tempReturnData: ReturnData[] = [];
// Loop thru all roll/math ops
for (let i = 0; i < sepRolls.length; i++) {
log(LT.LOG, `Parsing roll ${fullCmd} | Working ${sepRolls[i]}`);
for (const sepRoll of sepRolls) {
log(LT.LOG, `Parsing roll ${fullCmd} | Working ${sepRoll}`);
// Split the current iteration on the command postfix to separate the operation to be parsed and the text formatting after the opertaion
const [tempConf, tempFormat] = sepRolls[i].split(config.postfix);
const [tempConf, tempFormat] = sepRoll.split(config.postfix);
// Remove all spaces from the operation config and split it by any operator (keeping the operator in mathConf for fullSolver to do math on)
const mathConf: (string | number | SolvedStep)[] = <(string | number | SolvedStep)[]> tempConf.replace(/ /g, '').split(/([-+()*/%^])/g);

View File

@@ -13,9 +13,13 @@ export const MAXLOOPS = 5000000;
// genRoll(size) returns number
// genRoll rolls a die of size size and returns the result
export const genRoll = (size: number): number => {
// Math.random * size will return a decimal number between 0 and size (excluding size), so add 1 and floor the result to not get 0 as a result
return Math.floor((Math.random() * size) + 1);
export const genRoll = (size: number, maximiseRoll: boolean, nominalRoll: boolean): number => {
if (maximiseRoll) {
return size;
} else {
// Math.random * size will return a decimal number between 0 and size (excluding size), so add 1 and floor the result to not get 0 as a result
return nominalRoll ? ((size / 2) + 0.5) : Math.floor((Math.random() * size) + 1);
}
};
// compareRolls(a, b) returns -1|0|1
@@ -58,11 +62,11 @@ export const compareOrigidx = (a: RollSet, b: RollSet): number => {
// escapeCharacters escapes all characters listed in esc
export const escapeCharacters = (str: string, esc: string): string => {
// Loop thru each esc char one at a time
for (let i = 0; i < esc.length; i++) {
log(LT.LOG, `Escaping character ${esc[i]} | ${str}, ${esc}`);
for (const e of esc) {
log(LT.LOG, `Escaping character ${e} | ${str}, ${esc}`);
// Create a new regex to look for that char that needs replaced and escape it
const temprgx = new RegExp(`[${esc[i]}]`, 'g');
str = str.replace(temprgx, `\\${esc[i]}`);
const temprgx = new RegExp(`[${e}]`, 'g');
str = str.replace(temprgx, `\\${e}`);
}
return str;
};

View File

@@ -349,7 +349,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Copy the template to fill out for this iteration
const rolling = JSON.parse(JSON.stringify(templateRoll));
// If maximiseRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
rolling.roll = maximiseRoll ? rollConf.dieSize : (nominalRoll ? ((rollConf.dieSize / 2) + 0.5) : genRoll(rollConf.dieSize));
rolling.roll = genRoll(rollConf.dieSize, maximiseRoll, nominalRoll);
// Set origidx of roll
rolling.origidx = i;
@@ -388,7 +388,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Copy the template to fill out for this iteration
const newRoll = JSON.parse(JSON.stringify(templateRoll));
// If maximiseRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
newRoll.roll = maximiseRoll ? rollConf.dieSize : (nominalRoll ? ((rollConf.dieSize / 2) + 0.5) : genRoll(rollConf.dieSize));
newRoll.roll = genRoll(rollConf.dieSize, maximiseRoll, nominalRoll);
// If critScore arg is on, check if the roll should be a crit, if its off, check if the roll matches the die size
if (rollConf.critScore.on && rollConf.critScore.range.indexOf(newRoll.roll) >= 0) {
@@ -415,7 +415,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea
// Copy the template to fill out for this iteration
const newRoll = JSON.parse(JSON.stringify(templateRoll));
// If maximiseRoll is on, set the roll to the dieSize, else if nominalRoll is on, set the roll to the average roll of dieSize, else generate a new random roll
newRoll.roll = maximiseRoll ? rollConf.dieSize : (nominalRoll ? ((rollConf.dieSize / 2) + 0.5) : genRoll(rollConf.dieSize));
newRoll.roll = genRoll(rollConf.dieSize, maximiseRoll, nominalRoll);
// Always mark this roll as exploding
newRoll.exploding = true;