feat: better verify messages

This commit is contained in:
TresAbhi committed 2023-04-19 01:26:35 +00:00
1 parent 74c9f1e4da
commit 7e7d4f8771
2 files changed
+35 -54

No files matched your search

+32 -54
View File
@@ -4,73 +4,51 @@ import {
SlashCommandBuilder, SlashCommandBuilder,
} from 'discord.js'; } from 'discord.js';
import config from '../../config.json' assert { type: 'json' }; import config from '../../config.json' assert { type: 'json' };
import getBlitzURL from '../utilities/getBlitzURL.js';
export async function execute(interaction: CommandInteraction) { export async function execute(interaction: CommandInteraction) {
const response = (await fetch( //@ts-ignore
`https://api.wotblitz.${ const ign = interaction.options.getString('ign');
//@ts-ignore //@ts-ignore
interaction.options.getString('server') === 'na' const server = interaction.options.getString('server');
? 'com' const blitzURL = getBlitzURL(server);
: //@ts-ignore const players = (await fetch(
interaction.options.getString('server') `${blitzURL}account/list/?application_id=${config.wargaming_application_id}&search=${ign}`,
}/wotb/account/list/?application_id=${
config.wargaming_application_id
//@ts-ignore
}&search=${interaction.options.getString('ign')}`,
).then((response) => response.json())) as { ).then((response) => response.json())) as {
data: { nickname: string; account_id: number }[]; data: { nickname: string; account_id: number }[];
}; };
if (response.data.length === 1) { if (players.data[0].nickname === ign) {
//@ts-ignore // good match
if (response.data[0].nickname === interaction.options.getString('ign')) { const clan = (await fetch(
interaction.reply({ `${blitzURL}clans/accountinfo/?application_id=${config.wargaming_application_id}&account_id=${players.data[0].account_id}&extra=clan`,
embeds: [ ).then((response) => response.json())) as {
new EmbedBuilder() data: { [key: number]: { clan: { tag: string } } };
.setColor('#82ff29') };
.setTitle(`${interaction.user.username} is verified`)
.setDescription( interaction.reply({
`The user is now verified as ${ embeds: [
//@ts-ignore new EmbedBuilder()
interaction.options.getString('ign') .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
} else { }]`,
interaction.reply({ ),
embeds: [ ],
new EmbedBuilder() });
.setColor('#ff4747')
.setTitle(`Account not found`)
.setDescription(
//@ts-ignore
`No exact matches were found for "${interaction.options.getString(
'ign',
)}" in the ${
//@ts-ignore
interaction.options.getString('server')
} server. Are you sure you have no typos? Capitalization matters.`,
),
],
});
}
} else { } else {
// no exact match
interaction.reply({ interaction.reply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setColor('#ff4747') .setColor('#ff4747')
.setTitle(`Account not found`) .setTitle(`Account not found`)
.setDescription( .setDescription(
//@ts-ignore `Are you sure your username is exactly "${ign}" in the ${server} server? I found ${
`Are you sure your username is "${interaction.options.getString( players.data.length < 100 ? players.data.length : 'over 100'
'ign', } account(s). Try re-running the command. There might be a typo and capitalization matters.`,
)}" in the ${
//@ts-ignore
interaction.options.getString('server')
} server? I found ${
response.data.length < 100 ? response.data.length : 'over 100'
} accounts. Try re-running the command.`,
), ),
], ],
}); });
+3
View File
@@ -0,0 +1,3 @@
export default function getBlitzURL(server: string) {
return `https://api.wotblitz.${server === 'na' ? 'com' : server}/wotb/`;
}