diff --git a/src/commands/link.tsx b/src/commands/link.tsx index 9db82aaae..1e44da607 100644 --- a/src/commands/link.tsx +++ b/src/commands/link.tsx @@ -1,25 +1,21 @@ import { teal } from '@radix-ui/colors'; -import { - AttachmentBuilder, - GuildMemberRoleManager, - SlashCommandBuilder, -} from 'discord.js'; +import { GuildMemberRoleManager, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import discord from '../../discord.json' assert { type: 'json' }; import { Glow } from '../components/AllStatsOverview/components/WN8Display/components/Glow'; import Wrapper from '../components/Wrapper'; -import { REGION_NAMES_SHORT, Region } from '../constants/regions'; +import { REGION_NAMES_SHORT } from '../constants/regions'; import { getAccountInfo } from '../core/blitz/getAccountInfo'; import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo'; import { linkBlitzAndDiscord } from '../core/blitzkrieg/discordBlitz'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; +import embedInfo from '../core/discord/embedInfo'; import embedNegative from '../core/discord/embedNegative'; +import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; import { CommandRegistry } from '../events/interactionCreate'; import { theme } from '../stitches.config'; -const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/; - export const verifyCommand: CommandRegistry = { inProduction: true, inPublic: true, @@ -30,193 +26,183 @@ export const verifyCommand: CommandRegistry = { .addStringOption((option) => addUsernameChoices(option).setRequired(true)), async handler(interaction) { - const username = interaction.options.getString('username', true); + const { id, region } = await resolvePlayerFromCommand(interaction); + const discordId = parseInt(interaction.user.id); + const accountInfo = await getAccountInfo(region, id); + const clanAccountInfo = await getClanAccountInfo(region, id, ['clan']); - if (serverAndIdPattern.test(username)) { - const [region, idString] = username.split('/'); - const id = parseInt(idString); - const discordId = parseInt(interaction.user.id); - const accountInfo = await getAccountInfo(region as Region, id); - const clanAccountInfo = await getClanAccountInfo(region as Region, id, [ - 'clan', - ]); + await linkBlitzAndDiscord(discordId, region, id); - await linkBlitzAndDiscord(discordId, region as Region, id); - - if (interaction.guildId === discord.sklld_guild_id) { - if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) { - return embedNegative( - `${markdownEscape(interaction.user.username)} failed to verify`, - "I don't have the permission to change your manage roles.", - ); - } - - await (interaction.member!.roles as GuildMemberRoleManager).remove( - discord.sklld_verify_role, - ); - await (interaction.member!.roles as GuildMemberRoleManager).add( - discord.sklld_peasant_role, + if (interaction.guildId === discord.sklld_guild_id) { + if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) { + return embedNegative( + `${markdownEscape(interaction.user.username)} failed to verify`, + "I don't have the permission to change your manage roles.", ); } - return ( - + await (interaction.member!.roles as GuildMemberRoleManager).remove( + discord.sklld_verify_role, + ); + await (interaction.member!.roles as GuildMemberRoleManager).add( + discord.sklld_peasant_role, + ); + } + + return [ + +
+ +
- +
+ + +
+ + {interaction.user.displayName} + + + @{interaction.user.username} + +
+
-
+ /> + Accounts linked +
+ +
+ {clanAccountInfo?.clan ? ( - -
- - {interaction.user.displayName} - - - @{interaction.user.username} - -
-
- + ) : null}
- - Accounts linked -
- -
- {clanAccountInfo?.clan ? ( - - ) : null} -
- - {accountInfo.nickname} - - - {clanAccountInfo?.clan - ? `[${clanAccountInfo?.clan?.tag}] - ` - : ''} - {REGION_NAMES_SHORT[region as Region]} - -
+ {accountInfo.nickname} + + + {clanAccountInfo?.clan + ? `[${clanAccountInfo?.clan?.tag}] - ` + : ''} + {REGION_NAMES_SHORT[region]} +
- -
- - ); - } else { - return [ - embedNegative( - 'Please select from the options', - 'Follow the procedure like the video above. The search results may take a while to show up.', - ), - new AttachmentBuilder('https://i.imgur.com/2p6GFgC.gif'), - ]; - } + + +
+
, + + embedInfo( + 'Incorrect account?', + 'Use the command again and select a username from the search results.', + ), + ]; }, autocomplete: autocompleteUsername,