diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 378044914..2c027d95e 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -2,10 +2,10 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; +import { BlitzServer } from '../constants/servers.js'; import addIGNOption from '../utilities/addIGNOption.js'; import addServerChoices from '../utilities/addServerChoices.js'; import blitzLinks from '../utilities/blitzLinks.js'; -import extractUser from '../utilities/extractUser.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js'; import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js'; @@ -38,13 +38,10 @@ export default { async execute(interaction) { const clan = interaction.options.getString('clan') as keyof typeof CLANS; - - const extractedUser = await extractUser(interaction); - if (!extractedUser) return; - - const { name, server } = extractedUser; - + const name = interaction.options.getString('name')!; + const server = interaction.options.getString('server') as BlitzServer; const blitzAccount = await getBlitzAccount(interaction, name, server); + if (!blitzAccount) return; const blitzStarsAccount = await getBlitzStarsAccount( diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 4e9e33a72..52160191b 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -16,8 +16,8 @@ export default { command: new SlashCommandBuilder() .setName('searchplayers') .setDescription('Search players in a Blitz server') - .addStringOption((option) => addServerChoices(option).setRequired(true)) - .addStringOption((option) => addIGNOption(option).setRequired(true)) + .addStringOption(addServerChoices) + .addStringOption(addIGNOption) .addIntegerOption((option) => option .setName('limit') diff --git a/src/commands/stats.ts b/src/commands/stats.ts index b9efacf17..73379000e 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -2,13 +2,13 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { SKILLED_COLOR } from '../constants/colors.js'; +import { BlitzServer } from '../constants/servers.js'; import { AccountInfo, AllStats } from '../types/accountInfo.js'; import { PeriodStatistics, PlayerStatistics } from '../types/statistics.js'; import addIGNOption from '../utilities/addIGNOption.js'; import addServerChoices from '../utilities/addServerChoices.js'; import { args } from '../utilities/args.js'; import blitzLinks from '../utilities/blitzLinks.js'; -import extractUser from '../utilities/extractUser.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js'; import getWargamingResponse from '../utilities/getWargamingResponse.js'; @@ -41,14 +41,10 @@ export default { async execute(interaction) { const period = interaction.options.getString('period') as Period; - - const extractedUser = await extractUser(interaction); - if (!extractedUser) return; - - const { name, server } = extractedUser; - const command = `stats ${server} ${name} ${period}`; - + const name = interaction.options.getString('name')!; + const server = interaction.options.getString('server') as BlitzServer; const blitzAccount = await getBlitzAccount(interaction, name, server); + if (!blitzAccount) return; const blitzStarsAccount = (await getBlitzStarsAccount( diff --git a/src/commands/tanks.ts b/src/commands/tanks.ts index ca02b947d..11c565717 100644 --- a/src/commands/tanks.ts +++ b/src/commands/tanks.ts @@ -2,11 +2,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { SKILLED_COLOR } from '../constants/colors.js'; +import { BlitzServer } from '../constants/servers.js'; import { TanksStats } from '../types/tanksStats.js'; import addIGNOption from '../utilities/addIGNOption.js'; import addServerChoices from '../utilities/addServerChoices.js'; import { args } from '../utilities/args.js'; -import extractUser from '../utilities/extractUser.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; import getWargamingResponse from '../utilities/getWargamingResponse.js'; import { TANK_TYPE_EMOJIS, tankopedia } from '../utilities/tankopedia.js'; @@ -53,12 +53,10 @@ export default { async execute(interaction) { const tier = interaction.options.getInteger('tier')!; - const extractedUser = await extractUser(interaction); - if (!extractedUser) return; - - const { name, server } = extractedUser; - + const name = interaction.options.getString('name')!; + const server = interaction.options.getString('server') as BlitzServer; const account = await getBlitzAccount(interaction, name, server); + if (!account) return; const tankStats = await getWargamingResponse( diff --git a/src/commands/verify.ts b/src/commands/verify.ts index f1175eaf7..d4766c425 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -3,7 +3,7 @@ import markdownEscape from 'markdown-escape'; import discord from '../../discord.json' assert { type: 'json' }; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; -import { BLITZ_SERVERS_SHORT, BlitzServer } from '../constants/servers.js'; +import { BlitzServer } from '../constants/servers.js'; import { PlayerClanData } from '../types/playerClanData.js'; import addIGNOption from '../utilities/addIGNOption.js'; import addServerChoices from '../utilities/addServerChoices.js'; @@ -19,8 +19,8 @@ export default { command: new SlashCommandBuilder() .setName('verify') .setDescription("Set's the user's username to their in-game name") - .addStringOption((option) => addServerChoices(option).setRequired(true)) - .addStringOption((Option) => addIGNOption(Option).setRequired(true)), + .addStringOption(addServerChoices) + .addStringOption(addIGNOption), async execute(interaction) { let name = interaction.options.getString('name')!; @@ -65,9 +65,7 @@ export default { if (member) { try { - await member.setNickname( - `${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`, - ); + await member.setNickname(`${name}${clanTag}`); if (interaction.guildId === discord.guild_id) { if ( @@ -105,15 +103,15 @@ export default { .setColor(POSITIVE_COLOR) .setTitle(`${interaction.user.username} is verified`) .setDescription( - `The user is now verified as ${markdownEscape(name)} (${ - BLITZ_SERVERS_SHORT[server] - })${markdownEscape(clanTag)}`, + `The user is now verified as ${markdownEscape( + name, + )}${markdownEscape(clanTag)}`, ), ], }); console.log( - `${interaction.user.username} verified as ${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`, + `${interaction.user.username} verified as ${name}${clanTag}`, ); } catch (error) { await interaction.editReply({ diff --git a/src/utilities/addIGNOption.ts b/src/utilities/addIGNOption.ts index 17cf4bdc1..99937265f 100644 --- a/src/utilities/addIGNOption.ts +++ b/src/utilities/addIGNOption.ts @@ -4,5 +4,5 @@ export default function addIGNOption(option: SlashCommandStringOption) { return option .setName('name') .setDescription('The username you use in Blitz') - .setRequired(false); + .setRequired(true); } diff --git a/src/utilities/addServerChoices.ts b/src/utilities/addServerChoices.ts index 3f0125b8c..ee94f20ac 100644 --- a/src/utilities/addServerChoices.ts +++ b/src/utilities/addServerChoices.ts @@ -10,5 +10,5 @@ export default function addServerChoices(option: SlashCommandStringOption) { { name: BLITZ_SERVERS.eu, value: 'eu' }, { name: BLITZ_SERVERS.asia, value: 'asia' }, ) - .setRequired(false); + .setRequired(true); } diff --git a/src/utilities/extractUser.ts b/src/utilities/extractUser.ts deleted file mode 100644 index b278178a6..000000000 --- a/src/utilities/extractUser.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { CacheType, ChatInputCommandInteraction } from 'discord.js'; -import { - BLITZ_SERVERS_SHORT, - BLITZ_SERVERS_SHORT_INVERSE, - BlitzServer, -} from '../constants/servers.js'; -import { badNicknameFormat } from '../embeds/badNicknameFormat.js'; -import { noMember } from '../embeds/noMember.js'; -import errorEmbed from './errorEmbed.js'; - -const nicknamePattern = /(.+) \((.+)\)/; - -const VALID_BLITZ_SERVERS_SHORT = Object.keys(BLITZ_SERVERS_SHORT_INVERSE); - -export default async function extractUser( - interaction: ChatInputCommandInteraction, -) { - if (!interaction.member) { - await interaction.editReply({ embeds: [noMember] }); - return; - } - - const member = interaction.guild?.members.cache.get( - interaction.member.user.id, - ); - const nickname = member?.nickname ?? member?.user.username; - if (!nickname) { - await interaction.editReply({ embeds: [noMember] }); - return; - } - - const matches = nickname.match(nicknamePattern); - if (!matches) { - await interaction.editReply({ embeds: [badNicknameFormat] }); - return; - } - - const [, nameMatch, serverMatch] = matches; - const nameArg = interaction.options.getString('name'); - const serverArg = interaction.options.getString( - 'server', - ) as BlitzServer | null; - const name = nameArg ?? nameMatch; - const server = - BLITZ_SERVERS_SHORT[serverArg as keyof typeof BLITZ_SERVERS_SHORT] ?? - serverMatch; - - if (!VALID_BLITZ_SERVERS_SHORT.includes(server)) { - await interaction.editReply({ - embeds: [ - errorEmbed( - 'Invalid server', - `"${server}" is not a valid server. Use the \`/verify\` command to setup your nickname correctly or manually provide me with the server in the command.`, - ), - ], - }); - return; - } - - return { - name, - server: BLITZ_SERVERS_SHORT_INVERSE[ - server as keyof typeof BLITZ_SERVERS_SHORT_INVERSE - ] as BlitzServer, - }; -}