Files
blitzkit/packages/bot/src/commands/link.tsx
T

196 lines
6.3 KiB
TypeScript
Raw Normal View History

2024-09-08 10:42:34 -05:00
import {
getAccountInfo,
getClanAccountInfo,
linkBlitzAndDiscord,
} from '@blitzkit/core';
2023-10-10 21:20:01 -05:00
import { teal } from '@radix-ui/colors';
2024-03-20 20:40:01 -05:00
import { Glow } from '../components/AllStatsOverview/components/HeroStat/components/Glow';
2024-09-08 10:11:24 -05:00
import { CommandWrapper } from '../components/CommandWrapper';
import { addUsernameChoices } from '../core/discord/addUsernameChoices';
import { autocompleteUsername } from '../core/discord/autocompleteUsername';
2024-03-07 18:27:05 -06:00
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
2024-09-08 10:11:24 -05:00
import { embedInfo } from '../core/discord/embedInfo';
import { resolvePlayerFromCommand } from '../core/discord/resolvePlayerFromCommand';
2024-03-07 18:27:05 -06:00
import { translator } from '../core/localization/translator';
2023-10-10 21:20:01 -05:00
import { CommandRegistry } from '../events/interactionCreate';
import { theme } from '../stitches.config';
2024-03-06 15:34:10 -06:00
export const verifyCommand = new Promise<CommandRegistry>((resolve) => {
resolve({
2024-03-07 18:27:05 -06:00
command: createLocalizedCommand('link').addStringOption((option) =>
addUsernameChoices(option).setRequired(true),
),
2023-10-10 21:20:01 -05:00
2024-03-06 15:34:10 -06:00
async handler(interaction) {
2024-03-07 18:27:05 -06:00
const { t, translate } = translator(interaction.locale);
2024-03-06 15:34:10 -06:00
const { id, region } = await resolvePlayerFromCommand(interaction);
2024-04-03 15:19:48 -05:00
const discordId = BigInt(interaction.user.id);
2024-03-06 15:34:10 -06:00
const accountInfo = await getAccountInfo(region, id);
const clanAccountInfo = await getClanAccountInfo(region, id, ['clan']);
2023-10-10 21:20:01 -05:00
2024-04-03 15:19:48 -05:00
await linkBlitzAndDiscord(discordId, id);
2023-10-10 21:20:01 -05:00
2024-03-06 15:34:10 -06:00
return [
<CommandWrapper fat>
2023-10-10 21:20:01 -05:00
<div
style={{
display: 'flex',
alignItems: 'center',
2024-03-06 15:34:10 -06:00
justifyContent: 'space-between',
2023-10-10 21:20:01 -05:00
}}
>
2024-03-06 15:34:10 -06:00
<Glow color={teal.teal9} rotation={90} />
2024-01-19 20:53:27 -06:00
<div
style={{
display: 'flex',
2024-03-06 15:34:10 -06:00
flexDirection: 'column',
2024-01-19 20:53:27 -06:00
alignItems: 'center',
justifyContent: 'center',
2024-03-06 15:34:10 -06:00
gap: 16,
2024-01-19 20:53:27 -06:00
}}
>
<div
style={{
display: 'flex',
2024-03-06 15:34:10 -06:00
gap: 8,
alignItems: 'center',
justifyContent: 'center',
2024-01-19 20:53:27 -06:00
}}
>
2023-10-10 21:20:01 -05:00
<img
2024-05-04 16:28:12 -05:00
alt="avatar"
2024-03-06 15:34:10 -06:00
src={
interaction.user.avatarURL({ extension: 'png' }) ??
'https://i.stack.imgur.com/l60Hf.png'
}
2023-10-10 21:20:01 -05:00
style={{
width: 64,
height: 64,
borderRadius: 32,
objectFit: 'cover',
}}
/>
2024-03-06 15:34:10 -06:00
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 4,
}}
>
<span
style={{
fontSize: 32,
color: theme.colors.textHighContrast,
fontWeight: 900,
maxWidth: 240,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
>
{interaction.user.displayName}
</span>
<span
style={{
fontSize: 16,
color: theme.colors.textLowContrast,
}}
>
@{interaction.user.username}
</span>
</div>
</div>
2023-10-10 21:20:01 -05:00
<div
style={{
display: 'flex',
2024-03-06 15:34:10 -06:00
alignItems: 'center',
justifyContent: 'center',
2023-10-10 21:20:01 -05:00
gap: 4,
2024-03-06 15:34:10 -06:00
color: theme.colors.textLowContrast_teal,
2023-10-10 21:20:01 -05:00
}}
>
2024-03-06 15:34:10 -06:00
<img
2024-05-04 16:28:12 -05:00
alt="accounts linked"
2024-03-06 15:34:10 -06:00
src="https://i.imgur.com/jIcRgog.png"
2023-10-10 21:20:01 -05:00
style={{
2024-03-06 15:34:10 -06:00
width: 16,
height: 16,
}}
/>
2024-03-07 18:27:05 -06:00
<span
style={{ fontSize: 16 }}
>{t`bot.commands.link.body.accounts_linked`}</span>
2024-03-06 15:34:10 -06:00
</div>
<div
style={{
display: 'flex',
gap: 8,
alignItems: 'center',
justifyContent: 'center',
}}
>
{clanAccountInfo?.clan ? (
<img
2024-05-04 16:28:12 -05:00
alt="clan emblem"
2024-03-06 15:34:10 -06:00
style={{
width: 64,
height: 64,
borderRadius: 32,
objectFit: 'cover',
}}
src={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanAccountInfo?.clan?.emblem_set_id}.png`}
/>
) : null}
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 4,
2023-10-10 21:20:01 -05:00
}}
>
2024-03-06 15:34:10 -06:00
<span
style={{
fontSize: 32,
color: theme.colors.textHighContrast,
fontWeight: 900,
maxWidth: 240,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
>
{accountInfo.nickname}
</span>
<span
style={{
fontSize: 16,
color: theme.colors.textLowContrast,
}}
>
{clanAccountInfo?.clan
? `[${clanAccountInfo?.clan?.tag}] • `
: ''}
2024-03-07 18:27:05 -06:00
{translate(`common.regions.normal.${region}`)}
2024-03-06 15:34:10 -06:00
</span>
</div>
2023-10-10 21:20:01 -05:00
</div>
</div>
2024-03-06 15:34:10 -06:00
<Glow color={teal.teal9} rotation={-90} />
2023-10-10 21:20:01 -05:00
</div>
2024-03-06 15:34:10 -06:00
</CommandWrapper>,
2024-01-19 20:53:27 -06:00
2024-03-06 15:34:10 -06:00
embedInfo(
2024-03-07 18:27:05 -06:00
t`bot.commands.link.embed.title`,
t`bot.commands.link.embed.description`,
2024-03-06 15:34:10 -06:00
),
];
},
2024-01-19 20:53:27 -06:00
2024-03-06 15:34:10 -06:00
autocomplete: autocompleteUsername,
});
});