import { teal } from '@radix-ui/colors'; import { AttachmentBuilder, 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 { 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 embedNegative from '../core/discord/embedNegative'; 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, command: new SlashCommandBuilder() .setName('link') .setDescription('Links your Blitz and Discord account') .addStringOption((option) => addUsernameChoices(option).setRequired(true)), async handler(interaction) { const username = interaction.options.getString('username', true); 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 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, ); } return (
{interaction.user.displayName} @{interaction.user.username}
Accounts linked
{clanAccountInfo?.clan ? ( ) : null}
{accountInfo.nickname} {clanAccountInfo?.clan ? `[${clanAccountInfo?.clan?.tag}] - ` : ''} {REGION_NAMES_SHORT[region as 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'), ]; } }, autocomplete: autocompleteUsername, };