From 6e1c6e8db39e08c4d4a4b57bdede6a1461cdd41e Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Thu, 1 May 2025 17:56:06 -0400 Subject: [PATCH] [untested] - start reorganizing the solver folder (renamed to artigen here), organize imports better since deno has support for it now --- .vscode/settings.json | 1 + CONTRIBUTING.md | 10 ++ artificer.rc | 2 +- artificer.service | 2 +- db/initialize.ts | 4 +- db/populateDefaults.ts | 2 +- deno.json | 14 +++ deps.ts | 29 ------ flags.ts | 2 +- mod.ts | 45 ++++++--- src/api.ts | 16 ++- src/artigen/artigen.README.md | 2 + src/{solver => artigen}/counter.ts | 2 +- src/artigen/managers/queueManager.ts | 49 ++++++++++ .../managers/workerManager.ts} | 98 +++++-------------- src/{solver => artigen}/parser.ts | 41 ++++---- src/{solver => artigen}/rollFormatter.ts | 16 ++- src/{solver => artigen}/rollUtils.ts | 12 +-- src/{solver => artigen}/rollWorker.ts | 8 +- src/{solver => artigen}/roller.ts | 22 ++--- src/{solver => artigen}/solver.d.ts | 3 +- src/{solver => artigen}/solver.ts | 19 ++-- src/commandUtils.ts | 15 +-- src/commands/_index.ts | 36 +++---- src/commands/apiCmd.ts | 22 ++--- src/commands/apiCmd/_index.ts | 10 +- src/commands/apiCmd/allowBlock.ts | 13 ++- src/commands/apiCmd/apiHelp.ts | 16 ++- src/commands/apiCmd/deleteGuild.ts | 16 +-- src/commands/apiCmd/showHideWarn.ts | 13 ++- src/commands/apiCmd/status.ts | 13 ++- src/commands/audit.ts | 21 ++-- src/commands/auditCmd/_index.ts | 6 +- src/commands/auditCmd/auditDB.ts | 16 ++- src/commands/auditCmd/auditGuilds.ts | 44 ++++----- src/commands/auditCmd/auditHelp.ts | 13 ++- src/commands/emoji.ts | 22 ++--- src/commands/handleMentions.ts | 22 ++--- src/commands/heatmap.ts | 20 ++-- src/commands/help.ts | 21 ++-- src/commands/info.ts | 18 ++-- src/commands/optIn.ts | 18 ++-- src/commands/optOut.ts | 18 ++-- src/commands/ping.ts | 15 ++- src/commands/privacy.ts | 21 ++-- src/commands/report.ts | 20 ++-- src/commands/rip.ts | 18 ++-- src/commands/roll.ts | 30 +++--- src/commands/roll/_index.ts | 2 +- src/commands/roll/getModifiers.ts | 34 ++++--- src/commands/rollDecorators.ts | 21 ++-- src/commands/rollHelp.ts | 48 +++++---- src/commands/stats.ts | 23 ++--- src/commands/version.ts | 18 ++-- src/commonEmbeds.ts | 2 +- src/db/client.ts | 7 +- src/db/common.ts | 2 +- src/endpoints/_index.ts | 23 +++-- src/endpoints/deletes/apiKeyDelete.ts | 24 ++--- src/endpoints/gets/apiChannel.ts | 10 +- src/endpoints/gets/apiKey.ts | 24 ++--- src/endpoints/gets/apiKeyAdmin.ts | 19 ++-- src/endpoints/gets/apiRoll.ts | 32 +++--- src/endpoints/gets/heatmapPng.ts | 6 +- src/endpoints/posts/apiChannelAdd.ts | 10 +- src/endpoints/puts/apiChannelManageActive.ts | 10 +- src/endpoints/puts/apiChannelManageBan.ts | 13 ++- src/endpoints/puts/apiKeyManage.ts | 13 ++- src/endpoints/stdResponses.ts | 10 +- src/intervals.ts | 31 +++--- src/mod.d.ts | 10 +- src/solver/_index.ts | 5 - src/utils.ts | 17 +--- start.command | 2 +- 74 files changed, 645 insertions(+), 667 deletions(-) create mode 100644 CONTRIBUTING.md delete mode 100644 deps.ts create mode 100644 src/artigen/artigen.README.md rename src/{solver => artigen}/counter.ts (89%) create mode 100644 src/artigen/managers/queueManager.ts rename src/{solver/rollQueue.ts => artigen/managers/workerManager.ts} (71%) rename src/{solver => artigen}/parser.ts (94%) rename src/{solver => artigen}/rollFormatter.ts (89%) rename src/{solver => artigen}/rollUtils.ts (92%) rename src/{solver => artigen}/rollWorker.ts (77%) rename src/{solver => artigen}/roller.ts (98%) rename src/{solver => artigen}/solver.d.ts (98%) rename src/{solver => artigen}/solver.ts (95%) delete mode 100644 src/solver/_index.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 7c97844..666f4fa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ ], "spellright.documentTypes": [], "cSpell.words": [ + "artigen", "channelid", "CWOD", "DEVMODE", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..14be3fa --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +## Imports +- Should be grouped the following order: + - `@` (third party) + - `/` (root directory) + - `artigen` + - `commands` + - `db` + - `endpoints` + - `src` +- Should be alphabetical by import source file name \ No newline at end of file diff --git a/artificer.rc b/artificer.rc index b0808a4..df85f26 100644 --- a/artificer.rc +++ b/artificer.rc @@ -10,7 +10,7 @@ pidfile="/var/dbots/TheArtificer/artificer.pid" artificer_root="/var/dbots/TheArtificer" artificer_write="./logs/,./src/endpoints/gets/heatmap.png" -artificer_read="./src/solver/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./flags.ts,./src/mod.d.ts" +artificer_read="./src/artigen/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./flags.ts,./src/mod.d.ts" artificer_log="/var/log/artificer.log" artificer_chdir="${artificer_root}" diff --git a/artificer.service b/artificer.service index 2edea59..ad0bd7f 100644 --- a/artificer.service +++ b/artificer.service @@ -6,7 +6,7 @@ After=network.target [Service] Type=simple PIDFile=/run/deno.pid -ExecStart=/root/.deno/bin/deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/solver/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./flags.ts,./src/mod.d.ts --allow-net --allow-import .\mod.ts +ExecStart=/root/.deno/bin/deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/artigen/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./flags.ts,./src/mod.d.ts --allow-net --allow-import .\mod.ts RestartSec=60 Restart=on-failure diff --git a/db/initialize.ts b/db/initialize.ts index 88faf02..a988469 100644 --- a/db/initialize.ts +++ b/db/initialize.ts @@ -1,8 +1,8 @@ // This file will create all tables for the artificer schema // DATA WILL BE LOST IF DB ALREADY EXISTS, RUN AT OWN RISK -import config from '../config.ts'; -import dbClient from '../src/db/client.ts'; +import config from '/config.ts'; +import dbClient from 'db/client.ts'; console.log('Attempting to create DB'); await dbClient.execute(`CREATE SCHEMA IF NOT EXISTS ${config.db.name};`); diff --git a/db/populateDefaults.ts b/db/populateDefaults.ts index 563c505..d2ab33e 100644 --- a/db/populateDefaults.ts +++ b/db/populateDefaults.ts @@ -1,7 +1,7 @@ // This file will populate the tables with default values import config from '../config.ts'; -import dbClient from '../src/db/client.ts'; +import dbClient from 'src/db/client.ts'; console.log('Attempting to populate DB Admin API key'); await dbClient.execute('INSERT INTO all_keys(userid,apiKey) values(?,?)', [config.api.admin, config.api.adminKey]).catch((e) => { diff --git a/deno.json b/deno.json index e9165d5..cdca6c5 100644 --- a/deno.json +++ b/deno.json @@ -19,5 +19,19 @@ "indentWidth": 2, "singleQuote": true, "proseWrap": "preserve" + }, + "imports": { + "@discordeno": "https://deno.land/x/discordeno@12.0.1/mod.ts", + "@Log4Deno": "https://raw.githubusercontent.com/Burn-E99/Log4Deno/V2.1.1/mod.ts", + "@mysql": "https://deno.land/x/mysql@v2.12.1/mod.ts", + "@std/http": "jsr:@std/http@1.0.15", + "@nanoid": "https://deno.land/x/nanoid@v3.0.0/mod.ts", + "@imagescript": "https://deno.land/x/imagescript@1.3.0/mod.ts", + "/": "./", + "artigen/": "./src/artigen/", + "commands/": "./src/commands/", + "endpoints/": "./src/endpoints/", + "db/": "./src/db/", + "src/": "./src/" } } \ No newline at end of file diff --git a/deps.ts b/deps.ts deleted file mode 100644 index 3c75785..0000000 --- a/deps.ts +++ /dev/null @@ -1,29 +0,0 @@ -// All external dependencies are to be loaded here to make updating dependency versions much easier -export { - botId, - cache, - cacheHandlers, - DiscordActivityTypes, - editBotNickname, - editBotStatus, - getMessage, - hasGuildPermissions, - Intents, - sendDirectMessage, - sendMessage, - startBot, -} from 'https://deno.land/x/discordeno@12.0.1/mod.ts'; - -export type { CreateMessage, DiscordenoGuild, DiscordenoMessage, EmbedField } from 'https://deno.land/x/discordeno@12.0.1/mod.ts'; - -export { Client } from 'https://deno.land/x/mysql@v2.12.1/mod.ts'; - -export { STATUS_CODE, STATUS_TEXT } from 'jsr:@std/http@1.0.15'; - -export type { StatusCode } from 'jsr:@std/http@1.0.15'; - -export { nanoid } from 'https://deno.land/x/nanoid@v3.0.0/mod.ts'; - -export { closeLog, initLog, log, LogTypes as LT } from 'https://raw.githubusercontent.com/Burn-E99/Log4Deno/V2.1.1/mod.ts'; - -export * as is from 'https://deno.land/x/imagescript@1.3.0/mod.ts'; diff --git a/flags.ts b/flags.ts index 12d04c4..d58487d 100644 --- a/flags.ts +++ b/flags.ts @@ -3,4 +3,4 @@ export const DEVMODE = false; // DEBUG is used to toggle the cmdPrompt and show debug log messages export const DEBUG = false; // LOCALMODE is used to run a different bot token for local testing -export const LOCALMODE = false; +export const LOCALMODE = true; diff --git a/mod.ts b/mod.ts index 69c3d75..2584e41 100644 --- a/mod.ts +++ b/mod.ts @@ -3,17 +3,32 @@ * * December 21, 2020 */ +import { + botId, + cache, + DiscordActivityTypes, + DiscordenoGuild, + DiscordenoMessage, + editBotNickname, + editBotStatus, + Intents, + sendMessage, + startBot, +} from '@discordeno'; +import { initLog, log, LogTypes as LT } from '@Log4Deno'; -import config from './config.ts'; -import { DEBUG, DEVMODE, LOCALMODE } from './flags.ts'; -import { botId, cache, DiscordActivityTypes, DiscordenoGuild, DiscordenoMessage, editBotNickname, editBotStatus, initLog, Intents, log, LT, sendMessage, startBot } from './deps.ts'; -import api from './src/api.ts'; -import dbClient from './src/db/client.ts'; -import { ignoreList } from './src/db/common.ts'; -import commands from './src/commands/_index.ts'; -import intervals from './src/intervals.ts'; -import { successColor, warnColor } from './src/commandUtils.ts'; -import utils from './src/utils.ts'; +import config from '/config.ts'; +import { DEBUG, DEVMODE, LOCALMODE } from '/flags.ts'; + +import commands from 'commands/_index.ts'; + +import dbClient from 'db/client.ts'; +import { ignoreList } from 'db/common.ts'; + +import api from 'src/api.ts'; +import { successColor, warnColor } from 'src/commandUtils.ts'; +import intervals from 'src/intervals.ts'; +import utils from 'src/utils.ts'; // Extend the BigInt prototype to support JSON.stringify interface BigIntX extends BigInt { @@ -66,10 +81,12 @@ startBot({ }, 30000); // Interval to update bot list stats every 24 hours - LOCALMODE ? log(LT.INFO, 'updateListStatistics not running') : setInterval(() => { - log(LT.LOG, 'Updating all bot lists statistics'); - intervals.updateListStatistics(botId, cache.guilds.size + cache.dispatchedGuildIds.size); - }, 86400000); + LOCALMODE + ? log(LT.INFO, 'updateListStatistics not running') + : setInterval(() => { + log(LT.LOG, 'Updating all bot lists statistics'); + intervals.updateListStatistics(botId, cache.guilds.size + cache.dispatchedGuildIds.size); + }, 86400000); // Interval to update hourlyRates every hour setInterval(() => { diff --git a/src/api.ts b/src/api.ts index 85fc111..668c927 100644 --- a/src/api.ts +++ b/src/api.ts @@ -3,16 +3,14 @@ * * December 21, 2020 */ +import { log, LogTypes as LT } from '@Log4Deno'; -import config from '../config.ts'; -import { - // Log4Deno deps - log, - LT, -} from '../deps.ts'; -import dbClient from './db/client.ts'; -import endpoints from './endpoints/_index.ts'; -import stdResp from './endpoints/stdResponses.ts'; +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import endpoints from 'endpoints/_index.ts'; +import stdResp from 'endpoints/stdResponses.ts'; // start() returns nothing // start initializes and runs the entire API for the bot diff --git a/src/artigen/artigen.README.md b/src/artigen/artigen.README.md new file mode 100644 index 0000000..927c81b --- /dev/null +++ b/src/artigen/artigen.README.md @@ -0,0 +1,2 @@ +# artigen - The Artificer's Dice and Math Engine +artigen is the core engine powering The Artificer. diff --git a/src/solver/counter.ts b/src/artigen/counter.ts similarity index 89% rename from src/solver/counter.ts rename to src/artigen/counter.ts index f398d99..3b8e0b8 100644 --- a/src/solver/counter.ts +++ b/src/artigen/counter.ts @@ -1,4 +1,4 @@ -import { CountDetails, RollSet } from './solver.d.ts'; +import { CountDetails, RollSet } from 'artigen/solver.d.ts'; export const rollCounter = (rollSet: RollSet[]): CountDetails => { const countDetails = { diff --git a/src/artigen/managers/queueManager.ts b/src/artigen/managers/queueManager.ts new file mode 100644 index 0000000..3253360 --- /dev/null +++ b/src/artigen/managers/queueManager.ts @@ -0,0 +1,49 @@ +import config from '/config.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; +import { infoColor2, rollingEmbed } from 'src/commandUtils.ts'; +import { QueuedRoll } from 'src/mod.d.ts'; +import utils from 'src/utils.ts'; +import { currentWorkers, handleRollWorker } from 'artigen/managers/workerManager.ts'; + +const rollQueue: Array = []; + +// Runs the roll or queues it depending on how many workers are currently running +export const queueRoll = (rq: QueuedRoll) => { + if (rq.apiRoll) { + handleRollWorker(rq); + } else if (!rollQueue.length && currentWorkers < config.limits.maxWorkers) { + handleRollWorker(rq); + } else { + rollQueue.push(rq); + rq.dd.m + .edit({ + embeds: [ + { + color: infoColor2, + title: `${config.name} currently has its hands full and has queued your roll.`, + description: `There are currently ${currentWorkers + rollQueue.length} rolls ahead of this roll. + +The results for this roll will replace this message when it is done.`, + }, + ], + }) + .catch((e: Error) => utils.commonLoggers.messageEditError('rollQueue.ts:197', rq.dd.m, e)); + } +}; + +// Checks the queue constantly to make sure the queue stays empty +setInterval(() => { + log( + LT.LOG, + `Checking rollQueue for items, rollQueue length: ${rollQueue.length}, currentWorkers: ${currentWorkers}, config.limits.maxWorkers: ${config.limits.maxWorkers}` + ); + if (rollQueue.length && currentWorkers < config.limits.maxWorkers) { + const temp = rollQueue.shift(); + if (temp && !temp.apiRoll) { + temp.dd.m.edit(rollingEmbed).catch((e: Error) => utils.commonLoggers.messageEditError('rollQueue.ts:208', temp.dd.m, e)); + handleRollWorker(temp); + } else if (temp && temp.apiRoll) { + handleRollWorker(temp); + } + } +}, 1000); diff --git a/src/solver/rollQueue.ts b/src/artigen/managers/workerManager.ts similarity index 71% rename from src/solver/rollQueue.ts rename to src/artigen/managers/workerManager.ts index a99e2a5..38ed6ba 100644 --- a/src/solver/rollQueue.ts +++ b/src/artigen/managers/workerManager.ts @@ -1,36 +1,27 @@ -import config from '../../config.ts'; -import { DEVMODE } from '../../flags.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - // Log4Deno deps - log, - LT, - // Discordeno deps - sendDirectMessage, - sendMessage, -} from '../../deps.ts'; -import { SolvedRoll } from '../solver/solver.d.ts'; -import { ApiQueuedRoll, DDQueuedRoll, RollModifiers } from '../mod.d.ts'; -import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed, infoColor2, rollingEmbed } from '../commandUtils.ts'; -import stdResp from '../endpoints/stdResponses.ts'; -import utils from '../utils.ts'; -import { loggingEnabled } from './rollUtils.ts'; +import config from '/config.ts'; +import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed } from 'src/commandUtils.ts'; +import { QueuedRoll, RollModifiers } from 'src/mod.d.ts'; +import utils from 'src/utils.ts'; +import { SolvedRoll } from 'src/artigen/solver.d.ts'; +import { loggingEnabled } from 'src/artigen/rollUtils.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; +import { DEVMODE } from '/flags.ts'; +import dbClient from 'src/db/client.ts'; +import stdResp from 'src/endpoints/stdResponses.ts'; +import { DiscordenoMessage, sendDirectMessage, sendMessage } from '@discordeno'; +import { queries } from 'src/db/common.ts'; -let currentWorkers = 0; -const rollQueue: Array = []; +export let currentWorkers = 0; // Handle setting up and calling the rollWorker -const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => { +export const handleRollWorker = (rq: QueuedRoll) => { currentWorkers++; // gmModifiers used to create gmEmbed (basically just turn off the gmRoll) const gmModifiers = JSON.parse(JSON.stringify(rq.modifiers)); gmModifiers.gmRoll = false; - const rollWorker = new Worker(new URL('../solver/rollWorker.ts', import.meta.url).href, { type: 'module' }); + const rollWorker = new Worker(new URL('../artigen/rollWorker.ts', import.meta.url).href, { type: 'module' }); const workerTimeout = setTimeout(async () => { rollWorker.terminate(); @@ -44,12 +35,12 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => { ( await generateRollEmbed( rq.dd.message.authorId, - { + { error: true, errorCode: 'TooComplex', errorMsg: 'Error: Roll took too long to process, try breaking roll down into simpler parts', }, - {}, + {} ) ).embed, ], @@ -175,14 +166,14 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => { JSON.stringify( rq.modifiers.count ? { - counts: countEmbed, - details: pubEmbedDetails, - } + counts: countEmbed, + details: pubEmbedDetails, + } : { - details: pubEmbedDetails, - }, - ), - ), + details: pubEmbedDetails, + } + ) + ) ); } } @@ -194,44 +185,3 @@ const handleRollWorker = (rq: ApiQueuedRoll | DDQueuedRoll) => { } }); }; - -// Runs the roll or queues it depending on how many workers are currently running -export const queueRoll = (rq: ApiQueuedRoll | DDQueuedRoll) => { - if (rq.apiRoll) { - handleRollWorker(rq); - } else if (!rollQueue.length && currentWorkers < config.limits.maxWorkers) { - handleRollWorker(rq); - } else { - rq.dd.m - .edit({ - embeds: [ - { - color: infoColor2, - title: `${config.name} currently has its hands full and has queued your roll.`, - description: `There are currently ${currentWorkers + rollQueue.length} rolls ahead of this roll. - -The results for this roll will replace this message when it is done.`, - }, - ], - }) - .catch((e: Error) => utils.commonLoggers.messageEditError('rollQueue.ts:197', rq.dd.m, e)); - rollQueue.push(rq); - } -}; - -// Checks the queue constantly to make sure the queue stays empty -setInterval(() => { - log( - LT.LOG, - `Checking rollQueue for items, rollQueue length: ${rollQueue.length}, currentWorkers: ${currentWorkers}, config.limits.maxWorkers: ${config.limits.maxWorkers}`, - ); - if (rollQueue.length && currentWorkers < config.limits.maxWorkers) { - const temp = rollQueue.shift(); - if (temp && !temp.apiRoll) { - temp.dd.m.edit(rollingEmbed).catch((e: Error) => utils.commonLoggers.messageEditError('rollQueue.ts:208', temp.dd.m, e)); - handleRollWorker(temp); - } else if (temp && temp.apiRoll) { - handleRollWorker(temp); - } - } -}, 1000); diff --git a/src/solver/parser.ts b/src/artigen/parser.ts similarity index 94% rename from src/solver/parser.ts rename to src/artigen/parser.ts index 851b04c..d8a30a5 100644 --- a/src/solver/parser.ts +++ b/src/artigen/parser.ts @@ -1,22 +1,18 @@ -import { - log, - // Log4Deno deps - LT, -} from '../../deps.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; -import config from '../../config.ts'; +import config from '/config.ts'; -import { RollModifiers } from '../mod.d.ts'; -import { CountDetails, ReturnData, SolvedRoll, SolvedStep } from './solver.d.ts'; -import { compareTotalRolls, compareTotalRollsReverse, escapeCharacters, legalMathOperators, loggingEnabled } from './rollUtils.ts'; -import { formatRoll } from './rollFormatter.ts'; -import { fullSolver } from './solver.ts'; +import { RollModifiers } from 'src/mod.d.ts'; +import { CountDetails, ReturnData, SolvedRoll, SolvedStep } from 'artigen/solver.d.ts'; +import { compareTotalRolls, compareTotalRollsReverse, escapeCharacters, legalMathOperators, loggingEnabled } from 'artigen/rollUtils.ts'; +import { formatRoll } from 'artigen/rollFormatter.ts'; +import { fullSolver } from 'artigen/solver.ts'; // parseRoll(fullCmd, modifiers) // parseRoll handles converting fullCmd into a computer readable format for processing, and finally executes the solving export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll => { const operators = ['(', ')', '^', '*', '/', '%', '+', '-']; - const returnMsg = { + const returnMsg = { error: false, errorCode: '', errorMsg: '', @@ -37,6 +33,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll try { // Split the fullCmd by the command prefix to allow every roll/math op to be handled individually const sepRolls = fullCmd.split(config.prefix); + // TODO: HERE for the [[ ]] nesting stuff const tempReturnData: ReturnData[] = []; const tempCountDetails: CountDetails[] = [ @@ -57,7 +54,7 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll 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(/([-+()*/^]|(?tempConf.replace(/ /g, '').split(/([-+()*/^]|(? strMathConfI.endsWith(mathOp))) { @@ -176,10 +173,10 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll } else { // Handle normally, just set current item to negative if (typeof mathConf[i] === 'number') { - mathConf[i] = mathConf[i] * -1; + mathConf[i] = mathConf[i] * -1; } else { - ( mathConf[i]).total = ( mathConf[i]).total * -1; - ( mathConf[i]).details = `-${( mathConf[i]).details}`; + (mathConf[i]).total = (mathConf[i]).total * -1; + (mathConf[i]).details = `-${(mathConf[i]).details}`; } mathConf.splice(i - 1, 1); i--; @@ -258,12 +255,10 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll // Populate line2 (the results) and line3 (the details) with their data if (modifiers.order === '') { - line2 += `${preFormat}${modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}${ - escapeCharacters( - e.rollPostFormat, - '|*_~`', - ) - } `; + line2 += `${preFormat}${modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}${escapeCharacters( + e.rollPostFormat, + '|*_~`' + )} `; } else { // If order is on, turn rolls into csv without formatting line2 += `${preFormat}${modifiers.commaTotals ? e.rollTotal.toLocaleString() : e.rollTotal}${postFormat}, `; diff --git a/src/solver/rollFormatter.ts b/src/artigen/rollFormatter.ts similarity index 89% rename from src/solver/rollFormatter.ts rename to src/artigen/rollFormatter.ts index 18f8510..217cc22 100644 --- a/src/solver/rollFormatter.ts +++ b/src/artigen/rollFormatter.ts @@ -1,14 +1,10 @@ -import { - log, - // Log4Deno deps - LT, -} from '../../deps.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; -import { roll } from './roller.ts'; -import { rollCounter } from './counter.ts'; -import { RollFormat } from './solver.d.ts'; -import { loggingEnabled } from './rollUtils.ts'; -import { RollModifiers } from '../mod.d.ts'; +import { roll } from 'artigen/roller.ts'; +import { rollCounter } from 'artigen/counter.ts'; +import { RollFormat } from 'artigen/solver.d.ts'; +import { loggingEnabled } from 'artigen/rollUtils.ts'; +import { RollModifiers } from 'src/mod.d.ts'; // formatRoll(rollConf, modifiers) returns one SolvedStep // formatRoll handles creating and formatting the completed rolls into the SolvedStep format diff --git a/src/solver/rollUtils.ts b/src/artigen/rollUtils.ts similarity index 92% rename from src/solver/rollUtils.ts rename to src/artigen/rollUtils.ts index 02ed927..eab2cc0 100644 --- a/src/solver/rollUtils.ts +++ b/src/artigen/rollUtils.ts @@ -1,11 +1,7 @@ -import { - log, - // Log4Deno deps - LT, -} from '../../deps.ts'; -import { RollModifiers } from '../mod.d.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; +import { RollModifiers } from 'src/mod.d.ts'; -import { DPercentConf, ReturnData, RollSet } from './solver.d.ts'; +import { DPercentConf, ReturnData, RollSet } from 'artigen/solver.d.ts'; type MathFunction = (arg: number) => number; export const loggingEnabled = false; @@ -40,7 +36,7 @@ export const genFateRoll = (modifiers: RollModifiers): number => { return 0; } else { const sides = [-1, -1, 0, 0, 1, 1]; - return sides[genRoll(6, modifiers, { on: false }) - 1]; + return sides[genRoll(6, modifiers, { on: false }) - 1]; } }; diff --git a/src/solver/rollWorker.ts b/src/artigen/rollWorker.ts similarity index 77% rename from src/solver/rollWorker.ts rename to src/artigen/rollWorker.ts index 627df4c..100ebb8 100644 --- a/src/solver/rollWorker.ts +++ b/src/artigen/rollWorker.ts @@ -1,7 +1,7 @@ -import { closeLog, initLog } from '../../deps.ts'; -import { DEBUG } from '../../flags.ts'; -import { parseRoll } from './parser.ts'; -import { loggingEnabled } from './rollUtils.ts'; +import { closeLog, initLog } from '@Log4Deno'; +import { DEBUG } from '/flags.ts'; +import { parseRoll } from 'artigen/parser.ts'; +import { loggingEnabled } from 'artigen/rollUtils.ts'; loggingEnabled && initLog('logs/worker', DEBUG); diff --git a/src/solver/roller.ts b/src/artigen/roller.ts similarity index 98% rename from src/solver/roller.ts rename to src/artigen/roller.ts index fe0efc4..7a670dd 100644 --- a/src/solver/roller.ts +++ b/src/artigen/roller.ts @@ -1,13 +1,9 @@ -import config from '../../config.ts'; -import { - // Log4Deno deps - log, - LT, -} from '../../deps.ts'; +import config from '/config.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; -import { RollConf, RollSet, RollType } from './solver.d.ts'; -import { compareOrigIdx, compareRolls, genFateRoll, genRoll, loggingEnabled } from './rollUtils.ts'; -import { RollModifiers } from '../mod.d.ts'; +import { RollConf, RollSet, RollType } from 'artigen/solver.d.ts'; +import { compareOrigIdx, compareRolls, genFateRoll, genRoll, loggingEnabled } from 'artigen/rollUtils.ts'; +import { RollModifiers } from 'src/mod.d.ts'; // Call with loopCountCheck(++loopCount); // Will ensure if maxLoops is 10, 10 loops will be allowed, 11 will not. @@ -68,22 +64,22 @@ export const roll = (rollStr: string, modifiers: RollModifiers): RollSet[] => { reroll: { on: false, once: false, - nums: [], + nums: [], }, critScore: { on: false, - range: [], + range: [], }, critFail: { on: false, - range: [], + range: [], }, exploding: { on: false, once: false, compounding: false, penetrating: false, - nums: [], + nums: [], }, }; diff --git a/src/solver/solver.d.ts b/src/artigen/solver.d.ts similarity index 98% rename from src/solver/solver.d.ts rename to src/artigen/solver.d.ts index 77ad9c3..7e471b9 100644 --- a/src/solver/solver.d.ts +++ b/src/artigen/solver.d.ts @@ -1,5 +1,4 @@ -// solver.ts custom types - +// Available Roll Types export type RollType = '' | 'roll20' | 'fate' | 'cwod' | 'ova'; // RollSet is used to preserve all information about a calculated roll diff --git a/src/solver/solver.ts b/src/artigen/solver.ts similarity index 95% rename from src/solver/solver.ts rename to src/artigen/solver.ts index 954f5cc..553d071 100644 --- a/src/solver/solver.ts +++ b/src/artigen/solver.ts @@ -3,15 +3,10 @@ * * December 21, 2020 */ +import { log, LogTypes as LT } from '@Log4Deno'; -import { - log, - // Log4Deno deps - LT, -} from '../../deps.ts'; - -import { SolvedStep } from './solver.d.ts'; -import { legalMath, legalMathOperators, loggingEnabled } from './rollUtils.ts'; +import { SolvedStep } from 'artigen/solver.d.ts'; +import { legalMath, legalMathOperators, loggingEnabled } from 'artigen/rollUtils.ts'; // fullSolver(conf, wrapDetails) returns one condensed SolvedStep // fullSolver is a function that recursively solves the full roll and math @@ -191,10 +186,10 @@ export const fullSolver = (conf: (string | number | SolvedStep)[], wrapDetails: stepSolve.details = conf[0].toString(); } else { // Else fully populate the stepSolve with what was computed - stepSolve.total = ( conf[0]).total; - stepSolve.details = ( conf[0]).details; - stepSolve.containsCrit = ( conf[0]).containsCrit; - stepSolve.containsFail = ( conf[0]).containsFail; + stepSolve.total = (conf[0]).total; + stepSolve.details = (conf[0]).details; + stepSolve.containsCrit = (conf[0]).containsCrit; + stepSolve.containsFail = (conf[0]).containsFail; } // If this was a nested call, add on parens around the details to show what math we've done diff --git a/src/commandUtils.ts b/src/commandUtils.ts index 5376de9..373019d 100644 --- a/src/commandUtils.ts +++ b/src/commandUtils.ts @@ -1,8 +1,11 @@ -import config from '../config.ts'; -import { CountDetails, SolvedRoll } from './solver/solver.d.ts'; -import { RollModifiers } from './mod.d.ts'; -import { loggingEnabled } from './solver/rollUtils.ts'; -import { log, LT } from '../deps.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; + +import config from '/config.ts'; + +import { loggingEnabled } from 'artigen/rollUtils.ts'; +import { CountDetails, SolvedRoll } from 'artigen/solver.d.ts'; + +import { RollModifiers } from 'src/mod.d.ts'; export const failColor = 0xe71212; export const warnColor = 0xe38f28; @@ -46,7 +49,7 @@ export const generateStats = ( utilityCount: bigint, rollRate: number, utilityRate: number, - queryTimeMs: number, + queryTimeMs: number ) => ({ embeds: [ { diff --git a/src/commands/_index.ts b/src/commands/_index.ts index 4b4df96..3356728 100644 --- a/src/commands/_index.ts +++ b/src/commands/_index.ts @@ -1,21 +1,21 @@ -import { ping } from './ping.ts'; -import { rip } from './rip.ts'; -import { rollHelp } from './rollHelp.ts'; -import { rollDecorators } from './rollDecorators.ts'; -import { help } from './help.ts'; -import { info } from './info.ts'; -import { privacy } from './privacy.ts'; -import { version } from './version.ts'; -import { report } from './report.ts'; -import { stats } from './stats.ts'; -import { api } from './apiCmd.ts'; -import { emoji } from './emoji.ts'; -import { roll } from './roll.ts'; -import { handleMentions } from './handleMentions.ts'; -import { audit } from './audit.ts'; -import { heatmap } from './heatmap.ts'; -import { optOut } from './optOut.ts'; -import { optIn } from './optIn.ts'; +import { api } from 'commands/apiCmd.ts'; +import { audit } from 'commands/audit.ts'; +import { emoji } from 'commands/emoji.ts'; +import { handleMentions } from 'commands/handleMentions.ts'; +import { heatmap } from 'commands/heatmap.ts'; +import { help } from 'commands/help.ts'; +import { info } from 'commands/info.ts'; +import { optIn } from 'commands/optIn.ts'; +import { optOut } from 'commands/optOut.ts'; +import { ping } from 'commands/ping.ts'; +import { privacy } from 'commands/privacy.ts'; +import { rip } from 'commands/rip.ts'; +import { report } from 'commands/report.ts'; +import { roll } from 'commands/roll.ts'; +import { rollDecorators } from 'commands/rollDecorators.ts'; +import { rollHelp } from 'commands/rollHelp.ts'; +import { stats } from 'commands/stats.ts'; +import { version } from 'commands/version.ts'; export default { ping, diff --git a/src/commands/apiCmd.ts b/src/commands/apiCmd.ts index 4e7a449..2f853c8 100644 --- a/src/commands/apiCmd.ts +++ b/src/commands/apiCmd.ts @@ -1,14 +1,14 @@ -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - hasGuildPermissions, -} from '../../deps.ts'; -import apiCommands from './apiCmd/_index.ts'; -import { failColor } from '../commandUtils.ts'; -import utils from '../utils.ts'; -import config from '../../config.ts'; +import { DiscordenoMessage, hasGuildPermissions } from '@discordeno'; + +import config from '/config.ts'; + +import apiCommands from 'commands/apiCmd/_index.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { failColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const api = async (message: DiscordenoMessage, args: string[]) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/apiCmd/_index.ts b/src/commands/apiCmd/_index.ts index ea2d14e..ebec13c 100644 --- a/src/commands/apiCmd/_index.ts +++ b/src/commands/apiCmd/_index.ts @@ -1,8 +1,8 @@ -import { help } from './apiHelp.ts'; -import { allowBlock } from './allowBlock.ts'; -import { deleteGuild } from './deleteGuild.ts'; -import { status } from './status.ts'; -import { showHideWarn } from './showHideWarn.ts'; +import { allowBlock } from 'commands/apiCmd/allowBlock.ts'; +import { help } from 'commands/apiCmd/apiHelp.ts'; +import { deleteGuild } from 'commands/apiCmd/deleteGuild.ts'; +import { showHideWarn } from 'commands/apiCmd/showHideWarn.ts'; +import { status } from 'commands/apiCmd/status.ts'; export default { help, diff --git a/src/commands/apiCmd/allowBlock.ts b/src/commands/apiCmd/allowBlock.ts index 162d57e..c194bad 100644 --- a/src/commands/apiCmd/allowBlock.ts +++ b/src/commands/apiCmd/allowBlock.ts @@ -1,10 +1,9 @@ -import dbClient from '../../db/client.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../../deps.ts'; -import { generateApiFailed, generateApiSuccess } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import dbClient from 'db/client.ts'; + +import { generateApiFailed, generateApiSuccess } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const allowBlock = async (message: DiscordenoMessage, apiArg: string) => { let errorOutInitial = false; diff --git a/src/commands/apiCmd/apiHelp.ts b/src/commands/apiCmd/apiHelp.ts index 951a8b3..9ab811d 100644 --- a/src/commands/apiCmd/apiHelp.ts +++ b/src/commands/apiCmd/apiHelp.ts @@ -1,10 +1,9 @@ -import config from '../../../config.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../../deps.ts'; -import { infoColor1, infoColor2 } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import { infoColor1, infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const help = (message: DiscordenoMessage) => { message @@ -13,8 +12,7 @@ export const help = (message: DiscordenoMessage) => { { color: infoColor2, title: `${config.name}'s API Details:`, - description: - `${config.name} has a built in API that allows user to roll dice into Discord using third party programs. By default, API rolls are blocked from being sent in your guild. The API warning is also enabled by default. These commands may only be used by the Owner or Admins of your guild. + description: `${config.name} has a built in API that allows user to roll dice into Discord using third party programs. By default, API rolls are blocked from being sent in your guild. The API warning is also enabled by default. These commands may only be used by the Owner or Admins of your guild. For information on how to use the API, please check the GitHub README for more information [here](${config.links.sourceCode}). diff --git a/src/commands/apiCmd/deleteGuild.ts b/src/commands/apiCmd/deleteGuild.ts index 296b142..26f5e1d 100644 --- a/src/commands/apiCmd/deleteGuild.ts +++ b/src/commands/apiCmd/deleteGuild.ts @@ -1,11 +1,11 @@ -import dbClient from '../../db/client.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../../deps.ts'; -import { failColor, successColor } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; -import config from '../../../config.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import { failColor, successColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const deleteGuild = async (message: DiscordenoMessage) => { let errorOut = false; diff --git a/src/commands/apiCmd/showHideWarn.ts b/src/commands/apiCmd/showHideWarn.ts index 4ac2d76..59e3db9 100644 --- a/src/commands/apiCmd/showHideWarn.ts +++ b/src/commands/apiCmd/showHideWarn.ts @@ -1,10 +1,9 @@ -import dbClient from '../../db/client.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../../deps.ts'; -import { generateApiFailed, generateApiSuccess } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import dbClient from 'db/client.ts'; + +import { generateApiFailed, generateApiSuccess } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) => { let errorOutInitial = false; diff --git a/src/commands/apiCmd/status.ts b/src/commands/apiCmd/status.ts index 70147a1..ff09a3e 100644 --- a/src/commands/apiCmd/status.ts +++ b/src/commands/apiCmd/status.ts @@ -1,10 +1,9 @@ -import dbClient from '../../db/client.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../../deps.ts'; -import { failColor, generateApiStatus } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import dbClient from 'db/client.ts'; + +import { failColor, generateApiStatus } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const status = async (message: DiscordenoMessage) => { // Get status of guild from the db diff --git a/src/commands/audit.ts b/src/commands/audit.ts index 20d2ca5..d1d20f7 100644 --- a/src/commands/audit.ts +++ b/src/commands/audit.ts @@ -1,13 +1,14 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import auditCommands from './auditCmd/_index.ts'; -import { failColor } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import auditCommands from 'commands/auditCmd/_index.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { failColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const audit = (message: DiscordenoMessage, args: string[]) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/auditCmd/_index.ts b/src/commands/auditCmd/_index.ts index 42291da..7b23c1f 100644 --- a/src/commands/auditCmd/_index.ts +++ b/src/commands/auditCmd/_index.ts @@ -1,6 +1,6 @@ -import { auditHelp } from './auditHelp.ts'; -import { auditDB } from './auditDB.ts'; -import { auditGuilds } from './auditGuilds.ts'; +import { auditDB } from 'commands/auditCmd/auditDB.ts'; +import { auditGuilds } from 'commands/auditCmd/auditGuilds.ts'; +import { auditHelp } from 'commands/auditCmd/auditHelp.ts'; export default { auditHelp, diff --git a/src/commands/auditCmd/auditDB.ts b/src/commands/auditCmd/auditDB.ts index 1ef59f2..904aef6 100644 --- a/src/commands/auditCmd/auditDB.ts +++ b/src/commands/auditCmd/auditDB.ts @@ -1,12 +1,10 @@ -import dbClient from '../../db/client.ts'; -import { - // Discordeno deps - DiscordenoMessage, - EmbedField, -} from '../../../deps.ts'; -import { infoColor2 } from '../../commandUtils.ts'; -import { compilingStats } from '../../commonEmbeds.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage, EmbedField } from '@discordeno'; + +import dbClient from 'db/client.ts'; + +import { compilingStats } from 'src/commonEmbeds.ts'; +import { infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; interface DBSizeData { table: string; diff --git a/src/commands/auditCmd/auditGuilds.ts b/src/commands/auditCmd/auditGuilds.ts index 068cfc1..563febd 100644 --- a/src/commands/auditCmd/auditGuilds.ts +++ b/src/commands/auditCmd/auditGuilds.ts @@ -1,13 +1,9 @@ -import config from '../../../config.ts'; -import { - // Discordeno deps - cache, - cacheHandlers, - DiscordenoGuild, - DiscordenoMessage, -} from '../../../deps.ts'; -import { infoColor2 } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; +import { cache, cacheHandlers, DiscordenoGuild, DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import { infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; const sortGuildByMemberCount = (a: DiscordenoGuild, b: DiscordenoGuild) => { if (a.memberCount < b.memberCount) { @@ -123,21 +119,25 @@ Please see attached file for audit details on cached guilds and members.`, }, { name: 'Repeat Guild Owners:', - value: repeatCounts - .map((ownerCnt, serverIdx) => `${ownerCnt} ${ownerCnt === 1 ? 'person has' : 'people have'} me in ${serverIdx + 1} of their guilds`) - .filter((str) => str) - .join('\n') || 'No Repeat Guild Owners', + value: + repeatCounts + .map((ownerCnt, serverIdx) => `${ownerCnt} ${ownerCnt === 1 ? 'person has' : 'people have'} me in ${serverIdx + 1} of their guilds`) + .filter((str) => str) + .join('\n') || 'No Repeat Guild Owners', }, { name: 'Guild Size Dist:', - value: Array.from(guildSizeDist) - .map( - ([size, count], idx) => - `${count} Guild${count === 1 ? ' has' : 's have'} ${ - guildSizeDist.has(sizeCats[idx - 1]) ? `${size.toLocaleString()} - ${(sizeCats[idx - 1] - 1).toLocaleString()}` : `at least ${size.toLocaleString()}` - } Member${size === 1 ? '' : 's'}`, - ) - .join('\n') || 'Not available', + value: + Array.from(guildSizeDist) + .map( + ([size, count], idx) => + `${count} Guild${count === 1 ? ' has' : 's have'} ${ + guildSizeDist.has(sizeCats[idx - 1]) + ? `${size.toLocaleString()} - ${(sizeCats[idx - 1] - 1).toLocaleString()}` + : `at least ${size.toLocaleString()}` + } Member${size === 1 ? '' : 's'}` + ) + .join('\n') || 'Not available', }, ], }, diff --git a/src/commands/auditCmd/auditHelp.ts b/src/commands/auditCmd/auditHelp.ts index 5a6378f..9c90971 100644 --- a/src/commands/auditCmd/auditHelp.ts +++ b/src/commands/auditCmd/auditHelp.ts @@ -1,10 +1,9 @@ -import config from '../../../config.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../../deps.ts'; -import { infoColor1 } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import { infoColor1 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const auditHelp = (message: DiscordenoMessage) => { message diff --git a/src/commands/emoji.ts b/src/commands/emoji.ts index 5ac4599..a8a100a 100644 --- a/src/commands/emoji.ts +++ b/src/commands/emoji.ts @@ -1,15 +1,13 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - // Log4Deno deps - log, - LT, -} from '../../deps.ts'; -import { EmojiConf } from '../mod.d.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; +import { log, LogTypes as LT } from '@Log4Deno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { EmojiConf } from 'src/mod.d.ts'; +import utils from 'src/utils.ts'; const allEmojiAliases: string[] = []; diff --git a/src/commands/handleMentions.ts b/src/commands/handleMentions.ts index 7ef3c38..3261b35 100644 --- a/src/commands/handleMentions.ts +++ b/src/commands/handleMentions.ts @@ -1,15 +1,13 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - // Log4Deno deps - log, - LT, -} from '../../deps.ts'; -import { infoColor1 } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; +import { log, LogTypes as LT } from '@Log4Deno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor1 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const handleMentions = (message: DiscordenoMessage) => { log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`); diff --git a/src/commands/heatmap.ts b/src/commands/heatmap.ts index cf321b9..f9ec08e 100644 --- a/src/commands/heatmap.ts +++ b/src/commands/heatmap.ts @@ -1,13 +1,13 @@ -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import config from '../../config.ts'; -import { failColor, infoColor2 } from '../commandUtils.ts'; -import utils from '../utils.ts'; -import intervals from '../intervals.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { failColor, infoColor2 } from 'src/commandUtils.ts'; +import intervals from 'src/intervals.ts'; +import utils from 'src/utils.ts'; export const heatmap = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/help.ts b/src/commands/help.ts index cacec53..9fe88da 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor2 } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const help = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run @@ -91,8 +91,7 @@ export const help = (message: DiscordenoMessage) => { }, { 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 \`${config.postfix}\`), run \`${config.prefix}??\` 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, }, ], diff --git a/src/commands/info.ts b/src/commands/info.ts index 81c3531..73cb409 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor2 } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const info = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/optIn.ts b/src/commands/optIn.ts index 5a897e4..39f96c0 100644 --- a/src/commands/optIn.ts +++ b/src/commands/optIn.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { ignoreList, queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { failColor, successColor } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { ignoreList, queries } from 'db/common.ts'; + +import { failColor, successColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const optIn = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/optOut.ts b/src/commands/optOut.ts index 6701502..9799ebf 100644 --- a/src/commands/optOut.ts +++ b/src/commands/optOut.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { ignoreList, queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { failColor, successColor } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { ignoreList, queries } from 'db/common.ts'; + +import { failColor, successColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const optOut = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 13a9179..7678972 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,11 +1,10 @@ -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { generatePing } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { generatePing } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const ping = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/privacy.ts b/src/commands/privacy.ts index e750fea..98c7318 100644 --- a/src/commands/privacy.ts +++ b/src/commands/privacy.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor1 } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor1 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const privacy = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run @@ -21,8 +21,7 @@ export const privacy = (message: DiscordenoMessage) => { fields: [ { name: `${config.name} does not track or collect user information via Discord.`, - 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 ${config.name} 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 ${config.name} can see. For more details, please check out the Privacy Policy on the GitHub [here](${config.links.privacyPolicy}). diff --git a/src/commands/report.ts b/src/commands/report.ts index 3542547..0a0c4f0 100644 --- a/src/commands/report.ts +++ b/src/commands/report.ts @@ -1,14 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - // Discordeno deps - sendMessage, -} from '../../deps.ts'; -import { failColor, generateReport, successColor } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage, sendMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { failColor, generateReport, successColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const report = (message: DiscordenoMessage, args: string[]) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/rip.ts b/src/commands/rip.ts index bf626c1..aef683d 100644 --- a/src/commands/rip.ts +++ b/src/commands/rip.ts @@ -1,12 +1,12 @@ -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor2 } from '../commandUtils.ts'; -import utils from '../utils.ts'; -import config from '../../config.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const rip = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/roll.ts b/src/commands/roll.ts index 1476b49..1290887 100644 --- a/src/commands/roll.ts +++ b/src/commands/roll.ts @@ -1,18 +1,18 @@ -import config from '../../config.ts'; -import { DEVMODE } from '../../flags.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - // Log4Deno deps - log, - LT, -} from '../../deps.ts'; -import { rollingEmbed, warnColor } from '../commandUtils.ts'; -import rollFuncs from './roll/_index.ts'; -import { queueRoll } from '../solver/rollQueue.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; +import { log, LogTypes as LT } from '@Log4Deno'; + +import config from '/config.ts'; +import { DEVMODE } from '/flags.ts'; + +import { queueRoll } from 'artigen/managers/queueManager.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import rollFuncs from 'commands/roll/_index.ts'; + +import { rollingEmbed, warnColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const roll = async (message: DiscordenoMessage, args: string[], command: string) => { // Light telemetry to see how many times a command is being run diff --git a/src/commands/roll/_index.ts b/src/commands/roll/_index.ts index ae504a3..77bf87e 100644 --- a/src/commands/roll/_index.ts +++ b/src/commands/roll/_index.ts @@ -1,4 +1,4 @@ -import { getModifiers } from './getModifiers.ts'; +import { getModifiers } from 'commands/roll/getModifiers.ts'; export default { getModifiers, diff --git a/src/commands/roll/getModifiers.ts b/src/commands/roll/getModifiers.ts index 9d1e6d6..425c1cb 100644 --- a/src/commands/roll/getModifiers.ts +++ b/src/commands/roll/getModifiers.ts @@ -1,17 +1,15 @@ -import config from '../../../config.ts'; -import { DEVMODE } from '../../../flags.ts'; -import dbClient from '../../db/client.ts'; -import { queries } from '../../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, - // Log4Deno deps - log, - LT, -} from '../../../deps.ts'; -import { generateRollError } from '../../commandUtils.ts'; -import { RollModifiers } from '../../mod.d.ts'; -import utils from '../../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; +import { log, LogTypes as LT } from '@Log4Deno'; + +import config from '/config.ts'; +import { DEVMODE } from '/flags.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { generateRollError } from 'src/commandUtils.ts'; +import { RollModifiers } from 'src/mod.d.ts'; +import utils from 'src/utils.ts'; export const getModifiers = (m: DiscordenoMessage, args: string[], command: string, originalCommand: string): RollModifiers => { const errorType = 'Modifiers invalid:'; @@ -70,7 +68,9 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri } if (modifiers.gms.length < 1) { // If -gm is on and none were found, throw an error - m.edit(generateRollError(errorType, 'Must specify at least one GM by @mentioning them')).catch((e) => utils.commonLoggers.messageEditError('getModifiers.ts:66', m, e)); + m.edit(generateRollError(errorType, 'Must specify at least one GM by @mentioning them')).catch((e) => + utils.commonLoggers.messageEditError('getModifiers.ts:66', m, e) + ); if (DEVMODE && config.logRolls) { // If enabled, log rolls so we can verify the bots math @@ -87,7 +87,9 @@ export const getModifiers = (m: DiscordenoMessage, args: string[], command: stri if (!args[i] || (args[i].toLowerCase()[0] !== 'd' && args[i].toLowerCase()[0] !== 'a')) { // If -o is on and asc or desc was not specified, error out - m.edit(generateRollError(errorType, 'Must specify `a` or `d` to order the rolls ascending or descending')).catch((e) => utils.commonLoggers.messageEditError('getModifiers.ts:81', m, e)); + m.edit(generateRollError(errorType, 'Must specify `a` or `d` to order the rolls ascending or descending')).catch((e) => + utils.commonLoggers.messageEditError('getModifiers.ts:81', m, e) + ); if (DEVMODE && config.logRolls) { // If enabled, log rolls so we can verify the bots math diff --git a/src/commands/rollDecorators.ts b/src/commands/rollDecorators.ts index 6dc9ff9..f95b463 100644 --- a/src/commands/rollDecorators.ts +++ b/src/commands/rollDecorators.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor2 } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor2 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const rollDecorators = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run @@ -54,7 +54,8 @@ Examples: \`${config.prefix}d20${config.postfix} -nd\`, \`${config.prefix}d20${c }, { name: '`-gm @user1 @user2 @userN` - GM Roll', - value: 'Rolls the requested roll in GM mode, suppressing all publicly shown results and details and sending the results directly to the specified GMs', + value: + '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, }, { diff --git a/src/commands/rollHelp.ts b/src/commands/rollHelp.ts index 650f514..22358c6 100644 --- a/src/commands/rollHelp.ts +++ b/src/commands/rollHelp.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor1, infoColor2, successColor } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor1, infoColor2, successColor } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const rollHelp = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run @@ -72,27 +72,32 @@ Additionally, replace \`x\` with \`F\` to roll Fate dice`, }, { name: '`rq` [Optional]', - value: 'Rerolls any rolls that are greater than or equal to `a`, `r3` will reroll every die that land on 3 or greater, throwing out old rolls, cannot be used with `ro`', + value: + 'Rerolls any rolls that are greater than or equal to `a`, `r3` will reroll every die that land on 3 or greater, throwing out old rolls, cannot be used with `ro`', inline: true, }, { name: '`roa` or `ro=q` [Optional]', - value: 'Rerolls any rolls that match `a`, `ro3` will reroll each die that lands on 3 ONLY ONE TIME, throwing out old rolls, cannot be used with `r`', + value: + 'Rerolls any rolls that match `a`, `ro3` will reroll each die that lands on 3 ONLY ONE TIME, throwing out old rolls, cannot be used with `r`', inline: true, }, { name: '`roq` [Optional]', - value: 'Rerolls any rolls that are greater than or equal to `a`, `ro3` will reroll each die that lands on 3 or greater ONLY ONE TIME, throwing out old rolls, cannot be used with `r`', + value: + 'Rerolls any rolls that are greater than or equal to `a`, `ro3` will reroll each die that lands on 3 or greater ONLY ONE TIME, throwing out old rolls, cannot be used with `r`', inline: true, }, { @@ -187,27 +192,32 @@ Additionally, replace \`x\` with \`F\` to roll Fate dice`, }, { name: '`!p>u` [Optional]', - value: 'Penetrating Explosion on `u` and greater, rolls one `dy` for each die that lands on `u` or greater, but subtracts one from each resulting explosion', + value: + 'Penetrating Explosion on `u` and greater, rolls one `dy` for each die that lands on `u` or greater, but subtracts one from each resulting explosion', inline: true, }, { name: '`!pu` [Optional]', - value: 'Compounding Explosion on `u` and greater, rolls one `dy` for each die that lands on `u` or greater, but adds the resulting explosion to the die that caused this explosion', + value: + 'Compounding Explosion on `u` and greater, rolls one `dy` for each die that lands on `u` or greater, but adds the resulting explosion to the die that caused this explosion', inline: true, }, { name: '`!! { // Light telemetry to see how many times a command is being run @@ -45,8 +42,8 @@ export const stats = async (message: DiscordenoMessage) => { total - rolls, rollRate, totalRate - rollRate, - endTime - startTime, - ), + endTime - startTime + ) ).catch((e: Error) => utils.commonLoggers.messageEditError('stats.ts:38', m, e)); } catch (e) { utils.commonLoggers.messageSendError('stats.ts:41', message, e as Error); diff --git a/src/commands/version.ts b/src/commands/version.ts index 74289ab..ff41bd7 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -1,12 +1,12 @@ -import config from '../../config.ts'; -import dbClient from '../db/client.ts'; -import { queries } from '../db/common.ts'; -import { - // Discordeno deps - DiscordenoMessage, -} from '../../deps.ts'; -import { infoColor1 } from '../commandUtils.ts'; -import utils from '../utils.ts'; +import { DiscordenoMessage } from '@discordeno'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import { infoColor1 } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const version = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run diff --git a/src/commonEmbeds.ts b/src/commonEmbeds.ts index aa00998..9ec5f0b 100644 --- a/src/commonEmbeds.ts +++ b/src/commonEmbeds.ts @@ -1,4 +1,4 @@ -import { warnColor } from './commandUtils.ts'; +import { warnColor } from 'src/commandUtils.ts'; export const compilingStats = { embeds: [ diff --git a/src/db/client.ts b/src/db/client.ts index d7c782c..43afbef 100644 --- a/src/db/client.ts +++ b/src/db/client.ts @@ -1,6 +1,7 @@ -import config from '../../config.ts'; -import { Client } from '../../deps.ts'; -import { LOCALMODE } from '../../flags.ts'; +import { Client } from '@mysql'; + +import config from '/config.ts'; +import { LOCALMODE } from '/flags.ts'; const dbClient = await new Client().connect({ hostname: LOCALMODE ? config.db.localhost : config.db.host, diff --git a/src/db/common.ts b/src/db/common.ts index d47ba02..056f884 100644 --- a/src/db/common.ts +++ b/src/db/common.ts @@ -1,4 +1,4 @@ -import dbClient from './client.ts'; +import dbClient from 'db/client.ts'; type UserIdObj = { userid: bigint; diff --git a/src/endpoints/_index.ts b/src/endpoints/_index.ts index 3407cd3..5a42630 100644 --- a/src/endpoints/_index.ts +++ b/src/endpoints/_index.ts @@ -1,13 +1,16 @@ -import { apiKeyDelete } from './deletes/apiKeyDelete.ts'; -import { apiKey } from './gets/apiKey.ts'; -import { apiRoll } from './gets/apiRoll.ts'; -import { apiKeyAdmin } from './gets/apiKeyAdmin.ts'; -import { apiChannel } from './gets/apiChannel.ts'; -import { heatmapPng } from './gets/heatmapPng.ts'; -import { apiChannelAdd } from './posts/apiChannelAdd.ts'; -import { apiKeyManage } from './puts/apiKeyManage.ts'; -import { apiChannelManageBan } from './puts/apiChannelManageBan.ts'; -import { apiChannelManageActive } from './puts/apiChannelManageActive.ts'; +import { apiKeyDelete } from 'endpoints/deletes/apiKeyDelete.ts'; + +import { apiChannel } from 'endpoints/gets/apiChannel.ts'; +import { apiKey } from 'endpoints/gets/apiKey.ts'; +import { apiKeyAdmin } from 'endpoints/gets/apiKeyAdmin.ts'; +import { apiRoll } from 'endpoints/gets/apiRoll.ts'; +import { heatmapPng } from 'endpoints/gets/heatmapPng.ts'; + +import { apiChannelAdd } from 'endpoints/posts/apiChannelAdd.ts'; + +import { apiChannelManageActive } from 'endpoints/puts/apiChannelManageActive.ts'; +import { apiChannelManageBan } from 'endpoints/puts/apiChannelManageBan.ts'; +import { apiKeyManage } from 'endpoints/puts/apiKeyManage.ts'; export default { delete: { diff --git a/src/endpoints/deletes/apiKeyDelete.ts b/src/endpoints/deletes/apiKeyDelete.ts index e292fa3..02ed0e6 100644 --- a/src/endpoints/deletes/apiKeyDelete.ts +++ b/src/endpoints/deletes/apiKeyDelete.ts @@ -1,15 +1,15 @@ -import config from '../../../config.ts'; -import dbClient from '../../db/client.ts'; -import { - // nanoid deps - nanoid, - // Discordeno deps - sendMessage, -} from '../../../deps.ts'; -import { generateApiDeleteEmail } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; -import stdResp from '../stdResponses.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import { sendMessage } from '@discordeno'; +import { nanoid } from '@nanoid'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import { generateApiDeleteEmail } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const apiKeyDelete = async (query: Map, apiUserid: bigint, apiUserEmail: string, apiUserDelCode: string): Promise => { if (verifyQueryHasParams(query, ['user', 'email'])) { diff --git a/src/endpoints/gets/apiChannel.ts b/src/endpoints/gets/apiChannel.ts index 2dc66fb..746a542 100644 --- a/src/endpoints/gets/apiChannel.ts +++ b/src/endpoints/gets/apiChannel.ts @@ -1,7 +1,9 @@ -import dbClient from '../../db/client.ts'; -import stdResp from '../stdResponses.ts'; -import utils from '../../utils.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import utils from 'src/utils.ts'; export const apiChannel = async (query: Map, apiUserid: bigint): Promise => { if (verifyQueryHasParams(query, ['user'])) { diff --git a/src/endpoints/gets/apiKey.ts b/src/endpoints/gets/apiKey.ts index 540b5e6..73e33d7 100644 --- a/src/endpoints/gets/apiKey.ts +++ b/src/endpoints/gets/apiKey.ts @@ -1,15 +1,15 @@ -import config from '../../../config.ts'; -import dbClient from '../../db/client.ts'; -import { - // nanoid deps - nanoid, - // Discordeno deps - sendMessage, -} from '../../../deps.ts'; -import { generateApiKeyEmail } from '../../commandUtils.ts'; -import utils from '../../utils.ts'; -import stdResp from '../stdResponses.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import { sendMessage } from '@discordeno'; +import { nanoid } from '@nanoid'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import { generateApiKeyEmail } from 'src/commandUtils.ts'; +import utils from 'src/utils.ts'; export const apiKey = async (query: Map): Promise => { if (verifyQueryHasParams(query, ['user', 'email'])) { diff --git a/src/endpoints/gets/apiKeyAdmin.ts b/src/endpoints/gets/apiKeyAdmin.ts index b4be949..708c261 100644 --- a/src/endpoints/gets/apiKeyAdmin.ts +++ b/src/endpoints/gets/apiKeyAdmin.ts @@ -1,12 +1,13 @@ -import config from '../../../config.ts'; -import dbClient from '../../db/client.ts'; -import { - // nanoid deps - nanoid, -} from '../../../deps.ts'; -import stdResp from '../stdResponses.ts'; -import utils from '../../utils.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import { nanoid } from '@nanoid'; + +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import utils from 'src/utils.ts'; export const apiKeyAdmin = async (query: Map, apiUserid: bigint): Promise => { if (verifyQueryHasParams(query, ['user', 'a'])) { diff --git a/src/endpoints/gets/apiRoll.ts b/src/endpoints/gets/apiRoll.ts index 707ff47..eba0b48 100644 --- a/src/endpoints/gets/apiRoll.ts +++ b/src/endpoints/gets/apiRoll.ts @@ -1,18 +1,18 @@ -import config from '../../../config.ts'; -import dbClient from '../../db/client.ts'; -import { queries } from '../../db/common.ts'; -import { - // Discordeno deps - cache, - // Log4Deno deps - log, - LT, -} from '../../../deps.ts'; -import { RollModifiers } from '../../mod.d.ts'; -import utils from '../../utils.ts'; -import { queueRoll } from '../../solver/rollQueue.ts'; -import stdResp from '../stdResponses.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import { cache } from '@discordeno'; +import { log, LogTypes as LT } from '@Log4Deno'; + +import config from '/config.ts'; + +import { queueRoll } from 'artigen/managers/queueManager.ts'; + +import dbClient from 'db/client.ts'; +import { queries } from 'db/common.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import { RollModifiers } from 'src/mod.d.ts'; +import utils from 'src/utils.ts'; const apiWarning = `The following roll was conducted using my built in API. If someone in this channel did not request this roll, please report API abuse here: <${config.api.supportURL}>`; @@ -115,7 +115,7 @@ export const apiRoll = async (query: Map, apiUserid: bigint): Pr } else { // Alert API user that they messed up return stdResp.Forbidden( - `Verify you are a member of the guild you are sending this roll to. If you are, the ${config.name} may not have that registered, please send a message in the guild so ${config.name} can register this. This registration is temporary, so if you see this error again, just poke your server again.`, + `Verify you are a member of the guild you are sending this roll to. If you are, the ${config.name} may not have that registered, please send a message in the guild so ${config.name} can register this. This registration is temporary, so if you see this error again, just poke your server again.` ); } } else { diff --git a/src/endpoints/gets/heatmapPng.ts b/src/endpoints/gets/heatmapPng.ts index 8c7a53c..cae81c7 100644 --- a/src/endpoints/gets/heatmapPng.ts +++ b/src/endpoints/gets/heatmapPng.ts @@ -1,8 +1,4 @@ -import { - // httpd deps - STATUS_CODE, - STATUS_TEXT, -} from '../../../deps.ts'; +import { STATUS_CODE, STATUS_TEXT } from '@std/http'; export const heatmapPng = (): Response => { const file = Deno.readFileSync('./src/endpoints/gets/heatmap.png'); diff --git a/src/endpoints/posts/apiChannelAdd.ts b/src/endpoints/posts/apiChannelAdd.ts index 67aa6af..efef186 100644 --- a/src/endpoints/posts/apiChannelAdd.ts +++ b/src/endpoints/posts/apiChannelAdd.ts @@ -1,7 +1,9 @@ -import dbClient from '../../db/client.ts'; -import stdResp from '../stdResponses.ts'; -import utils from '../../utils.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import utils from 'src/utils.ts'; export const apiChannelAdd = async (query: Map, apiUserid: bigint): Promise => { if (verifyQueryHasParams(query, ['user', 'channel'])) { diff --git a/src/endpoints/puts/apiChannelManageActive.ts b/src/endpoints/puts/apiChannelManageActive.ts index 140bee9..6d347d5 100644 --- a/src/endpoints/puts/apiChannelManageActive.ts +++ b/src/endpoints/puts/apiChannelManageActive.ts @@ -1,7 +1,9 @@ -import dbClient from '../../db/client.ts'; -import stdResp from '../stdResponses.ts'; -import utils from '../../utils.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import utils from 'src/utils.ts'; export const apiChannelManageActive = async (query: Map, apiUserid: bigint, path: string): Promise => { if (verifyQueryHasParams(query, ['user', 'channel'])) { diff --git a/src/endpoints/puts/apiChannelManageBan.ts b/src/endpoints/puts/apiChannelManageBan.ts index 0878734..79e10c6 100644 --- a/src/endpoints/puts/apiChannelManageBan.ts +++ b/src/endpoints/puts/apiChannelManageBan.ts @@ -1,8 +1,11 @@ -import config from '../../../config.ts'; -import dbClient from '../../db/client.ts'; -import stdResp from '../stdResponses.ts'; -import utils from '../../utils.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import utils from 'src/utils.ts'; export const apiChannelManageBan = async (query: Map, apiUserid: bigint, path: string): Promise => { if (verifyQueryHasParams(query, ['user', 'channel', 'a'])) { diff --git a/src/endpoints/puts/apiKeyManage.ts b/src/endpoints/puts/apiKeyManage.ts index 0a4d49a..38942e4 100644 --- a/src/endpoints/puts/apiKeyManage.ts +++ b/src/endpoints/puts/apiKeyManage.ts @@ -1,8 +1,11 @@ -import config from '../../../config.ts'; -import dbClient from '../../db/client.ts'; -import stdResp from '../stdResponses.ts'; -import utils from '../../utils.ts'; -import { verifyQueryHasParams } from '../utils.ts'; +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; + +import stdResp from 'endpoints/stdResponses.ts'; +import { verifyQueryHasParams } from 'endpoints/utils.ts'; + +import utils from 'src/utils.ts'; export const apiKeyManage = async (query: Map, apiUserid: bigint, path: string): Promise => { if (verifyQueryHasParams(query, ['user', 'a'])) { diff --git a/src/endpoints/stdResponses.ts b/src/endpoints/stdResponses.ts index aa42a2f..fefd602 100644 --- a/src/endpoints/stdResponses.ts +++ b/src/endpoints/stdResponses.ts @@ -1,11 +1,7 @@ -import { - STATUS_CODE, - STATUS_TEXT, - // httpd deps - StatusCode, -} from '../../deps.ts'; +import { STATUS_CODE, STATUS_TEXT, StatusCode } from '@std/http'; -const genericResponse = (customText: string, status: StatusCode) => new Response(customText || STATUS_TEXT[status], { status: status, statusText: STATUS_TEXT[status] }); +const genericResponse = (customText: string, status: StatusCode) => + new Response(customText || STATUS_TEXT[status], { status: status, statusText: STATUS_TEXT[status] }); export default { BadRequest: (customText: string) => genericResponse(customText, STATUS_CODE.BadRequest), diff --git a/src/intervals.ts b/src/intervals.ts index 754a4f7..671b827 100644 --- a/src/intervals.ts +++ b/src/intervals.ts @@ -3,22 +3,17 @@ * * December 21, 2020 */ +import { cache, cacheHandlers } from '@discordeno'; +import { Image, decode } from '@imagescript'; +import { log, LogTypes as LT } from '@Log4Deno'; -import { - // Discordeno deps - cache, - cacheHandlers, - // imagescript dep - is, - // Log4Deno deps - log, - LT, -} from '../deps.ts'; -import { PastCommandCount } from './mod.d.ts'; -import dbClient from './db/client.ts'; -import { weekDays } from './db/common.ts'; -import utils from './utils.ts'; -import config from '../config.ts'; +import config from '/config.ts'; + +import dbClient from 'db/client.ts'; +import { weekDays } from 'db/common.ts'; + +import { PastCommandCount } from 'src/mod.d.ts'; +import utils from 'src/utils.ts'; // getRandomStatus() returns status as string // Gets a new random status for the bot @@ -163,8 +158,8 @@ let minRollCnt: number; let maxRollCnt: number; const updateHeatmapPng = async () => { const baseHeatmap = Deno.readFileSync('./src/endpoints/gets/heatmap-base.png'); - const heatmap = await is.decode(baseHeatmap); - if (!(heatmap instanceof is.Image)) { + const heatmap = await decode(baseHeatmap); + if (!(heatmap instanceof Image)) { return; } // Get latest data from DB @@ -198,7 +193,7 @@ const updateHeatmapPng = async () => { hourPixels[hour][0] + 1, dayPixels[day][1] - dayPixels[day][0] + 1, hourPixels[hour][1] - hourPixels[hour][0] + 1, - is.Image.rgbToColor(255 * (1 - percent), 255 * percent, 0), + Image.rgbToColor(255 * (1 - percent), 255 * percent, 0) ); } } diff --git a/src/mod.d.ts b/src/mod.d.ts index 2ea4800..2e281c0 100644 --- a/src/mod.d.ts +++ b/src/mod.d.ts @@ -1,5 +1,4 @@ -// mod.d.ts custom types -import { DiscordenoMessage } from '../deps.ts'; +import { DiscordenoMessage } from '@discordeno'; // EmojiConf is used as a structure for the emojis stored in config.ts export type EmojiConf = { @@ -28,12 +27,12 @@ export type RollModifiers = { }; // QueuedRoll is the structure to track rolls we could not immediately handle -interface QueuedRoll { +interface BaseQueuedRoll { rollCmd: string; modifiers: RollModifiers; originalCommand: string; } -export interface ApiQueuedRoll extends QueuedRoll { +export interface ApiQueuedRoll extends BaseQueuedRoll { apiRoll: true; api: { resolve: (value: Response | PromiseLike) => void; @@ -41,13 +40,14 @@ export interface ApiQueuedRoll extends QueuedRoll { userId: bigint; }; } -export interface DDQueuedRoll extends QueuedRoll { +export interface DDQueuedRoll extends BaseQueuedRoll { apiRoll: false; dd: { m: DiscordenoMessage; message: DiscordenoMessage; }; } +export type QueuedRoll = ApiQueuedRoll | DDQueuedRoll; export type PastCommandCount = { command: string; diff --git a/src/solver/_index.ts b/src/solver/_index.ts deleted file mode 100644 index 70ddfed..0000000 --- a/src/solver/_index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { parseRoll } from './parser.ts'; - -export default { - parseRoll, -}; diff --git a/src/utils.ts b/src/utils.ts index 48dfba0..8aa8dc4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,16 +3,8 @@ * * December 21, 2020 */ - -import { - // Discordeno deps - DiscordenoMessage, - // Log4Deno deps - log, - LT, - // Discordeno deps - sendMessage, -} from '../deps.ts'; +import { log, LogTypes as LT } from '@Log4Deno'; +import { DiscordenoMessage, sendMessage } from '@discordeno'; // ask(prompt) returns string // ask prompts the user at command line for message @@ -23,7 +15,7 @@ const ask = async (question: string, stdin = Deno.stdin, stdout = Deno.stdout): await stdout.write(new TextEncoder().encode(question)); // Read console's input into answer - const n = await stdin.read(buf); + const n = await stdin.read(buf); const answer = new TextDecoder().decode(buf.subarray(0, n)); return answer.trim(); @@ -101,7 +93,8 @@ const messageSendError = (location: string, message: DiscordenoMessage | string, genericLogger(LT.ERROR, `${location} | Failed to send message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message}`); const messageDeleteError = (location: string, message: DiscordenoMessage | string, err: Error) => genericLogger(LT.ERROR, `${location} | Failed to delete message: ${JSON.stringify(message)} | Error: ${err.name} - ${err.message}`); -const dbError = (location: string, type: string, err: Error) => genericLogger(LT.ERROR, `${location} | Failed to ${type} database | Error: ${err.name} - ${err.message}`); +const dbError = (location: string, type: string, err: Error) => + genericLogger(LT.ERROR, `${location} | Failed to ${type} database | Error: ${err.name} - ${err.message}`); export default { commonLoggers: { diff --git a/start.command b/start.command index 7bd7399..d5f9fdb 100644 --- a/start.command +++ b/start.command @@ -1 +1 @@ -deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/solver/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./flags.ts,./src/mod.d.ts --allow-net --allow-import mod.ts +deno run --allow-write=./logs/,./src/endpoints/gets/heatmap.png --allow-read=./src/artigen/,./src/endpoints/gets/heatmap-base.png,./src/endpoints/gets/heatmap.png,./config.ts,./deps.ts,./flags.ts,./src/mod.d.ts --allow-net --allow-import mod.ts