update common embed location, move some back into their own files

This commit is contained in:
Ean Milligan 2025-05-03 20:47:58 -04:00
parent f6eb3b2b69
commit f2797e6c33
36 changed files with 229 additions and 215 deletions

View File

@ -31,6 +31,7 @@
"~flags": "./flags.ts",
"artigen/": "./src/artigen/",
"commands/": "./src/commands/",
"embeds/": "./src/embeds/",
"endpoints/": "./src/endpoints/",
"db/": "./src/db/",
"src/": "./src/"

3
mod.ts
View File

@ -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';

View File

@ -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<SolvedRoll>, workerTimeout: number, rollRequest: QueuedRoll) => {

View File

@ -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) => {

View File

@ -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<QueuedRoll> = [];

View File

@ -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[]) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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[]) => {

View File

@ -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 {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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';

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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));

View File

@ -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) => {

View File

@ -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: [

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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);
}

View File

@ -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) => {

96
src/embeds/api.ts Normal file
View File

@ -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`,
},
],
},
],
});

View File

@ -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: [
{

5
src/embeds/colors.ts Normal file
View File

@ -0,0 +1,5 @@
export const failColor = 0xe71212;
export const warnColor = 0xe38f28;
export const successColor = 0x0f8108;
export const infoColor1 = 0x313bf9;
export const infoColor2 = 0x6805e9;

View File

@ -1,4 +1,4 @@
import { warnColor } from 'src/commandUtils.ts';
import { warnColor } from 'embeds/colors.ts';
export const compilingStats = {
embeds: [

View File

@ -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<string, string>, apiUserid: bigint, apiUserEmail: string, apiUserDelCode: string): Promise<Response> => {

View File

@ -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<string, string>): Promise<Response> => {