mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: safer verify command
This commit is contained in:
1 parent
c0dd0ed82c
commit
33703996b1
1 file changed
+60
-36
+60
-36
@@ -13,7 +13,7 @@ import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -23,11 +23,13 @@ export default {
|
||||
.addStringOption(addIGNOption),
|
||||
|
||||
execute(interaction) {
|
||||
const name = interaction.options.getString('name')!;
|
||||
let name = interaction.options.getString('name')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const command = `verify ${server} ${name}`;
|
||||
|
||||
getBlitzAccount(interaction, command, name, server, async (account) => {
|
||||
name = account.nickname;
|
||||
|
||||
getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`,
|
||||
interaction,
|
||||
@@ -67,54 +69,76 @@ export default {
|
||||
);
|
||||
|
||||
if (member) {
|
||||
await member?.setNickname(`${name}${clanTag}`);
|
||||
await member
|
||||
?.setNickname(`${name}${clanTag}`)
|
||||
.then(async () => {
|
||||
if (interaction.guildId === discord.guild_id) {
|
||||
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.",
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
if (interaction.guildId === discord.guild_id) {
|
||||
if (
|
||||
!interaction.guild.members.me.permissions.has('ManageRoles')
|
||||
) {
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify because of no manage roles permission.`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await member.roles.remove(discord.verify_role);
|
||||
await member.roles.add(discord.peasant_role);
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(POSITIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} is verified`)
|
||||
.setDescription(
|
||||
`The user is now verified as ${markdownEscape(
|
||||
name,
|
||||
)}${markdownEscape(clanTag)}`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`${interaction.user.username} verified as ${name}${clanTag}`,
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(
|
||||
`${markdownEscape(
|
||||
interaction.user.username,
|
||||
)} failed to verify`,
|
||||
`${interaction.user.username} failed to verify`,
|
||||
)
|
||||
.setDescription(
|
||||
"I don't have the permission to change your manage roles.",
|
||||
"I can't change your nickname because you have higher permissions than me.",
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify because of no manage roles permission.`,
|
||||
'Failed to verify because of higher permissions.',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await member.roles.remove(discord.verify_role);
|
||||
await member.roles.add(discord.peasant_role);
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(POSITIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} is verified`)
|
||||
.setDescription(
|
||||
`The user is now verified as ${markdownEscape(
|
||||
name,
|
||||
)}${markdownEscape(clanTag)}`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`${interaction.user.username} verified as ${name}${clanTag}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user