From 6f21789c46bdf821cba7231a6f125b5e6e931cad Mon Sep 17 00:00:00 2001 From: tresabhi Date: Wed, 21 Jun 2023 02:01:12 +0000 Subject: [PATCH] feat: moved cmdName behaviour to interaction create --- src/commands/debug.ts | 3 +-- src/commands/eligible.ts | 3 +-- src/commands/evolution.tsx | 3 +-- src/commands/help.ts | 3 +-- src/commands/inactive.tsx | 3 +-- src/commands/ownedtanks.tsx | 3 +-- src/commands/ping.ts | 3 +-- src/commands/playerachievements.ts | 3 +-- src/commands/playerinfo.ts | 3 +-- src/commands/searchclans.ts | 3 +-- src/commands/searchplayers.ts | 3 +-- src/commands/searchtanks.ts | 3 +-- src/commands/stats.tsx | 3 +-- src/commands/today.tsx | 3 +-- src/commands/verify.ts | 3 +-- src/core/interaction/cmdName.ts | 5 ----- src/events/interactionCreate.ts | 8 ++++++-- 17 files changed, 21 insertions(+), 37 deletions(-) delete mode 100644 src/core/interaction/cmdName.ts diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 9b7175480..8a6651562 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -3,7 +3,6 @@ import packageJSON from '../../package.json' assert { type: 'json' }; import { tankopedia } from '../core/blitz/tankopedia.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; import cleanTable from '../core/interaction/cleanTable.js'; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import getClientId from '../core/process/getClientId.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -17,7 +16,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('debug')) + .setName('debug') .setDescription('Debug information about the bot'), execute(interaction) { diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 13615f71c..c30b32390 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -9,7 +9,6 @@ import getPeriodStart from '../core/blitzstars/getPeriodStart.js'; import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; import cleanTable, { TableInput } from '../core/interaction/cleanTable.js'; -import cmdName from '../core/interaction/cmdName.js'; import negativeEmbed from '../core/interaction/negativeEmbed.js'; import positiveEmbed from '../core/interaction/positiveEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; @@ -30,7 +29,7 @@ export default { inPublic: false, command: new SlashCommandBuilder() - .setName(cmdName('eligible')) + .setName('eligible') .setDescription('Checks eligibility for any Skilled clan') .addStringOption((option) => option diff --git a/src/commands/evolution.tsx b/src/commands/evolution.tsx index 5a6fdcb09..27a6599d0 100644 --- a/src/commands/evolution.tsx +++ b/src/commands/evolution.tsx @@ -13,7 +13,6 @@ import resolveTankId from '../core/blitz/resolveTankId.js'; import resolveTankName from '../core/blitz/resolveTankName.js'; import { tankopedia } from '../core/blitz/tankopedia.js'; import getTankHistories from '../core/blitzstars/getTankHistories.js'; -import cmdName from '../core/interaction/cmdName.js'; import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js'; import { Period, @@ -33,7 +32,7 @@ export default { command: addStatsSubCommandGroups( new SlashCommandBuilder() - .setName(cmdName('evolution')) + .setName('evolution') .setDescription('Evolution of statistics'), ), diff --git a/src/commands/help.ts b/src/commands/help.ts index 292c3d379..671298988 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,6 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import { CommandRegistry, @@ -15,7 +14,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('help')) + .setName('help') .setDescription('All the help you need about the bot'), execute(interaction) { diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index 8c781ee85..d1db738dc 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -8,7 +8,6 @@ import { BLITZ_SERVERS } from '../constants/servers.js'; import clanAutocomplete from '../core/autocomplete/clan.js'; import getBlitzClan from '../core/blitz/getBlitzClan.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import cmdName from '../core/interaction/cmdName.js'; import addClanChoices from '../core/options/addClanChoices.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -23,7 +22,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('inactive')) + .setName('inactive') .setDescription('Lists all inactive players') .addStringOption(addClanChoices) .addNumberOption((option) => diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index 8a23ecf05..d92d5e1c3 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -14,7 +14,6 @@ import { Tier, tankopedia, } from '../core/blitz/tankopedia.js'; -import cmdName from '../core/interaction/cmdName.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -48,7 +47,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('ownedtanks')) + .setName('ownedtanks') .setDescription("Shows a player's owned tanks") .addStringOption((option) => option diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 1493876ad..13f58fe34 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,5 +1,4 @@ import { SlashCommandBuilder } from 'discord.js'; -import cmdName from '../core/interaction/cmdName.js'; import { CommandRegistry } from '../events/interactionCreate.js'; export default { @@ -9,7 +8,7 @@ export default { handlesInteraction: true, command: new SlashCommandBuilder() - .setName(cmdName('ping')) + .setName('ping') .setDescription('Check if the bot is alive'), async execute(interaction) { diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index b65e3626d..d230d712f 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -5,7 +5,6 @@ import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.js'; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; @@ -21,7 +20,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('playerachievements')) + .setName('playerachievements') .setDescription("All the player's achievements") .addStringOption(addUsernameOption) .addStringOption((option) => diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index 77b339508..9aae9269d 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -4,7 +4,6 @@ import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cleanTable from '../core/interaction/cleanTable.js'; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; @@ -17,7 +16,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('playerinfo')) + .setName('playerinfo') .setDescription('Basic information about a player') .addStringOption(addUsernameOption), diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index ef65b10b3..7d811ed16 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -2,7 +2,6 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import addClanChoices from '../core/options/addClanChoices.js'; import addServerChoices from '../core/options/addServerChoices.js'; @@ -16,7 +15,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('searchclans')) + .setName('searchclans') .setDescription('Search clans') .addStringOption(addServerChoices) .addStringOption((option) => addClanChoices(option).setAutocomplete(false)) diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 63a61d61a..35aa16395 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -3,7 +3,6 @@ import markdownEscape from 'markdown-escape'; import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import { usernamePattern } from '../core/blitz/listAccountsPanServer.js'; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import addServerChoices from '../core/options/addServerChoices.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; @@ -17,7 +16,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('searchplayers')) + .setName('searchplayers') .setDescription('Search players in a Blitz server') .addStringOption(addServerChoices) .addStringOption((option) => diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index c9760df1c..d19bf7762 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -2,7 +2,6 @@ import { SlashCommandBuilder } from 'discord.js'; import { go } from 'fuzzysort'; import markdownEscape from 'markdown-escape'; import { TANK_NAMES } from '../core/blitz/tankopedia.js'; -import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import addTankChoices from '../core/options/addTankChoices.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -13,7 +12,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('searchtanks')) + .setName('searchtanks') .setDescription('Search tanks') .addStringOption((option) => addTankChoices(option).setAutocomplete(false)) .addIntegerOption((option) => diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 9a65c019c..ea98a9706 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -17,7 +17,6 @@ import sumStats from '../core/blitz/sumStats.js'; import { Tier, tankopedia } from '../core/blitz/tankopedia.js'; import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; -import cmdName from '../core/interaction/cmdName.js'; import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js'; import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; @@ -36,7 +35,7 @@ export default { command: addStatsSubCommandGroups( new SlashCommandBuilder() - .setName(cmdName('stats')) + .setName('stats') .setDescription('In-game statistics'), ), diff --git a/src/commands/today.tsx b/src/commands/today.tsx index b30fd4a26..9ea6bf384 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -16,7 +16,6 @@ import { tankopedia } from '../core/blitz/tankopedia.js'; import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js'; import last5AM from '../core/blitzstars/last5AM.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; -import cmdName from '../core/interaction/cmdName.js'; import fullBlitzStarsStats from '../core/interaction/fullBlitzStarsStats.js'; import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; @@ -31,7 +30,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('today')) + .setName('today') .setDescription('A general daily breakdown of your performance') .addStringOption(addUsernameOption), diff --git a/src/commands/verify.ts b/src/commands/verify.ts index cbc0643f8..2afe3fdb0 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -4,7 +4,6 @@ import discord from '../../discord.json' assert { type: 'json' }; import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import cmdName from '../core/interaction/cmdName.js'; import negativeEmbed from '../core/interaction/negativeEmbed.js'; import positiveEmbed from '../core/interaction/positiveEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; @@ -19,7 +18,7 @@ export default { inPublic: true, command: new SlashCommandBuilder() - .setName(cmdName('verify')) + .setName('verify') .setDescription("Set's the user's username to their in-game name") .addStringOption((option) => addUsernameOption(option).setRequired(true)), diff --git a/src/core/interaction/cmdName.ts b/src/core/interaction/cmdName.ts deleted file mode 100644 index f53126d81..000000000 --- a/src/core/interaction/cmdName.ts +++ /dev/null @@ -1,5 +0,0 @@ -import isDev from '../process/isDev.js'; - -export default function cmdName(name: string) { - return isDev() ? `${name}dev` : name; -} diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index a8ce85cc9..48e30dd6b 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -96,10 +96,14 @@ export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = Object.entries(commands).forEach(([, registry]) => { if (isDev() ? registry.inDevelopment : registry.inProduction) { + const json = registry.command + .setName(isDev() ? `${registry.command.name}dev` : registry.command.name) + .toJSON(); + if (registry.inPublic) { - publicCommands.push(registry.command.toJSON()); + publicCommands.push(json); } else { - guildCommands.push(registry.command.toJSON()); + guildCommands.push(json); } } });