mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: role and nickname management
This commit is contained in:
1 parent
ce290440c3
commit
67c1a23ef9
4 files changed
+62
-33
No files matched your search
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": ["Abhi", "SKLLD", "wargaming"],
|
"cSpell.words": ["Abhi", "accountinfo", "SKLLD", "wargaming"],
|
||||||
"deno.enable": false,
|
"deno.enable": false,
|
||||||
"deno.unstable": false
|
"deno.unstable": false
|
||||||
}
|
}
|
||||||
+60
-28
@@ -1,43 +1,75 @@
|
|||||||
import {
|
import {
|
||||||
CommandInteraction,
|
CacheType,
|
||||||
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import config from '../../config.json' assert { type: 'json' };
|
import config from '../../config.json' assert { type: 'json' };
|
||||||
import getBlitzURL from '../utilities/getBlitzURL.js';
|
|
||||||
|
|
||||||
export async function execute(interaction: CommandInteraction) {
|
const SERVER_NAMES = { com: 'North America', eu: 'Europe', asia: 'Asia' };
|
||||||
//@ts-ignore
|
|
||||||
const ign = interaction.options.getString('ign');
|
export async function execute(
|
||||||
//@ts-ignore
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
const server = interaction.options.getString('server');
|
) {
|
||||||
const blitzURL = getBlitzURL(server);
|
const ign = interaction.options.getString('ign')!;
|
||||||
|
const server = interaction.options.getString('server')!;
|
||||||
|
const serverName = SERVER_NAMES[server as keyof typeof SERVER_NAMES];
|
||||||
const players = (await fetch(
|
const players = (await fetch(
|
||||||
`${blitzURL}account/list/?application_id=${config.wargaming_application_id}&search=${ign}`,
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${config.wargaming_application_id}&search=${ign}`,
|
||||||
).then((response) => response.json())) as {
|
).then((response) => response.json())) as {
|
||||||
data: { nickname: string; account_id: number }[];
|
data: { nickname: string; account_id: number }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
if (players.data[0].nickname === ign) {
|
if (players.data[0].nickname === ign) {
|
||||||
// good match
|
// good match
|
||||||
const clan = (await fetch(
|
const clanData = (await fetch(
|
||||||
`${blitzURL}clans/accountinfo/?application_id=${config.wargaming_application_id}&account_id=${players.data[0].account_id}&extra=clan`,
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${config.wargaming_application_id}&account_id=${players.data[0].account_id}&extra=clan`,
|
||||||
).then((response) => response.json())) as {
|
).then((response) => response.json())) as {
|
||||||
data: { [key: number]: { clan: { tag: string } } };
|
data: { [key: number]: { clan: { tag: string } | null } };
|
||||||
};
|
};
|
||||||
|
const clan = clanData.data[players.data[0].account_id].clan;
|
||||||
|
const clanTag = clan === null ? '' : ` [${clan.tag}]`;
|
||||||
|
|
||||||
interaction.reply({
|
if (interaction.member && interaction.guild) {
|
||||||
embeds: [
|
const member = interaction.guild?.members.cache.get(
|
||||||
new EmbedBuilder()
|
interaction.member?.user.id,
|
||||||
.setColor('#82ff29')
|
);
|
||||||
.setTitle(`${interaction.user.username} is verified`)
|
|
||||||
.setDescription(
|
member
|
||||||
`The user is now verified as ${ign} [${
|
?.setNickname(`${ign}${clanTag}`)
|
||||||
clan.data[players.data[0].account_id].clan.tag
|
.then(async () => {
|
||||||
}]`,
|
await member.roles.remove(config.discord_verify_role);
|
||||||
),
|
await member.roles.add(config.discord_peasant_role);
|
||||||
],
|
await interaction.reply({
|
||||||
});
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setColor('#82ff29')
|
||||||
|
.setTitle(`${interaction.user.username} is verified`)
|
||||||
|
.setDescription(`The user is now verified as ${ign}${clanTag}`),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${interaction.user.username} verified as ${ign}${clanTag}`,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(async () => {
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setColor('#ff4747')
|
||||||
|
.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 ${ign}${clanTag}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// no exact match
|
// no exact match
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
@@ -46,7 +78,7 @@ export async function execute(interaction: CommandInteraction) {
|
|||||||
.setColor('#ff4747')
|
.setColor('#ff4747')
|
||||||
.setTitle(`Account not found`)
|
.setTitle(`Account not found`)
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`Are you sure your username is exactly "${ign}" in the ${server} server? I found ${
|
`Are you sure your username is exactly "${ign}" in the ${serverName} server? I found ${
|
||||||
players.data.length < 100 ? players.data.length : 'over 100'
|
players.data.length < 100 ? players.data.length : 'over 100'
|
||||||
} similarly spelled account${
|
} similarly spelled account${
|
||||||
players.data.length !== 1 ? 's' : ''
|
players.data.length !== 1 ? 's' : ''
|
||||||
@@ -66,9 +98,9 @@ export const data = new SlashCommandBuilder()
|
|||||||
.setDescription('The Blitz server you are in')
|
.setDescription('The Blitz server you are in')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
{ name: 'NA', value: 'na' },
|
{ name: SERVER_NAMES.com, value: 'com' },
|
||||||
{ name: 'EU', value: 'eu' },
|
{ name: SERVER_NAMES.eu, value: 'eu' },
|
||||||
{ name: 'ASIA', value: 'asia' },
|
{ name: SERVER_NAMES.asia, value: 'asia' },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ client.on('interactionCreate', async (interaction: Interaction) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction);
|
command.execute(interaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (interaction.replied || interaction.deferred) {
|
if (interaction.replied || interaction.deferred) {
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
export default function getBlitzURL(server: string) {
|
|
||||||
return `https://api.wotblitz.${server === 'na' ? 'com' : server}/wotb/`;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user