2023-06-16 02:01:06 +00:00
|
|
|
import { 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-07-11 19:54:57 +00:00
|
|
|
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
|
|
|
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
|
|
|
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
|
|
|
|
import embedNegative from '../core/discord/embedNegative';
|
|
|
|
|
import embedPositive from '../core/discord/embedPositive';
|
|
|
|
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
2023-07-16 18:26:33 +00:00
|
|
|
import { secrets } from '../core/node/secrets';
|
2023-07-11 19:54:57 +00:00
|
|
|
import { CommandRegistry } from '../events/interactionCreate';
|
|
|
|
|
import { AccountInfo } from '../types/accountInfo';
|
|
|
|
|
import { PlayerClanData } from '../types/playerClanData';
|
2023-04-19 00:26:51 +00:00
|
|
|
|
2023-07-05 01:15:18 +00:00
|
|
|
export const verifyCommand: CommandRegistry = {
|
2023-04-26 00:02:10 +00:00
|
|
|
inProduction: true,
|
2023-08-04 18:24:20 +00:00
|
|
|
inDevelopment: true,
|
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-06-21 02:01:12 +00:00
|
|
|
.setName('verify')
|
2023-04-28 13:56:08 +00:00
|
|
|
.setDescription("Set's the user's username to their in-game name")
|
2023-06-27 02:22:28 +00:00
|
|
|
.addStringOption((option) => addUsernameChoices(option).setRequired(true)),
|
2023-04-19 01:26:35 +00:00
|
|
|
|
2023-06-27 01:43:30 +00:00
|
|
|
async handler(interaction) {
|
2023-06-27 02:07:14 +00:00
|
|
|
const blitzAccount = await resolvePlayerFromCommand(interaction);
|
2023-07-15 18:44:20 +00:00
|
|
|
const { id, region: server } = blitzAccount;
|
2023-05-16 02:12:51 +00:00
|
|
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
2023-07-16 18:26:33 +00:00
|
|
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.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-07-16 18:26:33 +00:00
|
|
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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-06-16 02:01:06 +00:00
|
|
|
const member =
|
|
|
|
|
interaction.member &&
|
|
|
|
|
interaction.guild?.members.cache.get(interaction.member?.user.id);
|
2023-05-06 22:39:51 +00:00
|
|
|
|
2023-05-08 01:45:57 +00:00
|
|
|
if (!interaction.guild?.members.me?.permissions.has('ManageNicknames')) {
|
2023-06-27 02:22:28 +00:00
|
|
|
return embedNegative(
|
2023-06-16 02:01:06 +00:00
|
|
|
`${markdownEscape(interaction.user.username)} failed to verify`,
|
|
|
|
|
"I don't have the permission to change your nickname.",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (!interaction.member || !member) {
|
2023-06-27 02:22:28 +00:00
|
|
|
return embedNegative(
|
2023-06-16 02:01:06 +00:00
|
|
|
`${interaction.user.username} is not in this server`,
|
|
|
|
|
"I couldn't find this person in this server. Did they leave?",
|
|
|
|
|
);
|
2023-05-08 01:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-16 02:01:06 +00:00
|
|
|
try {
|
|
|
|
|
await member.setNickname(`${accountInfo[id].nickname}${clanTag}`);
|
2023-05-08 01:45:57 +00:00
|
|
|
|
2023-06-16 02:01:06 +00:00
|
|
|
if (interaction.guildId === discord.sklld_guild_id) {
|
|
|
|
|
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
|
2023-06-27 02:22:28 +00:00
|
|
|
return embedNegative(
|
2023-06-16 02:01:06 +00:00
|
|
|
`${markdownEscape(interaction.user.username)} failed to verify`,
|
|
|
|
|
"I don't have the permission to change your manage roles.",
|
|
|
|
|
);
|
2023-05-08 01:45:57 +00:00
|
|
|
}
|
2023-06-16 02:01:06 +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
|
|
|
}
|
2023-06-16 02:01:06 +00:00
|
|
|
|
2023-06-27 02:22:28 +00:00
|
|
|
return embedPositive(
|
2023-06-16 02:01:06 +00:00
|
|
|
`${interaction.user.username} is verified`,
|
|
|
|
|
`The user is now verified as ${markdownEscape(
|
|
|
|
|
accountInfo[id].nickname,
|
|
|
|
|
)}${markdownEscape(clanTag)}`,
|
|
|
|
|
);
|
|
|
|
|
} catch (error) {
|
2023-06-27 02:22:28 +00:00
|
|
|
return embedNegative(
|
2023-06-16 02:01:06 +00:00
|
|
|
`${interaction.user.username} failed to verify`,
|
|
|
|
|
"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
|
|
|
|
2023-06-27 02:22:28 +00:00
|
|
|
autocomplete: autocompleteUsername,
|
2023-07-05 01:15:18 +00:00
|
|
|
};
|