mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: descrete wargaming response
This commit is contained in:
1 parent
fd1dc40918
commit
d4f676091d
14 files changed
+211
-297
No files matched your search
+49
-47
@@ -1,11 +1,11 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import discord from '../../discord.json' assert { type: 'json' };
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
@@ -38,55 +38,57 @@ export default {
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
|
||||
getBlitzAccount(interaction, name, server, async (account) => {
|
||||
// good match
|
||||
const clanData = (await fetch(
|
||||
getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${process.env.WARGAMING_APPLICATION_ID}&account_id=${account.account_id}&extra=clan`,
|
||||
).then((response) => response.json())) as PlayerClanData;
|
||||
const clan = clanData.data[account.account_id].clan;
|
||||
const clanTag = clan === null ? '' : ` [${clan!.tag}]`;
|
||||
interaction,
|
||||
async (clanData) => {
|
||||
const clan = clanData[account.account_id].clan;
|
||||
const clanTag = clan === null ? '' : ` [${clan!.tag}]`;
|
||||
|
||||
if (interaction.member && interaction.guild) {
|
||||
const member = interaction.guild?.members.cache.get(
|
||||
interaction.member?.user.id,
|
||||
);
|
||||
|
||||
member
|
||||
?.setNickname(`${name}${clanTag}`)
|
||||
.then(async () => {
|
||||
await member.roles.remove(discord.verify_role);
|
||||
await member.roles.add(discord.peasant_role);
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(POSITIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} is verified`)
|
||||
.setDescription(
|
||||
`The user is now verified as ${name}${clanTag}`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`${interaction.user.username} verified as ${name}${clanTag}`,
|
||||
if (interaction.member && interaction.guild) {
|
||||
const member = interaction.guild?.members.cache.get(
|
||||
interaction.member?.user.id,
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} failed to verify`)
|
||||
.setDescription(
|
||||
'I may not have the permission to change your nickname.',
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify as ${name}${clanTag}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
member
|
||||
?.setNickname(`${name}${clanTag}`)
|
||||
.then(async () => {
|
||||
await member.roles.remove(discord.verify_role);
|
||||
await member.roles.add(discord.peasant_role);
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(POSITIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} is verified`)
|
||||
.setDescription(
|
||||
`The user is now verified as ${name}${clanTag}`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`${interaction.user.username} verified as ${name}${clanTag}`,
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} failed to verify`)
|
||||
.setDescription(
|
||||
'I may not have the permission to change your nickname.',
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify as ${name}${clanTag}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
Reference in new issue
Block a user