mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: general inactive command
This commit is contained in:
1 parent
468bca77de
commit
57cc67c8be
10 files changed
+189
-115
No files matched your search
@@ -49,21 +49,21 @@ export default {
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('ign')
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
),
|
||||
|
||||
execute(interaction) {
|
||||
const ign = interaction.options.getString('ign')!;
|
||||
const name = interaction.options.getString('name')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const clan = interaction.options.getString('clan') as keyof typeof CLANS;
|
||||
|
||||
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||
getBlitzAccount(interaction, name, server, async (account) => {
|
||||
getBlitzStarsAccount(
|
||||
interaction,
|
||||
account.account_id,
|
||||
ign,
|
||||
name,
|
||||
async (data) => {
|
||||
const issues: string[] = [];
|
||||
|
||||
|
||||
+69
-60
@@ -2,28 +2,36 @@ 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 { PlayerPersonalData } from '../types/playerPersonalData.js';
|
||||
import { CLANS } from './eligible.js';
|
||||
import getClan from '../utilities/getClan.js';
|
||||
|
||||
const DEFAULT_THRESHOLD = 7;
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inPublic: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('inactive')
|
||||
.setDescription('Lists all inactive players')
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('clan')
|
||||
.setDescription('The Skilled clan you are checking')
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: CLANS.sklld.name, value: 'sklld' },
|
||||
{ name: CLANS.smri.name, value: 'smri' },
|
||||
)
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
.setDescription('The clan name or tag you are checking')
|
||||
.setRequired(true),
|
||||
)
|
||||
.addNumberOption((option) =>
|
||||
@@ -36,63 +44,64 @@ export default {
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const threshold =
|
||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||
const time = new Date().getTime() / 1000;
|
||||
const clanName = interaction.options.getString(
|
||||
'clan',
|
||||
) as keyof typeof CLANS;
|
||||
const clanData = (await (
|
||||
await fetch(
|
||||
`https://api.wotblitz.com/wotb/clans/info/?application_id=${process.env.WARGAMING_APPLICATION_ID}&clan_id=${CLANS[clanName].id}`,
|
||||
)
|
||||
).json()) as ClanDetails;
|
||||
const clan = clanData.data[CLANS[clanName].id];
|
||||
const memberIds = clan.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 name = interaction.options.getString('name')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
|
||||
const inactiveInfo = memberIds
|
||||
.map((memberId) => {
|
||||
const member = playerPersonalData.data[memberId];
|
||||
const inactiveDays = (time - member.last_battle_time) / 60 / 60 / 24;
|
||||
getClan(interaction, name, server, async (clan) => {
|
||||
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;
|
||||
|
||||
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 inactiveInfo = memberIds
|
||||
.map((memberId) => {
|
||||
const member = playerPersonalData.data[memberId];
|
||||
const inactiveDays = (time - member.last_battle_time) / 60 / 60 / 24;
|
||||
|
||||
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;
|
||||
|
||||
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.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
const hasInactiveMembers = inactiveInfo.length > 0;
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(hasInactiveMembers ? NEGATIVE_COLOR : POSITIVE_COLOR)
|
||||
.setTitle(
|
||||
hasInactiveMembers
|
||||
? `${CLANS[clanName].name}'s inactive members`
|
||||
: `No inactive members in ${CLANS[clanName].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`,
|
||||
);
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying inactive members in ${CLANS[clanName].name} for ${threshold} days`,
|
||||
);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -9,7 +9,7 @@ import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -39,24 +39,24 @@ export default {
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('ign')
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
),
|
||||
|
||||
execute(interaction) {
|
||||
const ign = interaction.options.getString('ign')!;
|
||||
const name = interaction.options.getString('name')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const period = interaction.options.getString('period')! as
|
||||
| '30'
|
||||
| '90'
|
||||
| 'career';
|
||||
|
||||
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||
getBlitzAccount(interaction, name, server, async (account) => {
|
||||
getBlitzStarsAccount(
|
||||
interaction,
|
||||
account.account_id,
|
||||
ign,
|
||||
name,
|
||||
async (data) => {
|
||||
{
|
||||
const stats =
|
||||
|
||||
@@ -28,7 +28,7 @@ export default {
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('ign')
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
)
|
||||
@@ -43,10 +43,10 @@ export default {
|
||||
|
||||
execute(interaction) {
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const ign = interaction.options.getString('ign')!;
|
||||
const name = interaction.options.getString('name')!;
|
||||
const tier = Math.round(interaction.options.getNumber('tier')!);
|
||||
|
||||
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||
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}`,
|
||||
|
||||
@@ -28,16 +28,16 @@ export default {
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('ign')
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
),
|
||||
|
||||
execute(interaction) {
|
||||
const ign = interaction.options.getString('ign')!;
|
||||
const name = interaction.options.getString('name')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
|
||||
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||
getBlitzAccount(interaction, name, server, async (account) => {
|
||||
// good match
|
||||
const clanData = (await fetch(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${process.env.WARGAMING_APPLICATION_ID}&account_id=${account.account_id}&extra=clan`,
|
||||
@@ -51,7 +51,7 @@ export default {
|
||||
);
|
||||
|
||||
member
|
||||
?.setNickname(`${ign}${clanTag}`)
|
||||
?.setNickname(`${name}${clanTag}`)
|
||||
.then(async () => {
|
||||
await member.roles.remove(discord.verify_role);
|
||||
await member.roles.add(discord.peasant_role);
|
||||
@@ -61,13 +61,13 @@ export default {
|
||||
.setColor(POSITIVE_COLOR)
|
||||
.setTitle(`${interaction.user.username} is verified`)
|
||||
.setDescription(
|
||||
`The user is now verified as ${ign}${clanTag}`,
|
||||
`The user is now verified as ${name}${clanTag}`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(
|
||||
`${interaction.user.username} verified as ${ign}${clanTag}`,
|
||||
`${interaction.user.username} verified as ${name}${clanTag}`,
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
@@ -83,7 +83,7 @@ export default {
|
||||
});
|
||||
|
||||
console.warn(
|
||||
`${interaction.user.username} failed to verify as ${ign}${clanTag}`,
|
||||
`${interaction.user.username} failed to verify as ${name}${clanTag}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user