From f2797e6c33115121366563ddf5f0f46a2680a648 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Sat, 3 May 2025 20:47:58 -0400 Subject: [PATCH] update common embed location, move some back into their own files --- deno.json | 1 + mod.ts | 3 +- .../managers/handler/workerComplete.ts | 3 +- .../managers/handler/workerTerminate.ts | 3 +- src/artigen/managers/queueManager.ts | 4 +- src/commands/apiCmd.ts | 3 +- src/commands/apiCmd/allowBlock.ts | 3 +- src/commands/apiCmd/apiHelp.ts | 3 +- src/commands/apiCmd/deleteGuild.ts | 3 +- src/commands/apiCmd/showHideWarn.ts | 3 +- src/commands/apiCmd/status.ts | 4 +- src/commands/audit.ts | 3 +- src/commands/auditCmd/auditDB.ts | 5 +- src/commands/auditCmd/auditGuilds.ts | 3 +- src/commands/auditCmd/auditHelp.ts | 3 +- src/commands/handleMentions.ts | 3 +- src/commands/heatmap.ts | 3 +- src/commands/help.ts | 3 +- src/commands/info.ts | 3 +- src/commands/optIn.ts | 3 +- src/commands/optOut.ts | 3 +- src/commands/ping.ts | 12 +- src/commands/privacy.ts | 3 +- src/commands/report.ts | 12 +- src/commands/rip.ts | 3 +- src/commands/roll.ts | 4 +- src/commands/rollDecorators.ts | 3 +- src/commands/rollHelp.ts | 3 +- src/commands/stats.ts | 58 ++++-- src/commands/version.ts | 3 +- src/embeds/api.ts | 96 ++++++++++ src/{commandUtils.ts => embeds/artigen.ts} | 169 +----------------- src/embeds/colors.ts | 5 + src/{commonEmbeds.ts => embeds/common.ts} | 2 +- src/endpoints/deletes/apiKeyDelete.ts | 3 +- src/endpoints/gets/apiKey.ts | 3 +- 36 files changed, 229 insertions(+), 215 deletions(-) create mode 100644 src/embeds/api.ts rename src/{commandUtils.ts => embeds/artigen.ts} (56%) create mode 100644 src/embeds/colors.ts rename src/{commonEmbeds.ts => embeds/common.ts} (74%) diff --git a/deno.json b/deno.json index ebc0aba..5e98e24 100644 --- a/deno.json +++ b/deno.json @@ -31,6 +31,7 @@ "~flags": "./flags.ts", "artigen/": "./src/artigen/", "commands/": "./src/commands/", + "embeds/": "./src/embeds/", "endpoints/": "./src/endpoints/", "db/": "./src/db/", "src/": "./src/" diff --git a/mod.ts b/mod.ts index b18fcf9..909b5ce 100644 --- a/mod.ts +++ b/mod.ts @@ -14,8 +14,9 @@ import commands from 'commands/_index.ts'; import dbClient from 'db/client.ts'; import { ignoreList } from 'db/common.ts'; +import { successColor, warnColor } from 'embeds/colors.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'; diff --git a/src/artigen/managers/handler/workerComplete.ts b/src/artigen/managers/handler/workerComplete.ts index 7f3302c..45b2e91 100644 --- a/src/artigen/managers/handler/workerComplete.ts +++ b/src/artigen/managers/handler/workerComplete.ts @@ -14,9 +14,10 @@ import { loggingEnabled } from 'artigen/utils/logFlag.ts'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; +import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed } from 'embeds/artigen.ts'; + import stdResp from 'endpoints/stdResponses.ts'; -import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed } from 'src/commandUtils.ts'; import utils from 'src/utils.ts'; export const onWorkerComplete = async (workerMessage: MessageEvent, workerTimeout: number, rollRequest: QueuedRoll) => { diff --git a/src/artigen/managers/handler/workerTerminate.ts b/src/artigen/managers/handler/workerTerminate.ts index 05540f3..e09a476 100644 --- a/src/artigen/managers/handler/workerTerminate.ts +++ b/src/artigen/managers/handler/workerTerminate.ts @@ -5,9 +5,10 @@ import { RollModifiers } from 'artigen/dice/dice.d.ts'; import { removeWorker } from 'artigen/managers/countManager.ts'; import { QueuedRoll } from 'artigen/managers/manager.d.ts'; +import { generateRollEmbed } from 'embeds/artigen.ts'; + import stdResp from 'endpoints/stdResponses.ts'; -import { generateRollEmbed } from 'src/commandUtils.ts'; import utils from 'src/utils.ts'; export const terminateWorker = async (rollWorker: Worker, rollRequest: QueuedRoll) => { diff --git a/src/artigen/managers/queueManager.ts b/src/artigen/managers/queueManager.ts index fab367f..fbbbc78 100644 --- a/src/artigen/managers/queueManager.ts +++ b/src/artigen/managers/queueManager.ts @@ -6,7 +6,9 @@ import { getWorkerCnt } from 'artigen/managers/countManager.ts'; import { QueuedRoll } from 'artigen/managers/manager.d.ts'; import { handleRollRequest } from 'artigen/managers/workerManager.ts'; -import { infoColor2, rollingEmbed } from 'src/commandUtils.ts'; +import { rollingEmbed } from 'embeds/artigen.ts'; +import { infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; const rollQueue: Array = []; diff --git a/src/commands/apiCmd.ts b/src/commands/apiCmd.ts index 75bf490..941b92b 100644 --- a/src/commands/apiCmd.ts +++ b/src/commands/apiCmd.ts @@ -7,7 +7,8 @@ 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 { failColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const api = async (message: DiscordenoMessage, args: string[]) => { diff --git a/src/commands/apiCmd/allowBlock.ts b/src/commands/apiCmd/allowBlock.ts index c194bad..8b4f26f 100644 --- a/src/commands/apiCmd/allowBlock.ts +++ b/src/commands/apiCmd/allowBlock.ts @@ -2,7 +2,8 @@ import { DiscordenoMessage } from '@discordeno'; import dbClient from 'db/client.ts'; -import { generateApiFailed, generateApiSuccess } from 'src/commandUtils.ts'; +import { generateApiFailed, generateApiSuccess } from 'embeds/api.ts'; + import utils from 'src/utils.ts'; export const allowBlock = async (message: DiscordenoMessage, apiArg: string) => { diff --git a/src/commands/apiCmd/apiHelp.ts b/src/commands/apiCmd/apiHelp.ts index f2b9642..bc04d6c 100644 --- a/src/commands/apiCmd/apiHelp.ts +++ b/src/commands/apiCmd/apiHelp.ts @@ -2,7 +2,8 @@ import { DiscordenoMessage } from '@discordeno'; import config from '~config'; -import { infoColor1, infoColor2 } from 'src/commandUtils.ts'; +import { infoColor1, infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const help = (message: DiscordenoMessage) => { diff --git a/src/commands/apiCmd/deleteGuild.ts b/src/commands/apiCmd/deleteGuild.ts index ef2a2ba..8f438e1 100644 --- a/src/commands/apiCmd/deleteGuild.ts +++ b/src/commands/apiCmd/deleteGuild.ts @@ -4,7 +4,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; -import { failColor, successColor } from 'src/commandUtils.ts'; +import { failColor, successColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const deleteGuild = async (message: DiscordenoMessage) => { diff --git a/src/commands/apiCmd/showHideWarn.ts b/src/commands/apiCmd/showHideWarn.ts index 59e3db9..cc33435 100644 --- a/src/commands/apiCmd/showHideWarn.ts +++ b/src/commands/apiCmd/showHideWarn.ts @@ -2,7 +2,8 @@ import { DiscordenoMessage } from '@discordeno'; import dbClient from 'db/client.ts'; -import { generateApiFailed, generateApiSuccess } from 'src/commandUtils.ts'; +import { generateApiFailed, generateApiSuccess } from 'embeds/api.ts'; + import utils from 'src/utils.ts'; export const showHideWarn = async (message: DiscordenoMessage, apiArg: string) => { diff --git a/src/commands/apiCmd/status.ts b/src/commands/apiCmd/status.ts index ff09a3e..c059624 100644 --- a/src/commands/apiCmd/status.ts +++ b/src/commands/apiCmd/status.ts @@ -2,7 +2,9 @@ import { DiscordenoMessage } from '@discordeno'; import dbClient from 'db/client.ts'; -import { failColor, generateApiStatus } from 'src/commandUtils.ts'; +import { generateApiStatus } from 'embeds/api.ts'; +import { failColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const status = async (message: DiscordenoMessage) => { diff --git a/src/commands/audit.ts b/src/commands/audit.ts index b121355..87f9b78 100644 --- a/src/commands/audit.ts +++ b/src/commands/audit.ts @@ -7,7 +7,8 @@ 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 { failColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const audit = (message: DiscordenoMessage, args: string[]) => { diff --git a/src/commands/auditCmd/auditDB.ts b/src/commands/auditCmd/auditDB.ts index 904aef6..c5038f8 100644 --- a/src/commands/auditCmd/auditDB.ts +++ b/src/commands/auditCmd/auditDB.ts @@ -2,8 +2,9 @@ import { DiscordenoMessage, EmbedField } from '@discordeno'; import dbClient from 'db/client.ts'; -import { compilingStats } from 'src/commonEmbeds.ts'; -import { infoColor2 } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; +import { compilingStats } from 'embeds/common.ts'; + import utils from 'src/utils.ts'; interface DBSizeData { diff --git a/src/commands/auditCmd/auditGuilds.ts b/src/commands/auditCmd/auditGuilds.ts index 94de09e..1b1fd7a 100644 --- a/src/commands/auditCmd/auditGuilds.ts +++ b/src/commands/auditCmd/auditGuilds.ts @@ -2,7 +2,8 @@ import { cache, cacheHandlers, DiscordenoGuild, DiscordenoMessage } from '@disco import config from '~config'; -import { infoColor2 } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; const sortGuildByMemberCount = (a: DiscordenoGuild, b: DiscordenoGuild) => { diff --git a/src/commands/auditCmd/auditHelp.ts b/src/commands/auditCmd/auditHelp.ts index ae93298..4e6d0c4 100644 --- a/src/commands/auditCmd/auditHelp.ts +++ b/src/commands/auditCmd/auditHelp.ts @@ -2,7 +2,8 @@ import { DiscordenoMessage } from '@discordeno'; import config from '~config'; -import { infoColor1 } from 'src/commandUtils.ts'; +import { infoColor1 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const auditHelp = (message: DiscordenoMessage) => { diff --git a/src/commands/handleMentions.ts b/src/commands/handleMentions.ts index fec579f..c82ce58 100644 --- a/src/commands/handleMentions.ts +++ b/src/commands/handleMentions.ts @@ -6,7 +6,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor1 } from 'src/commandUtils.ts'; +import { infoColor1 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const handleMentions = (message: DiscordenoMessage) => { diff --git a/src/commands/heatmap.ts b/src/commands/heatmap.ts index ce2ebb9..1e6c804 100644 --- a/src/commands/heatmap.ts +++ b/src/commands/heatmap.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { failColor, infoColor2 } from 'src/commandUtils.ts'; +import { failColor, infoColor2 } from 'embeds/colors.ts'; + import intervals from 'src/intervals.ts'; import utils from 'src/utils.ts'; diff --git a/src/commands/help.ts b/src/commands/help.ts index 4a42671..845042b 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor2 } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const help = (message: DiscordenoMessage) => { diff --git a/src/commands/info.ts b/src/commands/info.ts index f9f471b..6183cd2 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor2 } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const info = (message: DiscordenoMessage) => { diff --git a/src/commands/optIn.ts b/src/commands/optIn.ts index bd079fd..bc9e47c 100644 --- a/src/commands/optIn.ts +++ b/src/commands/optIn.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { ignoreList, queries } from 'db/common.ts'; -import { failColor, successColor } from 'src/commandUtils.ts'; +import { failColor, successColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const optIn = async (message: DiscordenoMessage) => { diff --git a/src/commands/optOut.ts b/src/commands/optOut.ts index 5580694..00b9266 100644 --- a/src/commands/optOut.ts +++ b/src/commands/optOut.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { ignoreList, queries } from 'db/common.ts'; -import { failColor, successColor } from 'src/commandUtils.ts'; +import { failColor, successColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const optOut = async (message: DiscordenoMessage) => { diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 7678972..164ab3a 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -3,9 +3,19 @@ import { DiscordenoMessage } from '@discordeno'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { generatePing } from 'src/commandUtils.ts'; +import { infoColor1 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; +const generatePing = (time: number) => ({ + embeds: [ + { + color: infoColor1, + title: time === -1 ? 'Ping?' : `Pong! Latency is ${time}ms.`, + }, + ], +}); + export const ping = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run dbClient.execute(queries.callIncCnt('ping')).catch((e) => utils.commonLoggers.dbError('ping.ts:14', 'call sproc INC_CNT on', e)); diff --git a/src/commands/privacy.ts b/src/commands/privacy.ts index 40f73ec..d82da90 100644 --- a/src/commands/privacy.ts +++ b/src/commands/privacy.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor1 } from 'src/commandUtils.ts'; +import { infoColor1 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const privacy = (message: DiscordenoMessage) => { diff --git a/src/commands/report.ts b/src/commands/report.ts index 4804120..8f0d6e0 100644 --- a/src/commands/report.ts +++ b/src/commands/report.ts @@ -5,7 +5,7 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { failColor, generateReport, successColor } from 'src/commandUtils.ts'; +import { failColor, infoColor2, successColor } from 'embeds/colors.ts'; import utils from 'src/utils.ts'; export const report = (message: DiscordenoMessage, args: string[]) => { @@ -13,7 +13,15 @@ export const report = (message: DiscordenoMessage, args: string[]) => { dbClient.execute(queries.callIncCnt('report')).catch((e) => utils.commonLoggers.dbError('report.ts:17', 'call sproc INC_CNT on', e)); if (args.join(' ')) { - sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e)); + sendMessage(config.reportChannel, { + embeds: [ + { + color: infoColor2, + title: 'USER REPORT:', + description: args.join(' ') || 'No message', + }, + ], + }).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e)); message .send({ embeds: [ diff --git a/src/commands/rip.ts b/src/commands/rip.ts index 3131334..6dfd63a 100644 --- a/src/commands/rip.ts +++ b/src/commands/rip.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor2 } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const rip = (message: DiscordenoMessage) => { diff --git a/src/commands/roll.ts b/src/commands/roll.ts index d5cf2a2..fc041f0 100644 --- a/src/commands/roll.ts +++ b/src/commands/roll.ts @@ -11,7 +11,9 @@ import { sendRollRequest } from 'artigen/managers/queueManager.ts'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { generateRollError, rollingEmbed, warnColor } from 'src/commandUtils.ts'; +import { generateRollError, rollingEmbed } from 'embeds/artigen.ts'; +import { warnColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const roll = async (message: DiscordenoMessage, args: string[], command: string) => { diff --git a/src/commands/rollDecorators.ts b/src/commands/rollDecorators.ts index 3ee44d8..3e1ecc8 100644 --- a/src/commands/rollDecorators.ts +++ b/src/commands/rollDecorators.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor2 } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const rollDecorators = (message: DiscordenoMessage) => { diff --git a/src/commands/rollHelp.ts b/src/commands/rollHelp.ts index 28824e0..bbe2dce 100644 --- a/src/commands/rollHelp.ts +++ b/src/commands/rollHelp.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor1, infoColor2, successColor } from 'src/commandUtils.ts'; +import { infoColor1, infoColor2, successColor } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const rollHelp = (message: DiscordenoMessage) => { diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 9180f95..166479c 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -1,10 +1,13 @@ import { cache, cacheHandlers, DiscordenoMessage } from '@discordeno'; +import config from '~config'; + import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { compilingStats } from 'src/commonEmbeds.ts'; -import { generateStats } from 'src/commandUtils.ts'; +import { infoColor2 } from 'embeds/colors.ts'; +import { compilingStats } from 'embeds/common.ts'; + import utils from 'src/utils.ts'; export const stats = async (message: DiscordenoMessage) => { @@ -33,18 +36,45 @@ export const stats = async (message: DiscordenoMessage) => { const endTime = new Date().getTime(); - m.edit( - generateStats( - cachedGuilds + cache.dispatchedGuildIds.size, - cachedChannels + cache.dispatchedChannelIds.size, - cachedMembers, - rolls, - total - rolls, - rollRate, - totalRate - rollRate, - endTime - startTime, - ), - ).catch((e: Error) => utils.commonLoggers.messageEditError('stats.ts:38', m, e)); + m.edit({ + embeds: [ + { + color: infoColor2, + title: `${config.name}'s Statistics:`, + timestamp: new Date().toISOString(), + fields: [ + { + name: 'Guilds:', + value: `${(cachedGuilds + cache.dispatchedGuildIds.size).toLocaleString()}`, + inline: true, + }, + { + name: 'Channels:', + value: `${(cachedChannels + cache.dispatchedChannelIds.size).toLocaleString()}`, + inline: true, + }, + { + name: 'Active Members:', + value: `${cachedMembers.toLocaleString()}`, + inline: true, + }, + { + name: 'Roll Commands:', + value: `${rolls.toLocaleString()}\n(${Math.abs(rollRate).toFixed(2)} per hour)`, + inline: true, + }, + { + name: 'Utility Commands:', + value: `${(total - rolls).toLocaleString()}\n(${Math.abs(totalRate - rollRate).toFixed(2)} per hour)`, + inline: true, + }, + ], + footer: { + text: `Total query time: ${endTime - startTime}ms`, + }, + }, + ], + }).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 4df0bcf..c0f8d6c 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -5,7 +5,8 @@ import config from '~config'; import dbClient from 'db/client.ts'; import { queries } from 'db/common.ts'; -import { infoColor1 } from 'src/commandUtils.ts'; +import { infoColor1 } from 'embeds/colors.ts'; + import utils from 'src/utils.ts'; export const version = (message: DiscordenoMessage) => { diff --git a/src/embeds/api.ts b/src/embeds/api.ts new file mode 100644 index 0000000..9526d8c --- /dev/null +++ b/src/embeds/api.ts @@ -0,0 +1,96 @@ +import config from '../../config.example.ts'; +import { failColor, infoColor1, successColor } from 'src/embeds/colors.ts'; + +export const generateApiFailed = (args: string) => ({ + embeds: [ + { + color: failColor, + title: `Failed to ${args} API rolls for this guild.`, + description: 'If this issue persists, please report this to the developers.', + }, + ], +}); + +export const generateApiStatus = (banned: boolean, active: boolean) => { + const apiStatus = active ? 'allowed' : 'blocked from being used'; + return { + embeds: [ + { + color: infoColor1, + title: `${config.name}'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: [ + { + color: successColor, + title: `API rolls have successfully been ${args} for this guild.`, + }, + ], +}); + +export const generateApiKeyEmail = (email: string, key: string) => ({ + content: `<@${config.api.admin}> A USER HAS REQUESTED AN API KEY`, + embeds: [ + { + color: infoColor1, + fields: [ + { + name: 'Send to:', + value: email, + }, + { + name: 'Subject:', + value: `${config.name} API Key`, + }, + { + name: 'Body:', + value: `Hello ${config.name} API User, + +Welcome aboard ${config.name}'s API. You can find full details about the API on the GitHub: ${config.links.sourceCode} + +Your API Key is: ${key} + +Guard this well, as there is zero tolerance for API abuse. + +Welcome aboard, +${config.name} Developer - Ean Milligan`, + }, + ], + }, + ], +}); + +export const generateApiDeleteEmail = (email: string, deleteCode: string) => ({ + content: `<@${config.api.admin}> A USER HAS REQUESTED A DELETE CODE`, + embeds: [ + { + color: infoColor1, + fields: [ + { + name: 'Send to:', + value: email, + }, + { + name: 'Subject:', + value: `${config.name} API Delete Code`, + }, + { + name: 'Body:', + value: `Hello ${config.name} API User, + +I am sorry to see you go. If you would like, please respond to this email detailing what I could have done better. + +As requested, here is your delete code: ${deleteCode} + +Sorry to see you go, +${config.name} Developer - Ean Milligan`, + }, + ], + }, + ], +}); diff --git a/src/commandUtils.ts b/src/embeds/artigen.ts similarity index 56% rename from src/commandUtils.ts rename to src/embeds/artigen.ts index 739059c..362e1b4 100644 --- a/src/commandUtils.ts +++ b/src/embeds/artigen.ts @@ -7,12 +7,7 @@ import { SolvedRoll } from 'artigen/artigen.d.ts'; import { CountDetails, RollModifiers } from 'artigen/dice/dice.d.ts'; import { loggingEnabled } from 'artigen/utils/logFlag.ts'; - -export const failColor = 0xe71212; -export const warnColor = 0xe38f28; -export const successColor = 0x0f8108; -export const infoColor1 = 0x313bf9; -export const infoColor2 = 0x6805e9; +import { failColor, infoColor1, infoColor2 } from 'embeds/colors.ts'; export const rollingEmbed = { embeds: [ @@ -23,106 +18,6 @@ export const rollingEmbed = { ], }; -export const generatePing = (time: number) => ({ - embeds: [ - { - color: infoColor1, - title: time === -1 ? 'Ping?' : `Pong! Latency is ${time}ms.`, - }, - ], -}); - -export const generateReport = (msg: string) => ({ - embeds: [ - { - color: infoColor2, - title: 'USER REPORT:', - description: msg || 'No message', - }, - ], -}); - -export const generateStats = ( - guildCount: number, - channelCount: number, - memberCount: number, - rollCount: bigint, - utilityCount: bigint, - rollRate: number, - utilityRate: number, - queryTimeMs: number, -) => ({ - embeds: [ - { - color: infoColor2, - title: `${config.name}'s Statistics:`, - timestamp: new Date().toISOString(), - fields: [ - { - name: 'Guilds:', - value: `${guildCount.toLocaleString()}`, - inline: true, - }, - { - name: 'Channels:', - value: `${channelCount.toLocaleString()}`, - inline: true, - }, - { - name: 'Active Members:', - value: `${memberCount.toLocaleString()}`, - inline: true, - }, - { - name: 'Roll Commands:', - value: `${rollCount.toLocaleString()}\n(${Math.abs(rollRate).toFixed(2)} per hour)`, - inline: true, - }, - { - name: 'Utility Commands:', - value: `${utilityCount.toLocaleString()}\n(${Math.abs(utilityRate).toFixed(2)} per hour)`, - inline: true, - }, - ], - footer: { - text: `Total query time: ${queryTimeMs}ms`, - }, - }, - ], -}); - -export const generateApiFailed = (args: string) => ({ - embeds: [ - { - color: failColor, - title: `Failed to ${args} API rolls for this guild.`, - description: 'If this issue persists, please report this to the developers.', - }, - ], -}); - -export const generateApiStatus = (banned: boolean, active: boolean) => { - const apiStatus = active ? 'allowed' : 'blocked from being used'; - return { - embeds: [ - { - color: infoColor1, - title: `${config.name}'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: [ - { - color: successColor, - title: `API rolls have successfully been ${args} for this guild.`, - }, - ], -}); - export const generateDMFailed = (user: bigint) => ({ embeds: [ { @@ -133,68 +28,6 @@ export const generateDMFailed = (user: bigint) => ({ ], }); -export const generateApiKeyEmail = (email: string, key: string) => ({ - content: `<@${config.api.admin}> A USER HAS REQUESTED AN API KEY`, - embeds: [ - { - color: infoColor1, - fields: [ - { - name: 'Send to:', - value: email, - }, - { - name: 'Subject:', - value: `${config.name} API Key`, - }, - { - name: 'Body:', - value: `Hello ${config.name} API User, - -Welcome aboard ${config.name}'s API. You can find full details about the API on the GitHub: ${config.links.sourceCode} - -Your API Key is: ${key} - -Guard this well, as there is zero tolerance for API abuse. - -Welcome aboard, -${config.name} Developer - Ean Milligan`, - }, - ], - }, - ], -}); - -export const generateApiDeleteEmail = (email: string, deleteCode: string) => ({ - content: `<@${config.api.admin}> A USER HAS REQUESTED A DELETE CODE`, - embeds: [ - { - color: infoColor1, - fields: [ - { - name: 'Send to:', - value: email, - }, - { - name: 'Subject:', - value: `${config.name} API Delete Code`, - }, - { - name: 'Body:', - value: `Hello ${config.name} API User, - -I am sorry to see you go. If you would like, please respond to this email detailing what I could have done better. - -As requested, here is your delete code: ${deleteCode} - -Sorry to see you go, -${config.name} Developer - Ean Milligan`, - }, - ], - }, - ], -}); - export const generateRollError = (errorType: string, errorName: string, errorMsg: string) => ({ embeds: [ { diff --git a/src/embeds/colors.ts b/src/embeds/colors.ts new file mode 100644 index 0000000..eff5ed4 --- /dev/null +++ b/src/embeds/colors.ts @@ -0,0 +1,5 @@ +export const failColor = 0xe71212; +export const warnColor = 0xe38f28; +export const successColor = 0x0f8108; +export const infoColor1 = 0x313bf9; +export const infoColor2 = 0x6805e9; diff --git a/src/commonEmbeds.ts b/src/embeds/common.ts similarity index 74% rename from src/commonEmbeds.ts rename to src/embeds/common.ts index 9ec5f0b..664c5d6 100644 --- a/src/commonEmbeds.ts +++ b/src/embeds/common.ts @@ -1,4 +1,4 @@ -import { warnColor } from 'src/commandUtils.ts'; +import { warnColor } from 'embeds/colors.ts'; export const compilingStats = { embeds: [ diff --git a/src/endpoints/deletes/apiKeyDelete.ts b/src/endpoints/deletes/apiKeyDelete.ts index bd64883..1a25e18 100644 --- a/src/endpoints/deletes/apiKeyDelete.ts +++ b/src/endpoints/deletes/apiKeyDelete.ts @@ -8,7 +8,8 @@ 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 { generateApiDeleteEmail } from 'embeds/api.ts'; + import utils from 'src/utils.ts'; export const apiKeyDelete = async (query: Map, apiUserid: bigint, apiUserEmail: string, apiUserDelCode: string): Promise => { diff --git a/src/endpoints/gets/apiKey.ts b/src/endpoints/gets/apiKey.ts index cd22146..821c928 100644 --- a/src/endpoints/gets/apiKey.ts +++ b/src/endpoints/gets/apiKey.ts @@ -8,7 +8,8 @@ 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 { generateApiKeyEmail } from 'embeds/api.ts'; + import utils from 'src/utils.ts'; export const apiKey = async (query: Map): Promise => {