feat: easier /link command

This commit is contained in:
TrèsAbhi committed 2024-01-19 20:53:27 -06:00
1 parent ae07b8de4c
commit 0480445bae
1 file changed
+15 -29
+15 -29
View File
@@ -1,25 +1,21 @@
import { teal } from '@radix-ui/colors'; import { teal } from '@radix-ui/colors';
import { import { GuildMemberRoleManager, SlashCommandBuilder } from 'discord.js';
AttachmentBuilder,
GuildMemberRoleManager,
SlashCommandBuilder,
} from 'discord.js';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import discord from '../../discord.json' assert { type: 'json' }; import discord from '../../discord.json' assert { type: 'json' };
import { Glow } from '../components/AllStatsOverview/components/WN8Display/components/Glow'; import { Glow } from '../components/AllStatsOverview/components/WN8Display/components/Glow';
import Wrapper from '../components/Wrapper'; 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 { getAccountInfo } from '../core/blitz/getAccountInfo';
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo'; import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
import { linkBlitzAndDiscord } from '../core/blitzkrieg/discordBlitz'; import { linkBlitzAndDiscord } from '../core/blitzkrieg/discordBlitz';
import addUsernameChoices from '../core/discord/addUsernameChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteUsername from '../core/discord/autocompleteUsername'; import autocompleteUsername from '../core/discord/autocompleteUsername';
import embedInfo from '../core/discord/embedInfo';
import embedNegative from '../core/discord/embedNegative'; import embedNegative from '../core/discord/embedNegative';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
import { CommandRegistry } from '../events/interactionCreate'; import { CommandRegistry } from '../events/interactionCreate';
import { theme } from '../stitches.config'; import { theme } from '../stitches.config';
const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
export const verifyCommand: CommandRegistry = { export const verifyCommand: CommandRegistry = {
inProduction: true, inProduction: true,
inPublic: true, inPublic: true,
@@ -30,18 +26,12 @@ export const verifyCommand: CommandRegistry = {
.addStringOption((option) => addUsernameChoices(option).setRequired(true)), .addStringOption((option) => addUsernameChoices(option).setRequired(true)),
async handler(interaction) { async handler(interaction) {
const username = interaction.options.getString('username', true); const { id, region } = await resolvePlayerFromCommand(interaction);
if (serverAndIdPattern.test(username)) {
const [region, idString] = username.split('/');
const id = parseInt(idString);
const discordId = parseInt(interaction.user.id); const discordId = parseInt(interaction.user.id);
const accountInfo = await getAccountInfo(region as Region, id); const accountInfo = await getAccountInfo(region, id);
const clanAccountInfo = await getClanAccountInfo(region as Region, id, [ const clanAccountInfo = await getClanAccountInfo(region, id, ['clan']);
'clan',
]);
await linkBlitzAndDiscord(discordId, region as Region, id); await linkBlitzAndDiscord(discordId, region, id);
if (interaction.guildId === discord.sklld_guild_id) { if (interaction.guildId === discord.sklld_guild_id) {
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) { if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
@@ -59,7 +49,7 @@ export const verifyCommand: CommandRegistry = {
); );
} }
return ( return [
<Wrapper fat> <Wrapper fat>
<div <div
style={{ style={{
@@ -198,7 +188,7 @@ export const verifyCommand: CommandRegistry = {
{clanAccountInfo?.clan {clanAccountInfo?.clan
? `[${clanAccountInfo?.clan?.tag}] - ` ? `[${clanAccountInfo?.clan?.tag}] - `
: ''} : ''}
{REGION_NAMES_SHORT[region as Region]} {REGION_NAMES_SHORT[region]}
</span> </span>
</div> </div>
</div> </div>
@@ -206,17 +196,13 @@ export const verifyCommand: CommandRegistry = {
<Glow color={teal.teal9} rotation={-90} /> <Glow color={teal.teal9} rotation={-90} />
</div> </div>
</Wrapper> </Wrapper>,
);
} else { embedInfo(
return [ 'Incorrect account?',
embedNegative( 'Use the command again and select a username from the search results.',
'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, autocomplete: autocompleteUsername,