mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +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
@@ -20,7 +20,7 @@ export const CLANS = {
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: false,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
+54
-48
@@ -1,11 +1,11 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import { ClanDetails } from '../types/clanDetails.js';
|
||||
import { ClanInfo } from '../types/clanInfo.js';
|
||||
import { PlayerPersonalData } from '../types/playerPersonalData.js';
|
||||
import getClan from '../utilities/getClan.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
|
||||
const DEFAULT_THRESHOLD = 7;
|
||||
|
||||
@@ -51,56 +51,62 @@ export default {
|
||||
const threshold =
|
||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||
const time = new Date().getTime() / 1000;
|
||||
const clanData = (await (
|
||||
await fetch(
|
||||
`https://api.wotblitz.com/wotb/clans/info/?application_id=${process.env.WARGAMING_APPLICATION_ID}&clan_id=${clan.clan_id}`,
|
||||
)
|
||||
).json()) as ClanDetails;
|
||||
const memberIds = clanData.data[clan.clan_id].members_ids;
|
||||
const playerPersonalData = (await (
|
||||
await fetch(
|
||||
`https://api.wotblitz.com/wotb/account/info/?application_id=${
|
||||
process.env.WARGAMING_APPLICATION_ID
|
||||
}&account_id=${memberIds.join(',')}`,
|
||||
)
|
||||
).json()) as PlayerPersonalData;
|
||||
|
||||
const inactiveInfo = memberIds
|
||||
.map((memberId) => {
|
||||
const member = playerPersonalData.data[memberId];
|
||||
const inactiveDays = (time - member.last_battle_time) / 60 / 60 / 24;
|
||||
getWargamingResponse<ClanInfo>(
|
||||
`https://api.wotblitz.com/wotb/clans/info/?application_id=${process.env.WARGAMING_APPLICATION_ID}&clan_id=${clan.clan_id}`,
|
||||
interaction,
|
||||
async (clanInfo) => {
|
||||
const memberIds = clanInfo[clan.clan_id].members_ids;
|
||||
|
||||
return [member.nickname, inactiveDays] as const;
|
||||
})
|
||||
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.map(([nickname, inactiveDays]) => {
|
||||
const days = Math.floor(inactiveDays);
|
||||
return `**${nickname}**: ${days} day${days === 1 ? '' : 's'}`;
|
||||
});
|
||||
const hasInactiveMembers = inactiveInfo.length > 0;
|
||||
getWargamingResponse<PlayerPersonalData>(
|
||||
`https://api.wotblitz.com/wotb/account/info/?application_id=${
|
||||
process.env.WARGAMING_APPLICATION_ID
|
||||
}&account_id=${memberIds.join(',')}`,
|
||||
interaction,
|
||||
async (playerPersonalData) => {
|
||||
const inactiveInfo = memberIds
|
||||
.map((memberId) => {
|
||||
const member = playerPersonalData[memberId];
|
||||
const inactiveDays =
|
||||
(time - member.last_battle_time) / 60 / 60 / 24;
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(hasInactiveMembers ? NEGATIVE_COLOR : POSITIVE_COLOR)
|
||||
.setTitle(
|
||||
hasInactiveMembers
|
||||
? `${clan.name}'s inactive members`
|
||||
: `No inactive members in ${clan.name}`,
|
||||
)
|
||||
.setDescription(
|
||||
hasInactiveMembers
|
||||
? `Players that exceed the threshold of ${threshold} days:\n\n${inactiveInfo.join(
|
||||
'\n',
|
||||
)}`
|
||||
: `No players exceed the threshold of ${threshold} days.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
return [member.nickname, inactiveDays] as const;
|
||||
})
|
||||
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.map(([nickname, inactiveDays]) => {
|
||||
const days = Math.floor(inactiveDays);
|
||||
return `**${nickname}**: ${days} day${days === 1 ? '' : 's'}`;
|
||||
});
|
||||
const hasInactiveMembers = inactiveInfo.length > 0;
|
||||
|
||||
console.log(
|
||||
`Displaying inactive members in ${clan.name} for ${threshold} days`,
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(
|
||||
hasInactiveMembers ? NEGATIVE_COLOR : POSITIVE_COLOR,
|
||||
)
|
||||
.setTitle(
|
||||
hasInactiveMembers
|
||||
? `${clan.name}'s inactive members`
|
||||
: `No inactive members in ${clan.name}`,
|
||||
)
|
||||
.setDescription(
|
||||
hasInactiveMembers
|
||||
? `Players that exceed the threshold of ${threshold} days:\n\n${inactiveInfo.join(
|
||||
'\n',
|
||||
)}`
|
||||
: `No players exceed the threshold of ${threshold} days.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying inactive members in ${clan.name} for ${threshold} days`,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
+35
-35
@@ -1,10 +1,10 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import { TanksStats } from '../types/tanksStats.js';
|
||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
import { tankTypeEmojis, tankopedia } from '../utilities/tankopedia.js';
|
||||
|
||||
export default {
|
||||
@@ -47,42 +47,42 @@ export default {
|
||||
const tier = Math.round(interaction.options.getNumber('tier')!);
|
||||
|
||||
getBlitzAccount(interaction, name, server, async (account) => {
|
||||
const tankStats = (await (
|
||||
await fetch(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${process.env.WARGAMING_APPLICATION_ID}&account_id=${account.account_id}`,
|
||||
)
|
||||
).json()) as TanksStats;
|
||||
getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${process.env.WARGAMING_APPLICATION_ID}&account_id=${account.account_id}`,
|
||||
interaction,
|
||||
async (tankStats) => {
|
||||
const tanks = tankStats[account.account_id]!.map(
|
||||
(tankData) => tankopedia.data[tankData.tank_id],
|
||||
).filter((tank) => tank.tier === tier);
|
||||
|
||||
const tanks = tankStats.data[account.account_id]!.map(
|
||||
(tankData) => tankopedia.data[tankData.tank_id],
|
||||
).filter((tank) => tank.tier === tier);
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle(
|
||||
`${account.nickname}'s owned ${
|
||||
tier === null ? '' : `tier ${tier} `
|
||||
}tanks`,
|
||||
)
|
||||
.setDescription(
|
||||
tanks.length === 0
|
||||
? `No tanks found for player in tier ${tier}`
|
||||
: tanks
|
||||
.map(
|
||||
(tank) =>
|
||||
`${tankTypeEmojis[tank.type]} ${tank.name} ${
|
||||
tank.is_premium ? '⭐' : ''
|
||||
}`,
|
||||
)
|
||||
.join('\n'),
|
||||
)
|
||||
.setColor(SKILLED_COLOR),
|
||||
],
|
||||
});
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle(
|
||||
`${account.nickname}'s owned ${
|
||||
tier === null ? '' : `tier ${tier} `
|
||||
}tanks`,
|
||||
)
|
||||
.setDescription(
|
||||
tanks.length === 0
|
||||
? `No tanks found for player in tier ${tier}`
|
||||
: tanks
|
||||
.map(
|
||||
(tank) =>
|
||||
`${tankTypeEmojis[tank.type]} ${tank.name} ${
|
||||
tank.is_premium ? '⭐' : ''
|
||||
}`,
|
||||
)
|
||||
.join('\n'),
|
||||
)
|
||||
.setColor(SKILLED_COLOR),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying ${account.nickname}'s owned tanks in tier ${tier}`,
|
||||
console.log(
|
||||
`Displaying ${account.nickname}'s owned tanks in tier ${tier}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
+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