import { teal } from '@radix-ui/colors'; 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 } 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'; 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 { id, region } = await resolvePlayerFromCommand(interaction); const discordId = parseInt(interaction.user.id); const accountInfo = await getAccountInfo(region, id); const clanAccountInfo = await getClanAccountInfo(region, id, ['clan']); await linkBlitzAndDiscord(discordId, 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[region]}
, embedInfo( 'Incorrect account?', 'Use the command again and select a username from the search results.', ), ]; }, autocomplete: autocompleteUsername, };