feat: heavy usage of await

This commit is contained in:
TresAbhi committed 2023-05-08 01:45:59 +00:00
1 parent 18360dfe8f
commit 91af52b4b8
14 files changed
+569 -666

No files matched your search

+102 -119
View File
@@ -13,7 +13,7 @@ import getWargamingResponse from '../utilities/getWargamingResponse.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
@@ -22,131 +22,114 @@ export default {
.addStringOption((option) => addServerChoices(option).setRequired(true))
.addStringOption((Option) => addIGNOption(Option).setRequired(true)),
execute(interaction) {
async execute(interaction) {
let name = interaction.options.getString('name')!;
const server = interaction.options.getString('server') as BlitzServer;
const command = `verify ${server} ${name}`;
const account = await getBlitzAccount(interaction, name, server);
getBlitzAccount(interaction, command, name, server, async (account) => {
name = account.nickname;
if (!account) return;
getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`,
interaction,
command,
async (clanData) => {
const clan = clanData[account.account_id].clan;
const clanTag = clan === null ? '' : ` [${clan!.tag}]`;
name = account.nickname;
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.",
),
],
});
const clanData = await getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`,
);
const clan = clanData[account.account_id]?.clan;
const clanTag = clan ? ` [${clan!.tag}]` : '';
console.warn(
`${interaction.user.username} failed to verify because of no nickname permission.`,
);
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.",
),
],
});
return;
}
if (interaction.member) {
const member = interaction.guild?.members.cache.get(
interaction.member?.user.id,
);
if (member) {
await member
?.setNickname(
`${name} (${BLITZ_SERVERS_SHORT[server]})${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.",
),
],
});
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,
)} (${BLITZ_SERVERS_SHORT[server]})${markdownEscape(
clanTag,
)}`,
),
],
});
console.log(
`${interaction.user.username} verified as ${name} (${BLITZ_SERVERS_SHORT[server]})${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.',
);
});
}
}
},
console.warn(
`${interaction.user.username} failed to verify because of no nickname permission.`,
);
});
return;
}
if (interaction.member) {
const member = interaction.guild?.members.cache.get(
interaction.member?.user.id,
);
if (member) {
try {
await member.setNickname(
`${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`,
);
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.",
),
],
});
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)} (${
BLITZ_SERVERS_SHORT[server]
})${markdownEscape(clanTag)}`,
),
],
});
console.log(
`${interaction.user.username} verified as ${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`,
);
} catch (error) {
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.');
}
}
}
},
} satisfies CommandRegistry;