mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: clans eligibility
This commit is contained in:
1 parent
0fbc0bf07f
commit
543ae0635a
9 files changed
+254
-85
No files matched your search
Vendored
+8
-1
@@ -1,5 +1,12 @@
|
|||||||
{
|
{
|
||||||
"cSpell.words": ["Abhi", "accountinfo", "SKLLD", "wargaming", "winrate"],
|
"cSpell.words": [
|
||||||
|
"Abhi",
|
||||||
|
"accountinfo",
|
||||||
|
"SKLLD",
|
||||||
|
"Smri",
|
||||||
|
"wargaming",
|
||||||
|
"winrate"
|
||||||
|
],
|
||||||
"deno.enable": false,
|
"deno.enable": false,
|
||||||
"deno.unstable": false
|
"deno.unstable": false
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,10 @@ import {
|
|||||||
import { readdirSync } from 'fs';
|
import { readdirSync } from 'fs';
|
||||||
import discord from '../../discord.json' assert { type: 'json' };
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
import getClientId from '../utilities/getClientId.js';
|
import getClientId from '../utilities/getClientId.js';
|
||||||
|
import isDev from '../utilities/isDev.js';
|
||||||
|
|
||||||
export interface CommandRegistry {
|
export interface CommandRegistry {
|
||||||
disabled?: boolean;
|
inDev?: boolean;
|
||||||
data: SlashCommandBuilder;
|
data: SlashCommandBuilder;
|
||||||
execute: (interaction: Interaction) => void;
|
execute: (interaction: Interaction) => void;
|
||||||
}
|
}
|
||||||
@@ -25,7 +26,7 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
|
|||||||
for (const file of commandFolders) {
|
for (const file of commandFolders) {
|
||||||
const command = (await import(`../commands/${file}`)) as CommandRegistry;
|
const command = (await import(`../commands/${file}`)) as CommandRegistry;
|
||||||
|
|
||||||
if (!command.disabled) {
|
if (isDev() ? command.inDev ?? false : true) {
|
||||||
commands.push(command.data.toJSON());
|
commands.push(command.data.toJSON());
|
||||||
commandCollection.set(command.data.name, command);
|
commandCollection.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
import {
|
||||||
|
CacheType,
|
||||||
|
ChatInputCommandInteraction,
|
||||||
|
EmbedBuilder,
|
||||||
|
SlashCommandBuilder,
|
||||||
|
} from 'discord.js';
|
||||||
|
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||||
|
import { SERVERS } from '../constants/servers.js';
|
||||||
|
import blitzLinks from '../utilities/blitzLinks.js';
|
||||||
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||||
|
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||||
|
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
||||||
|
|
||||||
|
export async function execute(
|
||||||
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
|
) {
|
||||||
|
const ign = interaction.options.getString('ign')!;
|
||||||
|
const server = interaction.options.getString(
|
||||||
|
'server',
|
||||||
|
) as keyof typeof SERVERS;
|
||||||
|
|
||||||
|
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||||
|
getBlitzStarsAccount(interaction, account.account_id, ign, async (data) => {
|
||||||
|
const sklldIssues: string[] = [];
|
||||||
|
const smriIssues: string[] = [];
|
||||||
|
|
||||||
|
if (data.period30d.all.battles < 150) {
|
||||||
|
sklldIssues.push(
|
||||||
|
`**Battles**: ${data.period30d.all.battles} (${
|
||||||
|
data.period30d.all.battles - 150
|
||||||
|
})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (data.period30d.avg_tier < 8) {
|
||||||
|
sklldIssues.push(
|
||||||
|
`**Tier**: ${data.period30d.avg_tier.toFixed(2)} (${(
|
||||||
|
data.period30d.avg_tier - 8
|
||||||
|
).toFixed(2)})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (data.period30d.special.winrate < 60) {
|
||||||
|
sklldIssues.push(
|
||||||
|
`**Winrate**: ${data.period30d.special.winrate.toFixed(2)}% (${(
|
||||||
|
data.period30d.special.winrate - 60
|
||||||
|
).toFixed(2)}%)`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (data.period30d.wn8 < 2100) {
|
||||||
|
sklldIssues.push(
|
||||||
|
`**WN8**: ${data.period30d.wn8.toFixed(0)} (${(
|
||||||
|
data.period30d.wn8 - 2100
|
||||||
|
).toFixed(0)})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (data.period30d.special.dpb < 2400) {
|
||||||
|
sklldIssues.push(
|
||||||
|
`**Damage per battle**: ${data.period30d.special.dpb.toFixed(0)} (${(
|
||||||
|
data.period30d.special.dpb - 2400
|
||||||
|
).toFixed(0)})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.statistics.all.battles < 1500) {
|
||||||
|
smriIssues.push(
|
||||||
|
`**Battles**: ${data.statistics.all.battles} (${
|
||||||
|
data.statistics.all.battles - 1500
|
||||||
|
})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (data.statistics.special.winrate < 53) {
|
||||||
|
smriIssues.push(
|
||||||
|
`**Winrate**: ${data.statistics.special.winrate.toFixed(2)}% (${(
|
||||||
|
data.statistics.special.winrate - 53
|
||||||
|
).toFixed(2)}%)`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [
|
||||||
|
poweredByBlitzStars(
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setTitle(`${data.nickname}'s eligibility for Skilled clans`)
|
||||||
|
.setColor(
|
||||||
|
sklldIssues.length === 0 || smriIssues.length === 0
|
||||||
|
? POSITIVE_COLOR
|
||||||
|
: NEGATIVE_COLOR,
|
||||||
|
)
|
||||||
|
.setDescription(
|
||||||
|
`${
|
||||||
|
sklldIssues.length === 0
|
||||||
|
? '**✅ Player is eligible for `[SKLLD]`**'
|
||||||
|
: `**❌ \`[SKLLD] short by (30 days):\`**\n${sklldIssues.join(
|
||||||
|
'\n',
|
||||||
|
)}`
|
||||||
|
}\n\n${
|
||||||
|
smriIssues.length === 0
|
||||||
|
? '**✅ Player is eligible for `[SMRI]`**'
|
||||||
|
: `**❌ \`[SMRI] short by (career):\`**\n${smriIssues.join(
|
||||||
|
'\n',
|
||||||
|
)}`
|
||||||
|
}\n\n${blitzLinks(data)}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Showing ${data.nickname}'s eligibility for Skilled clans`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const data = new SlashCommandBuilder()
|
||||||
|
.setName('eligible')
|
||||||
|
.setDescription("Gets the user's eligibility for Skilled clans")
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('server')
|
||||||
|
.setDescription('The Blitz server you are in')
|
||||||
|
.addChoices(
|
||||||
|
{ name: SERVERS.com, value: 'com' },
|
||||||
|
{ name: SERVERS.eu, value: 'eu' },
|
||||||
|
{ name: SERVERS.asia, value: 'asia' },
|
||||||
|
)
|
||||||
|
.setRequired(true),
|
||||||
|
)
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('ign')
|
||||||
|
.setDescription('The username you use in Blitz')
|
||||||
|
.setRequired(true),
|
||||||
|
);
|
||||||
+61
-78
@@ -4,11 +4,12 @@ import {
|
|||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import fetch from 'node-fetch';
|
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||||
import { NEGATIVE_COLOR, SKILLED_COLOR } from '../constants/colors.js';
|
|
||||||
import { SERVERS } from '../constants/servers.js';
|
import { SERVERS } from '../constants/servers.js';
|
||||||
import { PlayerStatistics } from '../types/statistics.js';
|
import blitzLinks from '../utilities/blitzLinks.js';
|
||||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||||
|
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||||
|
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
||||||
|
|
||||||
export async function execute(
|
export async function execute(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
@@ -23,89 +24,71 @@ export async function execute(
|
|||||||
| 'career';
|
| 'career';
|
||||||
|
|
||||||
getBlitzAccount(interaction, ign, server, async (account) => {
|
getBlitzAccount(interaction, ign, server, async (account) => {
|
||||||
fetch(`https://www.blitzstars.com/api/top/player/${account.account_id}`)
|
getBlitzStarsAccount(interaction, account.account_id, ign, async (data) => {
|
||||||
.then(async (response) => {
|
{
|
||||||
const data = (await response.json()) as PlayerStatistics;
|
|
||||||
const stats =
|
const stats =
|
||||||
period === 'career' ? data.statistics : data[`period${period}d`];
|
period === 'career' ? data.statistics : data[`period${period}d`];
|
||||||
|
|
||||||
interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
poweredByBlitzStars(
|
||||||
.setColor(SKILLED_COLOR)
|
new EmbedBuilder()
|
||||||
.setTitle(
|
.setColor(SKILLED_COLOR)
|
||||||
`${data.nickname}'s ${
|
.setTitle(
|
||||||
period === 'career' ? period : `${period} day`
|
`${data.nickname}'s ${
|
||||||
} stats`,
|
period === 'career' ? period : `${period} day`
|
||||||
)
|
} stats`,
|
||||||
.setDescription(
|
)
|
||||||
`${[
|
.setDescription(
|
||||||
['Winrate', `${stats.special.winrate.toFixed(2)}%`],
|
`${[
|
||||||
['Survival', `${stats.special.survivalRate.toFixed(2)}%`],
|
['Winrate', `${stats.special.winrate.toFixed(2)}%`],
|
||||||
[
|
['Survival', `${stats.special.survivalRate.toFixed(2)}%`],
|
||||||
'Accuracy',
|
[
|
||||||
`${((stats.all.hits / stats.all.shots) * 100).toFixed(2)}%`,
|
'Accuracy',
|
||||||
],
|
`${((stats.all.hits / stats.all.shots) * 100).toFixed(
|
||||||
['WN8', stats.wn8.toFixed(0)],
|
2,
|
||||||
['WN7', stats.wn7.toFixed(0)],
|
)}%`,
|
||||||
[],
|
],
|
||||||
['Battles', stats.all.battles],
|
['WN8', stats.wn8.toFixed(0)],
|
||||||
['Wins', stats.all.wins],
|
['WN7', stats.wn7.toFixed(0)],
|
||||||
['Losses', stats.all.losses],
|
[],
|
||||||
['Average tier', stats.avg_tier.toFixed(2)],
|
['Battles', stats.all.battles],
|
||||||
[],
|
['Wins', stats.all.wins],
|
||||||
['Hits per battle', stats.special.hpb.toFixed(2)],
|
['Losses', stats.all.losses],
|
||||||
['Damage per battle', stats.special.dpb.toFixed(0)],
|
['Average tier', stats.avg_tier.toFixed(2)],
|
||||||
['Kills per battle', stats.special.kpb.toFixed(2)],
|
[],
|
||||||
['Spots per battle', stats.special.spb.toFixed(2)],
|
['Hits per battle', stats.special.hpb.toFixed(2)],
|
||||||
[
|
['Damage per battle', stats.special.dpb.toFixed(0)],
|
||||||
'Shots per battle',
|
['Kills per battle', stats.special.kpb.toFixed(2)],
|
||||||
(stats.all.shots / stats.all.battles).toFixed(2),
|
['Spots per battle', stats.special.spb.toFixed(2)],
|
||||||
],
|
[
|
||||||
[
|
'Shots per battle',
|
||||||
'Hits per battle',
|
(stats.all.shots / stats.all.battles).toFixed(2),
|
||||||
(stats.all.hits / stats.all.battles).toFixed(2),
|
],
|
||||||
],
|
[
|
||||||
[
|
'Hits per battle',
|
||||||
'XP per battle',
|
(stats.all.hits / stats.all.battles).toFixed(2),
|
||||||
(stats.all.xp / stats.all.battles).toFixed(0),
|
],
|
||||||
],
|
[
|
||||||
[],
|
'XP per battle',
|
||||||
['Damage ratio', stats.special.damageRatio.toFixed(2)],
|
(stats.all.xp / stats.all.battles).toFixed(0),
|
||||||
['Kills to death ratio', stats.special.kdr.toFixed(2)],
|
],
|
||||||
]
|
[],
|
||||||
.map((array) =>
|
['Damage ratio', stats.special.damageRatio.toFixed(2)],
|
||||||
array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`,
|
['Kills to death ratio', stats.special.kdr.toFixed(2)],
|
||||||
)
|
]
|
||||||
.join(
|
.map((array) =>
|
||||||
'\n',
|
array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`,
|
||||||
)}\n\n[View full stats](https://www.blitzstars.com/player/${
|
)
|
||||||
data.region
|
.join('\n')}\n\n${blitzLinks(data)}`,
|
||||||
}/${
|
),
|
||||||
data.nickname
|
),
|
||||||
}) • [Support BlitzStars](https://www.blitzstars.com/supporters)`,
|
|
||||||
)
|
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
text: 'Powered by BlitzStars',
|
|
||||||
iconURL:
|
|
||||||
'https://www.blitzstars.com/assets/images/TankyMcPewpew.png',
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing ${data.nickname}'s ${period} stats`);
|
console.log(`Showing ${data.nickname}'s ${period} stats`);
|
||||||
})
|
}
|
||||||
.catch(() => {
|
});
|
||||||
interaction.reply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setTitle('No data to display')
|
|
||||||
.setDescription(`${ign} is not tracked by BlitzStars.`)
|
|
||||||
.setColor(NEGATIVE_COLOR),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { PlayerStatistics } from '../types/statistics.js';
|
||||||
|
|
||||||
|
export default function blitzLinks(data: PlayerStatistics) {
|
||||||
|
return `[View full stats](https://www.blitzstars.com/player/${data.region}/${data.nickname}) • [Support BlitzStars](https://www.blitzstars.com/supporters)`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import {
|
||||||
|
CacheType,
|
||||||
|
ChatInputCommandInteraction,
|
||||||
|
EmbedBuilder,
|
||||||
|
} from 'discord.js';
|
||||||
|
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||||
|
import { PlayerStatistics } from '../types/statistics.js';
|
||||||
|
|
||||||
|
export default async function getBlitzStarsAccount(
|
||||||
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
|
accountId: number,
|
||||||
|
ign: string,
|
||||||
|
callback: (account: PlayerStatistics) => void,
|
||||||
|
) {
|
||||||
|
fetch(`https://www.blitzstars.com/api/top/player/${accountId}`)
|
||||||
|
.then(async (response) => {
|
||||||
|
callback((await response.json()) as PlayerStatistics);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [
|
||||||
|
new EmbedBuilder()
|
||||||
|
.setTitle('No data to display')
|
||||||
|
.setDescription(`${ign} is not tracked by BlitzStars.`)
|
||||||
|
.setColor(NEGATIVE_COLOR),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import { argv } from 'process';
|
|
||||||
import discord from '../../discord.json' assert { type: 'json' };
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
|
import isDev from './isDev.js';
|
||||||
const isDev = argv.includes('--dev');
|
|
||||||
|
|
||||||
export default function getClientId() {
|
export default function getClientId() {
|
||||||
return isDev ? discord.client_id_dev : discord.client_id;
|
return isDev() ? discord.client_id_dev : discord.client_id;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { argv } from 'process';
|
||||||
|
|
||||||
|
const isDevBoolean = argv.includes('--dev');
|
||||||
|
|
||||||
|
export default function isDev() {
|
||||||
|
return isDevBoolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { EmbedBuilder } from 'discord.js';
|
||||||
|
|
||||||
|
export default function poweredByBlitzStars(embed: EmbedBuilder) {
|
||||||
|
return embed.setTimestamp().setFooter({
|
||||||
|
text: 'Powered by BlitzStars',
|
||||||
|
iconURL: 'https://www.blitzstars.com/assets/images/TankyMcPewpew.png',
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user