2023-04-26 00:02:10 +00:00
|
|
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
2023-05-06 17:45:43 +00:00
|
|
|
import markdownEscape from 'markdown-escape';
|
2023-04-20 13:43:35 +00:00
|
|
|
import discord from '../../discord.json' assert { type: 'json' };
|
2023-04-22 01:18:07 +00:00
|
|
|
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
2023-05-14 17:13:42 +00:00
|
|
|
import usernameAutocomplete from '../core/autocomplete/username.js';
|
2023-05-16 02:02:50 +00:00
|
|
|
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
2023-05-13 22:01:58 +00:00
|
|
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
|
|
|
|
import cmdName from '../core/interaction/cmdName.js';
|
2023-05-14 17:13:42 +00:00
|
|
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
2023-06-12 01:17:26 +00:00
|
|
|
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
2023-05-19 23:50:24 +00:00
|
|
|
import { CommandRegistry } from '../events/interactionCreate.js';
|
2023-05-16 02:12:51 +00:00
|
|
|
import { AccountInfo } from '../types/accountInfo.js';
|
2023-04-27 01:13:50 +00:00
|
|
|
import { PlayerClanData } from '../types/playerClanData.js';
|
2023-04-19 00:26:51 +00:00
|
|
|
|
2023-04-26 00:02:10 +00:00
|
|
|
export default {
|
|
|
|
|
inProduction: true,
|
2023-06-06 16:53:13 +00:00
|
|
|
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()
|
2023-05-13 01:27:12 +00:00
|
|
|
.setName(cmdName('verify'))
|
2023-04-28 13:56:08 +00:00
|
|
|
.setDescription("Set's the user's username to their in-game name")
|
2023-06-03 18:05:09 +00:00
|
|
|
.addStringOption((option) => addUsernameOption(option).setRequired(true)),
|
2023-04-19 01:26:35 +00:00
|
|
|
|
2023-05-08 01:45:57 +00:00
|
|
|
async execute(interaction) {
|
2023-06-03 18:05:09 +00:00
|
|
|
const blitzAccount = await getBlitzAccount(interaction);
|
2023-05-16 02:12:51 +00:00
|
|
|
const { id, server } = blitzAccount;
|
|
|
|
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
2023-06-12 01:17:26 +00:00
|
|
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
2023-05-16 02:12:51 +00:00
|
|
|
);
|
2023-05-08 01:45:57 +00:00
|
|
|
const clanData = await getWargamingResponse<PlayerClanData>(
|
2023-06-12 01:17:26 +00:00
|
|
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
2023-05-08 01:45:57 +00:00
|
|
|
);
|
2023-05-16 02:12:51 +00:00
|
|
|
const clan = clanData[id]?.clan;
|
2023-05-08 01:45:57 +00:00
|
|
|
const clanTag = clan ? ` [${clan!.tag}]` : '';
|
2023-05-06 22:39:51 +00:00
|
|
|
|
2023-05-08 01:45:57 +00:00
|
|
|
if (!interaction.guild?.members.me?.permissions.has('ManageNicknames')) {
|
|
|
|
|
interaction.editReply({
|
|
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(NEGATIVE_COLOR)
|
|
|
|
|
.setTitle(
|
|
|
|
|
`${markdownEscape(interaction.user.username)} failed to verify`,
|
|
|
|
|
)
|
|
|
|
|
.setDescription(
|
|
|
|
|
"I don't have the permission to change your nickname.",
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
2023-05-06 22:39:51 +00:00
|
|
|
|
2023-05-08 01:45:57 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (interaction.member) {
|
|
|
|
|
const member = interaction.guild?.members.cache.get(
|
|
|
|
|
interaction.member?.user.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (member) {
|
|
|
|
|
try {
|
2023-05-16 02:12:51 +00:00
|
|
|
await member.setNickname(`${accountInfo[id].nickname}${clanTag}`);
|
2023-05-08 01:45:57 +00:00
|
|
|
|
2023-05-19 23:36:02 +00:00
|
|
|
if (interaction.guildId === discord.sklld_guild_id) {
|
2023-05-08 01:45:57 +00:00
|
|
|
if (
|
|
|
|
|
!interaction.guild?.members.me?.permissions.has('ManageRoles')
|
|
|
|
|
) {
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(NEGATIVE_COLOR)
|
|
|
|
|
.setTitle(
|
|
|
|
|
`${markdownEscape(
|
|
|
|
|
interaction.user.username,
|
|
|
|
|
)} failed to verify`,
|
|
|
|
|
)
|
|
|
|
|
.setDescription(
|
|
|
|
|
"I don't have the permission to change your manage roles.",
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 23:36:02 +00:00
|
|
|
await member.roles.remove(discord.sklld_verify_role);
|
|
|
|
|
await member.roles.add(discord.sklld_peasant_role);
|
2023-05-08 01:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(POSITIVE_COLOR)
|
|
|
|
|
.setTitle(`${interaction.user.username} is verified`)
|
|
|
|
|
.setDescription(
|
2023-05-10 20:00:30 +00:00
|
|
|
`The user is now verified as ${markdownEscape(
|
2023-05-16 02:12:51 +00:00
|
|
|
accountInfo[id].nickname,
|
2023-05-10 20:00:30 +00:00
|
|
|
)}${markdownEscape(clanTag)}`,
|
2023-05-08 01:45:57 +00:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(NEGATIVE_COLOR)
|
|
|
|
|
.setTitle(`${interaction.user.username} failed to verify`)
|
|
|
|
|
.setDescription(
|
2023-06-03 18:05:09 +00:00
|
|
|
"I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.",
|
2023-05-08 01:45:57 +00:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-26 00:02:10 +00:00
|
|
|
},
|
2023-05-14 17:13:42 +00:00
|
|
|
|
|
|
|
|
autocomplete: usernameAutocomplete,
|
2023-04-26 00:02:10 +00:00
|
|
|
} satisfies CommandRegistry;
|