Files
blitzkit/src/commands/verify.ts
T

79 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-04-19 00:58:29 +00:00
import {
CommandInteraction,
EmbedBuilder,
SlashCommandBuilder,
} from 'discord.js';
import config from '../../config.json' assert { type: 'json' };
2023-04-19 01:26:35 +00:00
import getBlitzURL from '../utilities/getBlitzURL.js';
2023-04-19 00:26:51 +00:00
2023-04-19 00:58:29 +00:00
export async function execute(interaction: CommandInteraction) {
2023-04-19 01:26:35 +00:00
//@ts-ignore
const ign = interaction.options.getString('ign');
//@ts-ignore
const server = interaction.options.getString('server');
const blitzURL = getBlitzURL(server);
const players = (await fetch(
`${blitzURL}account/list/?application_id=${config.wargaming_application_id}&search=${ign}`,
2023-04-19 00:58:29 +00:00
).then((response) => response.json())) as {
data: { nickname: string; account_id: number }[];
};
2023-04-19 01:26:35 +00:00
if (players.data[0].nickname === ign) {
// good match
const clan = (await fetch(
`${blitzURL}clans/accountinfo/?application_id=${config.wargaming_application_id}&account_id=${players.data[0].account_id}&extra=clan`,
).then((response) => response.json())) as {
data: { [key: number]: { clan: { tag: string } } };
};
interaction.reply({
embeds: [
new EmbedBuilder()
.setColor('#82ff29')
.setTitle(`${interaction.user.username} is verified`)
.setDescription(
`The user is now verified as ${ign} [${
clan.data[players.data[0].account_id].clan.tag
}]`,
),
],
});
2023-04-19 00:58:29 +00:00
} else {
2023-04-19 01:26:35 +00:00
// no exact match
2023-04-19 00:58:29 +00:00
interaction.reply({
embeds: [
new EmbedBuilder()
.setColor('#ff4747')
.setTitle(`Account not found`)
.setDescription(
2023-04-19 01:26:35 +00:00
`Are you sure your username is exactly "${ign}" in the ${server} server? I found ${
players.data.length < 100 ? players.data.length : 'over 100'
2023-04-19 14:50:31 +00:00
} similarly spelled account${
players.data.length !== 1 ? 's' : ''
}. Try re-running the command. There might be a typo and capitalization matters.`,
2023-04-19 00:58:29 +00:00
),
],
});
}
2023-04-19 00:26:51 +00:00
}
export const data = new SlashCommandBuilder()
.setName('verify')
.setDescription('Verifies the user with Blitz')
.addStringOption((option) =>
option
.setName('server')
.setDescription('The Blitz server you are in')
.setRequired(true)
.addChoices(
{ name: 'NA', value: 'na' },
{ name: 'EU', value: 'eu' },
{ name: 'ASIA', value: 'asia' },
),
)
.addStringOption((option) =>
option
.setName('ign')
.setDescription('The username you use in Blitz')
.setRequired(true),
);