From 01ed20941d2a39053a359e94ce9e935fc903a047 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Tue, 27 Jun 2023 02:22:28 +0000 Subject: [PATCH] feat: cleaned discord --- src/commands/debug.ts | 8 +++---- src/commands/eligible.ts | 16 +++++++------- src/commands/evolution.tsx | 12 +++++----- src/commands/help.ts | 4 ++-- src/commands/inactive.tsx | 4 ++-- src/commands/ownedtanks.tsx | 8 +++---- src/commands/playerachievements.ts | 18 ++++++++------- src/commands/playerinfo.ts | 16 +++++++------- src/commands/searchclans.ts | 4 ++-- src/commands/searchplayers.ts | 8 +++---- src/commands/searchtanks.ts | 4 ++-- src/commands/stats.tsx | 12 +++++----- src/commands/today.tsx | 8 +++---- src/commands/verify.ts | 22 +++++++++---------- ...oups.ts => addStatTypeSubCommandGroups.ts} | 10 +++++---- ...sernameOption.ts => addUsernameChoices.ts} | 2 +- ...lanAutocomplete.ts => autocompleteClan.ts} | 2 +- ...ksAutocomplete.ts => autocompleteTanks.ts} | 2 +- ...utocomplete.ts => autocompleteUsername.ts} | 2 +- .../discord/{infoEmbed.ts => embedInfo.ts} | 2 +- .../{negativeEmbed.ts => embedNegative.ts} | 2 +- .../{positiveEmbed.ts => embedPositive.ts} | 2 +- .../{warningEmbed.ts => embedWarning.ts} | 2 +- src/core/discord/fullBlitzStarsStats.ts | 12 ---------- src/core/discord/generateCustomId.ts | 9 -------- .../{cleanTable.ts => markdownTable.ts} | 2 +- src/core/discord/noMember.ts | 6 ----- src/core/discord/notTrackedByBlitzStars.ts | 6 ----- src/core/discord/supportBlitzStars.ts | 1 + .../handlers/chatInputCommand.ts | 8 +++---- 30 files changed, 93 insertions(+), 121 deletions(-) rename src/core/discord/{addStatsSubCommandGroups.ts => addStatTypeSubCommandGroups.ts} (70%) rename src/core/discord/{addUsernameOption.ts => addUsernameChoices.ts} (75%) rename src/core/discord/{clanAutocomplete.ts => autocompleteClan.ts} (94%) rename src/core/discord/{tanksAutocomplete.ts => autocompleteTanks.ts} (94%) rename src/core/discord/{usernameAutocomplete.ts => autocompleteUsername.ts} (95%) rename src/core/discord/{infoEmbed.ts => embedInfo.ts} (77%) rename src/core/discord/{negativeEmbed.ts => embedNegative.ts} (78%) rename src/core/discord/{positiveEmbed.ts => embedPositive.ts} (78%) rename src/core/discord/{warningEmbed.ts => embedWarning.ts} (78%) delete mode 100644 src/core/discord/fullBlitzStarsStats.ts delete mode 100644 src/core/discord/generateCustomId.ts rename src/core/discord/{cleanTable.ts => markdownTable.ts} (81%) delete mode 100644 src/core/discord/noMember.ts delete mode 100644 src/core/discord/notTrackedByBlitzStars.ts diff --git a/src/commands/debug.ts b/src/commands/debug.ts index bb669e193..9cfb93357 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -3,8 +3,8 @@ import packageJSON from '../../package.json' assert { type: 'json' }; import { client } from '../bot.js'; import { tankopedia } from '../core/blitz/tankopedia.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; -import cleanTable from '../core/discord/cleanTable.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import embedInfo from '../core/discord/embedInfo.js'; +import markdownTable from '../core/discord/markdownTable.js'; import getClientId from '../core/node/getClientId.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; @@ -23,9 +23,9 @@ export default { const currentTime = new Date().getTime(); const uptime = currentTime - executionStart; - return infoEmbed( + return embedInfo( `${client.user?.username} debug information`, - cleanTable([ + markdownTable([ ['Version', packageJSON.version], ['Client ID', getClientId()], ['Tag', interaction.client.user.tag], diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index adae55419..faa00c9e7 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -7,10 +7,10 @@ import getPeriodNow from '../core/blitzstars/getPeriodNow.js'; import getPeriodStart from '../core/blitzstars/getPeriodStart.js'; import getTankStatsDiffed from '../core/blitzstars/getTankStatsDiffed.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; -import cleanTable, { TableInput } from '../core/discord/cleanTable.js'; -import negativeEmbed from '../core/discord/negativeEmbed.js'; -import positiveEmbed from '../core/discord/positiveEmbed.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import embedNegative from '../core/discord/embedNegative.js'; +import embedPositive from '../core/discord/embedPositive.js'; +import markdownTable, { TableInput } from '../core/discord/markdownTable.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; @@ -44,7 +44,7 @@ export default { ) .setRequired(true), ) - .addStringOption(addUsernameOption), + .addStringOption(addUsernameChoices), async handler(interaction) { const clan = interaction.options.getString('clan') as SkilledClan; @@ -137,7 +137,7 @@ export default { isEligible = problems.length === 0; body = isEligible ? 'Player is fully eligible.' - : `Player is not eligible. Shortcomings in 30-day statistics:\n\n${cleanTable( + : `Player is not eligible. Shortcomings in 30-day statistics:\n\n${markdownTable( problems, )}`; } else if (clan === 'SMRI') { @@ -162,11 +162,11 @@ export default { isEligible = problems.length === 0; body = isEligible ? 'Player is fully eligible.' - : `Player is not eligible. Shortcomings in career statistics:\n\n${cleanTable( + : `Player is not eligible. Shortcomings in career statistics:\n\n${markdownTable( problems, )}`; } - return (isEligible ? positiveEmbed : negativeEmbed)(title, body); + return (isEligible ? embedPositive : embedNegative)(title, body); }, } satisfies CommandRegistry; diff --git a/src/commands/evolution.tsx b/src/commands/evolution.tsx index d389e7ed7..165fe79bc 100644 --- a/src/commands/evolution.tsx +++ b/src/commands/evolution.tsx @@ -1,10 +1,10 @@ import { SlashCommandBuilder } from 'discord.js'; import resolveTankId from '../core/blitz/resolveTankId.js'; -import addStatsSubCommandGroups from '../core/discord/addStatsSubCommandGroups.js'; +import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups.js'; +import autocompleteTanks from '../core/discord/autocompleteTanks.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import tanksAutocomplete from '../core/discord/tanksAutocomplete.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import evolution from '../renderers/evolution.js'; import { StatType } from '../renderers/stats.js'; @@ -14,7 +14,7 @@ export default { inDevelopment: true, inPublic: true, - command: addStatsSubCommandGroups( + command: addStatTypeSubCommandGroups( new SlashCommandBuilder() .setName('evolution') .setDescription('Evolution of statistics'), @@ -45,7 +45,7 @@ export default { }, autocomplete: (interaction) => { - usernameAutocomplete(interaction); - tanksAutocomplete(interaction); + autocompleteUsername(interaction); + autocompleteTanks(interaction); }, } satisfies CommandRegistry; diff --git a/src/commands/help.ts b/src/commands/help.ts index a65c18293..2ce447da2 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,7 +1,7 @@ import { SlashCommandBuilder } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; import { client } from '../bot.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import embedInfo from '../core/discord/embedInfo.js'; import { CommandRegistry, guildCommands, @@ -18,7 +18,7 @@ export default { .setDescription('All the help you need about the bot'), handler(interaction) { - return infoEmbed( + return embedInfo( `${client.user?.username} help`, `**About**\n${ client.user?.username diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index dc52d8163..d47a52278 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -8,7 +8,7 @@ import { BLITZ_SERVERS } from '../constants/servers.js'; import getBlitzClan from '../core/blitz/getBlitzClan.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import addClanChoices from '../core/discord/addClanChoices.js'; -import clanAutocomplete from '../core/discord/clanAutocomplete.js'; +import autocompleteClan from '../core/discord/autocompleteClan.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -84,5 +84,5 @@ export default { ); }, - autocomplete: clanAutocomplete, + autocomplete: autocompleteClan, } satisfies CommandRegistry; diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index 7fb28c870..5dd529765 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -12,9 +12,9 @@ import { Tier, tankopedia, } from '../core/blitz/tankopedia.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -67,7 +67,7 @@ export default { ) .setRequired(true), ) - .addStringOption(addUsernameOption), + .addStringOption(addUsernameChoices), async handler(interaction) { const tier = Number(interaction.options.getString('tier')); @@ -120,5 +120,5 @@ export default { ); }, - autocomplete: usernameAutocomplete, + autocomplete: autocompleteUsername, } satisfies CommandRegistry; diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index b8f9872a4..0f566c6db 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -2,11 +2,13 @@ import { SlashCommandBuilder } from 'discord.js'; import { startCase } from 'lodash'; import markdownEscape from 'markdown-escape'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; -import cleanTable, { TableInputEntry } from '../core/discord/cleanTable.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; +import embedInfo from '../core/discord/embedInfo.js'; +import markdownTable, { + TableInputEntry, +} from '../core/discord/markdownTable.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { AccountAchievements } from '../types/accountAchievements.js'; @@ -22,7 +24,7 @@ export default { command: new SlashCommandBuilder() .setName('playerachievements') .setDescription("All the player's achievements") - .addStringOption(addUsernameOption) + .addStringOption(addUsernameChoices) .addStringOption((option) => option .setName('sort') @@ -50,10 +52,10 @@ export default { ...accountAchievements.max_series, }; - return infoEmbed( + return embedInfo( `${markdownEscape(accounts[id].nickname)}'s information`, - cleanTable( + markdownTable( Object.keys(compound) .filter((achievement) => compound[achievement] > 0) .sort( @@ -72,5 +74,5 @@ export default { ); }, - autocomplete: usernameAutocomplete, + autocomplete: autocompleteUsername, } satisfies CommandRegistry; diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index b7349f0a8..1066e7e60 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -1,11 +1,11 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; -import cleanTable from '../core/discord/cleanTable.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; +import embedInfo from '../core/discord/embedInfo.js'; +import markdownTable from '../core/discord/markdownTable.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -18,7 +18,7 @@ export default { command: new SlashCommandBuilder() .setName('playerinfo') .setDescription('Basic information about a player') - .addStringOption(addUsernameOption), + .addStringOption(addUsernameChoices), async handler(interaction) { const account = await resolvePlayerFromCommand(interaction); @@ -28,10 +28,10 @@ export default { ); const accountInfo = accounts[id]; - return infoEmbed( + return embedInfo( `${markdownEscape(accountInfo.nickname)}'s information`, - cleanTable([ + markdownTable([ ['Nickname', `${accountInfo.nickname}`], ['Battles', `${accountInfo.statistics.all.battles}`], [ @@ -56,5 +56,5 @@ export default { ); }, - autocomplete: usernameAutocomplete, + autocomplete: autocompleteUsername, } satisfies CommandRegistry; diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index 674b18c8a..d29675fe7 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -4,7 +4,7 @@ import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import addClanChoices from '../core/discord/addClanChoices.js'; import addServerChoices from '../core/discord/addServerChoices.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import embedInfo from '../core/discord/embedInfo.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { ClanList } from '../types/clanList.js'; @@ -35,7 +35,7 @@ export default { `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`, ); - return infoEmbed( + return embedInfo( `Clan search for "${markdownEscape(clan)}" in ${BLITZ_SERVERS[server]}`, clanList.length === 0 ? 'No clans found.' diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index f0d6a13ce..aad73abc1 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -4,8 +4,8 @@ import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import { usernamePattern } from '../core/blitz/listPlayers.js'; import addServerChoices from '../core/discord/addServerChoices.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import embedInfo from '../core/discord/embedInfo.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { AccountList } from '../types/accountList.js'; @@ -20,7 +20,7 @@ export default { .setDescription('Search players in a Blitz server') .addStringOption(addServerChoices) .addStringOption((option) => - addUsernameOption(option).setAutocomplete(false).setRequired(true), + addUsernameChoices(option).setAutocomplete(false).setRequired(true), ) .addIntegerOption((option) => option @@ -43,7 +43,7 @@ export default { ) : []; - return infoEmbed( + return embedInfo( `Player search for "${markdownEscape(name)}" in ${BLITZ_SERVERS[server]}`, `\`\`\`${ players.length === 0 diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index dd320f77b..76e4157c3 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -3,7 +3,7 @@ import { go } from 'fuzzysort'; import markdownEscape from 'markdown-escape'; import { TANK_NAMES } from '../core/blitz/tankopedia.js'; import addTankChoices from '../core/discord/addTankChoices.js'; -import infoEmbed from '../core/discord/infoEmbed.js'; +import embedInfo from '../core/discord/embedInfo.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; export default { @@ -30,7 +30,7 @@ export default { (result) => result.target, ); - return infoEmbed( + return embedInfo( `Tank search for "${markdownEscape(tank)}"`, results.length === 0 ? 'No tanks found.' diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index f2d99b0b8..8194b7db2 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -2,7 +2,9 @@ import { SlashCommandBuilder } from 'discord.js'; import { CYCLIC_API } from '../constants/cyclic.js'; import resolveTankId from '../core/blitz/resolveTankId.js'; import { Period } from '../core/discord/addPeriodSubCommands.js'; -import addStatsSubCommandGroups from '../core/discord/addStatsSubCommandGroups.js'; +import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups.js'; +import autocompleteTanks from '../core/discord/autocompleteTanks.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; import interactionToURL from '../core/discord/interactionToURL.js'; import linkButton from '../core/discord/linkButton.js'; import primaryButton from '../core/discord/primaryButton.js'; @@ -10,8 +12,6 @@ import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton.js' import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand.js'; import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import tanksAutocomplete from '../core/discord/tanksAutocomplete.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import stats, { StatType } from '../renderers/stats.js'; @@ -20,7 +20,7 @@ export default { inDevelopment: false, inPublic: true, - command: addStatsSubCommandGroups( + command: addStatTypeSubCommandGroups( new SlashCommandBuilder() .setName('stats') .setDescription('In-game statistics'), @@ -51,8 +51,8 @@ export default { }, autocomplete: (interaction) => { - usernameAutocomplete(interaction); - tanksAutocomplete(interaction); + autocompleteUsername(interaction); + autocompleteTanks(interaction); }, async button(interaction) { diff --git a/src/commands/today.tsx b/src/commands/today.tsx index 786148753..e7f29d0e0 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -1,7 +1,7 @@ import { SlashCommandBuilder } from 'discord.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import today from '../renderers/today.js'; @@ -13,7 +13,7 @@ export default { command: new SlashCommandBuilder() .setName('today') .setDescription('A general daily breakdown of your performance') - .addStringOption(addUsernameOption), + .addStringOption(addUsernameChoices), async handler(interaction) { const player = await resolvePlayerFromCommand(interaction); @@ -21,5 +21,5 @@ export default { return await today(player); }, - autocomplete: usernameAutocomplete, + autocomplete: autocompleteUsername, } satisfies CommandRegistry; diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 6888a7455..8ea2582c9 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -2,11 +2,11 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import discord from '../../discord.json' assert { type: 'json' }; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import addUsernameOption from '../core/discord/addUsernameOption.js'; -import negativeEmbed from '../core/discord/negativeEmbed.js'; -import positiveEmbed from '../core/discord/positiveEmbed.js'; +import addUsernameChoices from '../core/discord/addUsernameChoices.js'; +import autocompleteUsername from '../core/discord/autocompleteUsername.js'; +import embedNegative from '../core/discord/embedNegative.js'; +import embedPositive from '../core/discord/embedPositive.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; -import usernameAutocomplete from '../core/discord/usernameAutocomplete.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { CommandRegistry } from '../events/interactionCreate/index.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -20,7 +20,7 @@ export default { command: new SlashCommandBuilder() .setName('verify') .setDescription("Set's the user's username to their in-game name") - .addStringOption((option) => addUsernameOption(option).setRequired(true)), + .addStringOption((option) => addUsernameChoices(option).setRequired(true)), async handler(interaction) { const blitzAccount = await resolvePlayerFromCommand(interaction); @@ -38,13 +38,13 @@ export default { interaction.guild?.members.cache.get(interaction.member?.user.id); if (!interaction.guild?.members.me?.permissions.has('ManageNicknames')) { - return negativeEmbed( + return embedNegative( `${markdownEscape(interaction.user.username)} failed to verify`, "I don't have the permission to change your nickname.", ); } if (!interaction.member || !member) { - return negativeEmbed( + return embedNegative( `${interaction.user.username} is not in this server`, "I couldn't find this person in this server. Did they leave?", ); @@ -55,7 +55,7 @@ export default { if (interaction.guildId === discord.sklld_guild_id) { if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) { - return negativeEmbed( + return embedNegative( `${markdownEscape(interaction.user.username)} failed to verify`, "I don't have the permission to change your manage roles.", ); @@ -65,19 +65,19 @@ export default { await member.roles.add(discord.sklld_peasant_role); } - return positiveEmbed( + return embedPositive( `${interaction.user.username} is verified`, `The user is now verified as ${markdownEscape( accountInfo[id].nickname, )}${markdownEscape(clanTag)}`, ); } catch (error) { - return negativeEmbed( + return embedNegative( `${interaction.user.username} failed to verify`, "I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.", ); } }, - autocomplete: usernameAutocomplete, + autocomplete: autocompleteUsername, } satisfies CommandRegistry; diff --git a/src/core/discord/addStatsSubCommandGroups.ts b/src/core/discord/addStatTypeSubCommandGroups.ts similarity index 70% rename from src/core/discord/addStatsSubCommandGroups.ts rename to src/core/discord/addStatTypeSubCommandGroups.ts index f24315784..a5657db10 100644 --- a/src/core/discord/addStatsSubCommandGroups.ts +++ b/src/core/discord/addStatTypeSubCommandGroups.ts @@ -1,13 +1,15 @@ import { SlashCommandBuilder } from 'discord.js'; import addPeriodSubCommands from './addPeriodSubCommands.js'; import addTankChoices from './addTankChoices.js'; -import addUsernameOption from './addUsernameOption.js'; +import addUsernameChoices from './addUsernameChoices.js'; -export default function addStatsSubCommandGroups(option: SlashCommandBuilder) { +export default function addStatTypeSubCommandGroups( + option: SlashCommandBuilder, +) { return option .addSubcommandGroup((option) => addPeriodSubCommands(option, (option) => - option.addStringOption(addUsernameOption), + option.addStringOption(addUsernameChoices), ) .setName('player') .setDescription("Player's statistics"), @@ -16,7 +18,7 @@ export default function addStatsSubCommandGroups(option: SlashCommandBuilder) { addPeriodSubCommands(option, (option) => option .addStringOption(addTankChoices) - .addStringOption(addUsernameOption), + .addStringOption(addUsernameChoices), ) .setName('tank') .setDescription("Tank's statistics"), diff --git a/src/core/discord/addUsernameOption.ts b/src/core/discord/addUsernameChoices.ts similarity index 75% rename from src/core/discord/addUsernameOption.ts rename to src/core/discord/addUsernameChoices.ts index c5da50df8..cc089f368 100644 --- a/src/core/discord/addUsernameOption.ts +++ b/src/core/discord/addUsernameChoices.ts @@ -1,6 +1,6 @@ import { SlashCommandStringOption } from 'discord.js'; -export default function addUsernameOption(option: SlashCommandStringOption) { +export default function addUsernameChoices(option: SlashCommandStringOption) { return option .setName('username') .setDescription( diff --git a/src/core/discord/clanAutocomplete.ts b/src/core/discord/autocompleteClan.ts similarity index 94% rename from src/core/discord/clanAutocomplete.ts rename to src/core/discord/autocompleteClan.ts index 4f375e749..78c7df143 100644 --- a/src/core/discord/clanAutocomplete.ts +++ b/src/core/discord/autocompleteClan.ts @@ -6,7 +6,7 @@ import { import { BLITZ_SERVERS } from '../../constants/servers.js'; import listClans from '../blitz/listClans.js'; -export default async function clanAutocomplete( +export default async function autocompleteClan( interaction: AutocompleteInteraction, ) { const focusedOption = interaction.options.getFocused(true); diff --git a/src/core/discord/tanksAutocomplete.ts b/src/core/discord/autocompleteTanks.ts similarity index 94% rename from src/core/discord/tanksAutocomplete.ts rename to src/core/discord/autocompleteTanks.ts index 7d5776f7d..8b45d8022 100644 --- a/src/core/discord/tanksAutocomplete.ts +++ b/src/core/discord/autocompleteTanks.ts @@ -7,7 +7,7 @@ import { go } from 'fuzzysort'; import resolveTankName from '../blitz/resolveTankName.js'; import { TANKS } from '../blitz/tankopedia.js'; -export default async function tanksAutocomplete( +export default async function autocompleteTanks( interaction: AutocompleteInteraction, ) { const focusedOption = interaction.options.getFocused(true); diff --git a/src/core/discord/usernameAutocomplete.ts b/src/core/discord/autocompleteUsername.ts similarity index 95% rename from src/core/discord/usernameAutocomplete.ts rename to src/core/discord/autocompleteUsername.ts index 6b3e8d283..871f424f2 100644 --- a/src/core/discord/usernameAutocomplete.ts +++ b/src/core/discord/autocompleteUsername.ts @@ -6,7 +6,7 @@ import { import { BLITZ_SERVERS } from '../../constants/servers.js'; import listPlayers from '../blitz/listPlayers.js'; -export default async function usernameAutocomplete( +export default async function autocompleteUsername( interaction: AutocompleteInteraction, ) { const focusedOption = interaction.options.getFocused(true); diff --git a/src/core/discord/infoEmbed.ts b/src/core/discord/embedInfo.ts similarity index 77% rename from src/core/discord/infoEmbed.ts rename to src/core/discord/embedInfo.ts index 21976cd95..4c591e1f6 100644 --- a/src/core/discord/infoEmbed.ts +++ b/src/core/discord/embedInfo.ts @@ -1,7 +1,7 @@ import { EmbedBuilder } from 'discord.js'; import { ACCENT_COLOR } from '../../constants/colors.js'; -export default function infoEmbed(title: string, description: string) { +export default function embedInfo(title: string, description: string) { return new EmbedBuilder() .setColor(ACCENT_COLOR) .setTitle(title) diff --git a/src/core/discord/negativeEmbed.ts b/src/core/discord/embedNegative.ts similarity index 78% rename from src/core/discord/negativeEmbed.ts rename to src/core/discord/embedNegative.ts index f01024c82..54e11ab8b 100644 --- a/src/core/discord/negativeEmbed.ts +++ b/src/core/discord/embedNegative.ts @@ -1,7 +1,7 @@ import { EmbedBuilder } from 'discord.js'; import { NEGATIVE_COLOR } from '../../constants/colors.js'; -export default function negativeEmbed(title: string, description: string) { +export default function embedNegative(title: string, description: string) { return new EmbedBuilder() .setColor(NEGATIVE_COLOR) .setTitle(title) diff --git a/src/core/discord/positiveEmbed.ts b/src/core/discord/embedPositive.ts similarity index 78% rename from src/core/discord/positiveEmbed.ts rename to src/core/discord/embedPositive.ts index 29a86adc5..c9067d818 100644 --- a/src/core/discord/positiveEmbed.ts +++ b/src/core/discord/embedPositive.ts @@ -1,7 +1,7 @@ import { EmbedBuilder } from 'discord.js'; import { POSITIVE_COLOR } from '../../constants/colors.js'; -export default function positiveEmbed(title: string, description: string) { +export default function embedPositive(title: string, description: string) { return new EmbedBuilder() .setColor(POSITIVE_COLOR) .setTitle(title) diff --git a/src/core/discord/warningEmbed.ts b/src/core/discord/embedWarning.ts similarity index 78% rename from src/core/discord/warningEmbed.ts rename to src/core/discord/embedWarning.ts index b8006d1c2..45ee01909 100644 --- a/src/core/discord/warningEmbed.ts +++ b/src/core/discord/embedWarning.ts @@ -1,7 +1,7 @@ import { EmbedBuilder } from 'discord.js'; import { WARNING_COLOR } from '../../constants/colors.js'; -export default function warningEmbed(title: string, description: string) { +export default function embedWarning(title: string, description: string) { return new EmbedBuilder() .setColor(WARNING_COLOR) .setTitle(title) diff --git a/src/core/discord/fullBlitzStarsStats.ts b/src/core/discord/fullBlitzStarsStats.ts deleted file mode 100644 index 362e202c5..000000000 --- a/src/core/discord/fullBlitzStarsStats.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ButtonBuilder, ButtonStyle } from 'discord.js'; -import { BlitzServer } from '../../constants/servers.js'; - -export default function fullBlitzStarsStats( - server: BlitzServer, - username: string, -) { - return new ButtonBuilder() - .setLabel('View on BlitzStars') - .setURL(`https://www.blitzstars.com/player/${server}/${username}`) - .setStyle(ButtonStyle.Link); -} diff --git a/src/core/discord/generateCustomId.ts b/src/core/discord/generateCustomId.ts deleted file mode 100644 index 380573365..000000000 --- a/src/core/discord/generateCustomId.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { CacheType, ChatInputCommandInteraction } from 'discord.js'; - -export default function generateCustomId( - interaction: ChatInputCommandInteraction, -) { - return `${interaction.commandName}/${ - interaction.options.getSubcommandGroup() ?? '' - }/${interaction.options.getSubcommand() ?? ''}`; -} diff --git a/src/core/discord/cleanTable.ts b/src/core/discord/markdownTable.ts similarity index 81% rename from src/core/discord/cleanTable.ts rename to src/core/discord/markdownTable.ts index 45961433c..af2f3a475 100644 --- a/src/core/discord/cleanTable.ts +++ b/src/core/discord/markdownTable.ts @@ -1,7 +1,7 @@ export type TableInputEntry = [string, string | number] | []; export type TableInput = TableInputEntry[]; -export default function cleanTable(input: TableInput) { +export default function markdownTable(input: TableInput) { return input .filter((array) => array[1] !== undefined) .map((array) => (array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`)) diff --git a/src/core/discord/noMember.ts b/src/core/discord/noMember.ts deleted file mode 100644 index 6b2071220..000000000 --- a/src/core/discord/noMember.ts +++ /dev/null @@ -1,6 +0,0 @@ -import negativeEmbed from './negativeEmbed.js'; - -export const noMember = negativeEmbed( - 'User of command is not a member', - 'Discord claims that the user of this command does not have an account... strange!', -); diff --git a/src/core/discord/notTrackedByBlitzStars.ts b/src/core/discord/notTrackedByBlitzStars.ts deleted file mode 100644 index 566551cf3..000000000 --- a/src/core/discord/notTrackedByBlitzStars.ts +++ /dev/null @@ -1,6 +0,0 @@ -import negativeEmbed from './negativeEmbed.js'; - -export const notTrackedByBlitzStars = negativeEmbed( - 'No data to display', - 'Player is not tracked by BlitzStars.', -); diff --git a/src/core/discord/supportBlitzStars.ts b/src/core/discord/supportBlitzStars.ts index f7d40c6ee..9953dd818 100644 --- a/src/core/discord/supportBlitzStars.ts +++ b/src/core/discord/supportBlitzStars.ts @@ -1,5 +1,6 @@ import { ButtonBuilder, ButtonStyle } from 'discord.js'; +// TODO: ADD THIS AGAIN IMMEDIATELY export const supportBlitzStars = new ButtonBuilder() .setLabel('Support BlitzStars') .setURL('https://www.blitzstars.com/supporters') diff --git a/src/events/interactionCreate/handlers/chatInputCommand.ts b/src/events/interactionCreate/handlers/chatInputCommand.ts index 0944dbdb5..090af20b7 100644 --- a/src/events/interactionCreate/handlers/chatInputCommand.ts +++ b/src/events/interactionCreate/handlers/chatInputCommand.ts @@ -5,9 +5,9 @@ import { CacheType, ChatInputCommandInteraction, } from 'discord.js'; -import negativeEmbed from '../../../core/discord/negativeEmbed.js'; +import embedNegative from '../../../core/discord/embedNegative.js'; import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js'; -import warningEmbed from '../../../core/discord/warningEmbed.js'; +import embedWarning from '../../../core/discord/embedWarning.js'; import { psa } from '../../../core/node/psa.js'; import { handleError } from '../../error.js'; import { commands } from '../index.js'; @@ -29,7 +29,7 @@ export default async function handleChatInputCommand( if (psa.data) { if (!reply.embeds) reply.embeds = []; - reply.embeds.push(warningEmbed(psa.data.title, psa.data.description)); + reply.embeds.push(embedWarning(psa.data.title, psa.data.description)); } await interaction.editReply(reply); @@ -43,7 +43,7 @@ export default async function handleChatInputCommand( await interaction.editReply({ embeds: [ - negativeEmbed( + embedNegative( (error as Error).message, `${(error as Error).cause ?? 'No further information is available.'}`, ),