mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +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 {
|
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,54 +69,76 @@ 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.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) {
|
console.warn(
|
||||||
if (
|
`${interaction.user.username} failed to verify because of no manage roles permission.`,
|
||||||
!interaction.guild.members.me.permissions.has('ManageRoles')
|
);
|
||||||
) {
|
|
||||||
|
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({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setColor(NEGATIVE_COLOR)
|
.setColor(NEGATIVE_COLOR)
|
||||||
.setTitle(
|
.setTitle(
|
||||||
`${markdownEscape(
|
`${interaction.user.username} failed to verify`,
|
||||||
interaction.user.username,
|
|
||||||
)} failed to verify`,
|
|
||||||
)
|
)
|
||||||
.setDescription(
|
.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(
|
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