2023-04-26 00:02:10 +00:00
|
|
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
2023-04-20 13:43:35 +00:00
|
|
|
import discord from '../../discord.json' assert { type: 'json' };
|
2023-04-26 00:02:10 +00:00
|
|
|
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
2023-04-22 01:18:07 +00:00
|
|
|
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
2023-05-02 23:01:54 +00:00
|
|
|
import { BlitzServer } from '../constants/servers.js';
|
2023-04-27 01:13:50 +00:00
|
|
|
import { PlayerClanData } from '../types/playerClanData.js';
|
2023-05-02 23:01:54 +00:00
|
|
|
import addIGNOption from '../utilities/addIGNOption.js';
|
|
|
|
|
import addServerChoices from '../utilities/addServerChoices.js';
|
2023-04-28 13:42:42 +00:00
|
|
|
import { args } from '../utilities/args.js';
|
2023-04-22 01:18:07 +00:00
|
|
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
2023-04-27 00:21:39 +00:00
|
|
|
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
2023-04-19 00:26:51 +00:00
|
|
|
|
2023-04-26 00:02:10 +00:00
|
|
|
export default {
|
|
|
|
|
inProduction: true,
|
|
|
|
|
inDevelopment: false,
|
2023-04-28 13:56:08 +00:00
|
|
|
inPublic: true,
|
2023-04-19 00:58:29 +00:00
|
|
|
|
2023-04-26 00:02:10 +00:00
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
|
.setName('verify')
|
2023-04-28 13:56:08 +00:00
|
|
|
.setDescription("Set's the user's username to their in-game name")
|
2023-05-02 23:01:54 +00:00
|
|
|
.addStringOption(addServerChoices)
|
|
|
|
|
.addStringOption(addIGNOption),
|
2023-04-19 01:26:35 +00:00
|
|
|
|
2023-04-26 00:02:10 +00:00
|
|
|
execute(interaction) {
|
2023-04-26 01:23:07 +00:00
|
|
|
const name = interaction.options.getString('name')!;
|
2023-04-26 00:02:10 +00:00
|
|
|
const server = interaction.options.getString('server') as BlitzServer;
|
2023-04-19 15:58:32 +00:00
|
|
|
|
2023-04-26 01:23:07 +00:00
|
|
|
getBlitzAccount(interaction, name, server, async (account) => {
|
2023-04-27 00:21:39 +00:00
|
|
|
getWargamingResponse<PlayerClanData>(
|
2023-04-28 13:42:42 +00:00
|
|
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`,
|
2023-04-27 00:21:39 +00:00
|
|
|
interaction,
|
|
|
|
|
async (clanData) => {
|
|
|
|
|
const clan = clanData[account.account_id].clan;
|
|
|
|
|
const clanTag = clan === null ? '' : ` [${clan!.tag}]`;
|
2023-04-26 00:02:10 +00:00
|
|
|
|
2023-04-27 00:21:39 +00:00
|
|
|
if (interaction.member && interaction.guild) {
|
|
|
|
|
const member = interaction.guild?.members.cache.get(
|
|
|
|
|
interaction.member?.user.id,
|
2023-04-26 00:02:10 +00:00
|
|
|
);
|
|
|
|
|
|
2023-04-27 00:21:39 +00:00
|
|
|
member
|
|
|
|
|
?.setNickname(`${name}${clanTag}`)
|
|
|
|
|
.then(async () => {
|
2023-04-28 13:56:08 +00:00
|
|
|
if (interaction.guildId === discord.guild_id) {
|
|
|
|
|
await member.roles.remove(discord.verify_role);
|
|
|
|
|
await member.roles.add(discord.peasant_role);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 01:13:50 +00:00
|
|
|
await interaction.editReply({
|
2023-04-27 00:21:39 +00:00
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(POSITIVE_COLOR)
|
|
|
|
|
.setTitle(`${interaction.user.username} is verified`)
|
|
|
|
|
.setDescription(
|
|
|
|
|
`The user is now verified as ${name}${clanTag}`,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
`${interaction.user.username} verified as ${name}${clanTag}`,
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.catch(async () => {
|
2023-04-28 20:37:41 -05:00
|
|
|
await interaction.editReply({
|
2023-04-27 00:21:39 +00:00
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(NEGATIVE_COLOR)
|
|
|
|
|
.setTitle(`${interaction.user.username} failed to verify`)
|
|
|
|
|
.setDescription(
|
|
|
|
|
'I may not have the permission to change your nickname.',
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.warn(
|
|
|
|
|
`${interaction.user.username} failed to verify as ${name}${clanTag}`,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-04-26 00:02:10 +00:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
} satisfies CommandRegistry;
|