From 6cfe98e954a321a6fcd60bafe1108b6e03ecb3ce Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Sat, 28 May 2022 00:09:09 -0400 Subject: [PATCH] deno fmt + rework api subcommands to be a switch statement --- src/commandUtils.ts | 8 +++--- src/commands/apiCmd.ts | 55 ++++++++++++++++++++++++++---------------- src/commands/report.ts | 2 +- src/commands/roll.ts | 6 ++--- src/commands/stats.ts | 2 +- 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/commandUtils.ts b/src/commandUtils.ts index a401882..8a3c27b 100644 --- a/src/commandUtils.ts +++ b/src/commandUtils.ts @@ -208,7 +208,7 @@ export const generateRollEmbed = async (authorId: bigint, returnDetails: SolvedR }, hasAttachment: false, attachment: { - 'blob': await new Blob(['' as BlobPart], { 'type': 'text'}), + 'blob': await new Blob(['' as BlobPart], { 'type': 'text' }), 'name': 'rollDetails.txt', }, }; @@ -224,7 +224,7 @@ Results have been messaged to the following GMs: ${modifiers.gms.join(' ')}`, }, hasAttachment: false, attachment: { - 'blob': await new Blob(['' as BlobPart], { 'type': 'text'}), + 'blob': await new Blob(['' as BlobPart], { 'type': 'text' }), 'name': 'rollDetails.txt', }, }; @@ -257,7 +257,7 @@ ${details}`, }, hasAttachment: false, attachment: { - 'blob': await new Blob(['' as BlobPart], { 'type': 'text'}), + 'blob': await new Blob(['' as BlobPart], { 'type': 'text' }), 'name': 'rollDetails.txt', }, }; @@ -277,7 +277,7 @@ ${details}`, }, hasAttachment: false, attachment: { - 'blob': await new Blob(['' as BlobPart], { 'type': 'text'}), + 'blob': await new Blob(['' as BlobPart], { 'type': 'text' }), 'name': 'rollDetails.txt', }, }; diff --git a/src/commands/apiCmd.ts b/src/commands/apiCmd.ts index afe3285..f54b4ee 100644 --- a/src/commands/apiCmd.ts +++ b/src/commands/apiCmd.ts @@ -3,8 +3,8 @@ import { // Discordeno deps DiscordenoMessage, hasGuildPermissions, - log, // Log4Deno deps + log, LT, } from '../../deps.ts'; import apiCommands from './apiCmd/_index.ts'; @@ -34,26 +34,39 @@ export const api = async (message: DiscordenoMessage, args: string[]) => { // Makes sure the user is authenticated to run the API command if (await hasGuildPermissions(message.authorId, message.guildId, ['ADMINISTRATOR'])) { - // [[api help - // Shows API help details - if (apiArg === 'help' || apiArg === 'h') { - apiCommands.help(message); - } // [[api allow/block - // Lets a guild admin allow or ban API rolls from happening in said guild - else if (apiArg === 'allow' || apiArg === 'block' || apiArg === 'enable' || apiArg === 'disable') { - apiCommands.allowBlock(message, apiArg); - } // [[api delete - // Lets a guild admin delete their server from the database - else if (apiArg === 'delete') { - apiCommands.deleteGuild(message); - } // [[api status - // Lets a guild admin check the status of API rolling in said guild - else if (apiArg === 'status') { - apiCommands.status(message); - } // [[api show-warn/hide-warn - // Lets a guild admin decide if the API warning should be shown on messages from the API - else if (apiArg === 'show-warn' || apiArg === 'hide-warn') { - apiCommands.showHideWarn(message, apiArg); + switch (apiArg) { + case 'help': + case 'h': + // [[api help + // Shows API help details + apiCommands.help(message); + break; + case 'allow': + case 'block': + case 'enable': + case 'disable': + // [[api allow/block + // Lets a guild admin allow or ban API rolls from happening in said guild + apiCommands.allowBlock(message, apiArg); + break; + case 'delete': + // [[api delete + // Lets a guild admin delete their server from the database + apiCommands.deleteGuild(message); + break; + case 'status': + // [[api status + // Lets a guild admin check the status of API rolling in said guild + apiCommands.status(message); + break; + case 'show-warn': + case 'hide-warn': + // [[api show-warn/hide-warn + // Lets a guild admin decide if the API warning should be shown on messages from the API + apiCommands.showHideWarn(message, apiArg); + break; + default: + break; } } else { message.send({ diff --git a/src/commands/report.ts b/src/commands/report.ts index 9c93203..bf0510a 100644 --- a/src/commands/report.ts +++ b/src/commands/report.ts @@ -8,7 +8,7 @@ import { LT, sendMessage, } from '../../deps.ts'; -import { successColor, failColor, generateReport } from '../commandUtils.ts'; +import { failColor, generateReport, successColor } from '../commandUtils.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/roll.ts b/src/commands/roll.ts index db309db..431e767 100644 --- a/src/commands/roll.ts +++ b/src/commands/roll.ts @@ -11,7 +11,7 @@ import { } from '../../deps.ts'; import solver from '../solver/_index.ts'; import { SolvedRoll } from '../solver/solver.d.ts'; -import { warnColor, infoColor1, generateCountDetailsEmbed, generateDMFailed, generateRollEmbed } from '../commandUtils.ts'; +import { generateCountDetailsEmbed, generateDMFailed, generateRollEmbed, infoColor1, warnColor } from '../commandUtils.ts'; import rollFuncs from './roll/_index.ts'; export const roll = async (message: DiscordenoMessage, args: string[], command: string) => { @@ -66,7 +66,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command: // If there was an error, report it to the user in hopes that they can determine what they did wrong if (returnmsg.error) { - m.edit({embeds: [pubEmbedDetails.embed]}); + m.edit({ embeds: [pubEmbedDetails.embed] }); if (DEVMODE && config.logRolls) { // If enabled, log rolls so we can see what went wrong @@ -78,7 +78,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command: // Determine if we are to send a GM roll or a normal roll if (modifiers.gmRoll) { // Send the public embed to correct channel - m.edit({embeds: [pubEmbedDetails.embed]}); + m.edit({ embeds: [pubEmbedDetails.embed] }); // And message the full details to each of the GMs, alerting roller of every GM that could not be messaged modifiers.gms.forEach(async (gm) => { diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 81d0e74..ec842bd 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -8,7 +8,7 @@ import { // Log4Deno deps LT, } from '../../deps.ts'; -import { warnColor, generateStats } from '../commandUtils.ts'; +import { generateStats, warnColor } from '../commandUtils.ts'; export const stats = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run