feat: safer verify command

This commit is contained in:
TresAbhi committed 2023-05-06 23:07:28 +00:00
1 parent c0dd0ed82c
commit 33703996b1
1 file changed
+29 -5
+29 -5
View File
@@ -13,7 +13,7 @@ import getWargamingResponse from '../utilities/getWargamingResponse.js';
export default { export default {
inProduction: true, inProduction: true,
inDevelopment: false, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
@@ -23,11 +23,13 @@ export default {
.addStringOption(addIGNOption), .addStringOption(addIGNOption),
execute(interaction) { execute(interaction) {
const name = interaction.options.getString('name')!; let name = interaction.options.getString('name')!;
const server = interaction.options.getString('server') as BlitzServer; const server = interaction.options.getString('server') as BlitzServer;
const command = `verify ${server} ${name}`; const command = `verify ${server} ${name}`;
getBlitzAccount(interaction, command, name, server, async (account) => { getBlitzAccount(interaction, command, name, server, async (account) => {
name = account.nickname;
getWargamingResponse<PlayerClanData>( getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`, `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`,
interaction, interaction,
@@ -67,11 +69,14 @@ export default {
); );
if (member) { if (member) {
await member?.setNickname(`${name}${clanTag}`); await member
?.setNickname(`${name}${clanTag}`)
.then(async () => {
if (interaction.guildId === discord.guild_id) { if (interaction.guildId === discord.guild_id) {
if ( if (
!interaction.guild.members.me.permissions.has('ManageRoles') !interaction.guild?.members.me?.permissions.has(
'ManageRoles',
)
) { ) {
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
@@ -115,6 +120,25 @@ export default {
console.log( console.log(
`${interaction.user.username} verified as ${name}${clanTag}`, `${interaction.user.username} verified as ${name}${clanTag}`,
); );
})
.catch(async () => {
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
.setTitle(
`${interaction.user.username} failed to verify`,
)
.setDescription(
"I can't change your nickname because you have higher permissions than me.",
),
],
});
console.warn(
'Failed to verify because of higher permissions.',
);
});
} }
} }
}, },