mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 15:52:55 +01:00
Merge pull request #5 from tresabhi/1.6.0
This commit is contained in:
47 files changed
+588
-360
No files matched your search
Vendored
+1
@@ -6,6 +6,7 @@
|
|||||||
"ownedtanks",
|
"ownedtanks",
|
||||||
"Resvg",
|
"Resvg",
|
||||||
"searchplayers",
|
"searchplayers",
|
||||||
|
"SKLLD",
|
||||||
"Smri",
|
"Smri",
|
||||||
"strvk",
|
"strvk",
|
||||||
"tankopedia",
|
"tankopedia",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "blitzkrieg",
|
"name": "blitzkrieg",
|
||||||
"version": "1.5.4",
|
"version": "1.6.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -46,7 +46,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Displaying bot's debug information");
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||||
|
import getWN8 from '../core/blitz/getWN8.js';
|
||||||
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
|
import sumStats from '../core/blitz/sumStats.js';
|
||||||
|
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||||
|
import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
|
||||||
|
import getPeriodicStart from '../core/blitzstars/getPeriodStart.js';
|
||||||
|
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
||||||
|
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||||
|
import cleanTable, { TableInput } from '../core/interaction/cleanTable.js';
|
||||||
|
import cmdName from '../core/interaction/cmdName.js';
|
||||||
|
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
||||||
|
import positiveEmbed from '../core/interaction/positiveEmbed.js';
|
||||||
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
|
import { args } from '../core/process/args.js';
|
||||||
|
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||||
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
|
|
||||||
|
export type SkilledClan = 'SKLLD' | 'SMRI';
|
||||||
|
|
||||||
|
export const SKILLED_CLANS: Record<SkilledClan, string> = {
|
||||||
|
SKLLD: 'Skilled',
|
||||||
|
SMRI: 'Samurai',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
inProduction: true,
|
||||||
|
inDevelopment: false,
|
||||||
|
inPublic: false,
|
||||||
|
|
||||||
|
command: new SlashCommandBuilder()
|
||||||
|
.setName(cmdName('eligible'))
|
||||||
|
.setDescription('Checks eligibility for any Skilled clan')
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('clan')
|
||||||
|
.setDescription('The clan to check')
|
||||||
|
.setChoices(
|
||||||
|
{
|
||||||
|
name: SKILLED_CLANS.SKLLD,
|
||||||
|
value: 'SKLLD' satisfies SkilledClan,
|
||||||
|
},
|
||||||
|
{ name: SKILLED_CLANS.SMRI, value: 'SMRI' satisfies SkilledClan },
|
||||||
|
)
|
||||||
|
.setRequired(true),
|
||||||
|
)
|
||||||
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
const clan = interaction.options.getString('clan') as SkilledClan;
|
||||||
|
const { id, server } = await getBlitzAccount(interaction);
|
||||||
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
|
);
|
||||||
|
const problems: TableInput = [];
|
||||||
|
const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
|
||||||
|
let isEligible = false;
|
||||||
|
let body = '';
|
||||||
|
|
||||||
|
if (clan === 'SKLLD') {
|
||||||
|
const tankStatsOverTime = await getTankStatsOverTime(
|
||||||
|
interaction,
|
||||||
|
server,
|
||||||
|
id,
|
||||||
|
getPeriodicStart('30'),
|
||||||
|
getPeriodNow(),
|
||||||
|
);
|
||||||
|
const entries = Object.entries(tankStatsOverTime);
|
||||||
|
const stats = sumStats(entries.map(([, stats]) => stats));
|
||||||
|
const averageTier =
|
||||||
|
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||||
|
const tankId = parseInt(tankIdString);
|
||||||
|
const tankTier = tankopedia[tankId].tier;
|
||||||
|
|
||||||
|
return accumulator + tankTier * stats.battles;
|
||||||
|
}, 0) / stats.battles;
|
||||||
|
const WN8 =
|
||||||
|
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||||
|
const tankId = parseInt(tankIdString);
|
||||||
|
|
||||||
|
// edge case where new tanks don't have averages
|
||||||
|
if (tankAverages[tankId]) {
|
||||||
|
const tankWN8 = getWN8(tankAverages[tankId].all, stats);
|
||||||
|
|
||||||
|
if (isNaN(tankWN8)) return accumulator;
|
||||||
|
return accumulator + tankWN8 * stats.battles;
|
||||||
|
} else return accumulator;
|
||||||
|
}, 0) / stats.battles;
|
||||||
|
const tier10Damage =
|
||||||
|
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||||
|
const tankId = parseInt(tankIdString);
|
||||||
|
|
||||||
|
if (tankopedia[tankId]?.tier === 10) {
|
||||||
|
const tankStats = tankStatsOverTime[tankId];
|
||||||
|
return accumulator + tankStats.damage_dealt;
|
||||||
|
} else return accumulator;
|
||||||
|
}, 0) /
|
||||||
|
entries.reduce((accumulator, [tankIdString, stats]) => {
|
||||||
|
const tankId = parseInt(tankIdString);
|
||||||
|
|
||||||
|
if (tankopedia[tankId]?.tier === 10) {
|
||||||
|
const tankStats = tankStatsOverTime[tankId];
|
||||||
|
return accumulator + tankStats.battles;
|
||||||
|
} else return accumulator;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
if (stats.battles < 126) {
|
||||||
|
problems.push(['Battles', `${stats.battles} (${stats.battles - 126})`]);
|
||||||
|
}
|
||||||
|
if (averageTier < 8) {
|
||||||
|
problems.push([
|
||||||
|
'Average tier',
|
||||||
|
`${averageTier.toFixed(2)} (${(averageTier - 8).toFixed(2)})`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (stats.wins / stats.battles < 0.6) {
|
||||||
|
problems.push([
|
||||||
|
'Winrate',
|
||||||
|
`${(100 * (stats.wins / stats.battles)).toFixed(2)}% (${(
|
||||||
|
100 *
|
||||||
|
(stats.wins / stats.battles - 0.6)
|
||||||
|
).toFixed(2)}%)`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (WN8 < 2450) {
|
||||||
|
problems.push(['WN8', `${WN8.toFixed(0)} (${WN8 - 2450})`]);
|
||||||
|
}
|
||||||
|
if (tier10Damage < 1250) {
|
||||||
|
problems.push([
|
||||||
|
'Tier 10 damage',
|
||||||
|
`${tier10Damage.toFixed(0)} (${tier10Damage - 1250})`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
isEligible = problems.length === 0;
|
||||||
|
body = isEligible
|
||||||
|
? 'Player is fully eligible.'
|
||||||
|
: `Player is not eligible. Shortcomings in 30-day statistics:\n\n${cleanTable(
|
||||||
|
problems,
|
||||||
|
)}`;
|
||||||
|
} else if (clan === 'SMRI') {
|
||||||
|
const stats = accountInfo[id].statistics.all;
|
||||||
|
|
||||||
|
if (stats.battles < 1500) {
|
||||||
|
problems.push([
|
||||||
|
'Battles',
|
||||||
|
`${stats.battles} (${stats.battles - 1500})`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (stats.wins / stats.battles <= 0.53) {
|
||||||
|
problems.push([
|
||||||
|
'Winrate',
|
||||||
|
`${(100 * (stats.wins / stats.battles)).toFixed(2)}% (${(
|
||||||
|
100 *
|
||||||
|
(stats.wins / stats.battles - 0.53)
|
||||||
|
).toFixed(2)}%)`,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
isEligible = problems.length === 0;
|
||||||
|
body = isEligible
|
||||||
|
? 'Player is fully eligible.'
|
||||||
|
: `Player is not eligible. Shortcomings in career statistics:\n\n${cleanTable(
|
||||||
|
problems,
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: isEligible
|
||||||
|
? [positiveEmbed(title, body)]
|
||||||
|
: [negativeEmbed(title, body)],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
} satisfies CommandRegistry;
|
||||||
@@ -39,7 +39,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Displaying help information');
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|
||||||
import markdownEscape from 'markdown-escape';
|
|
||||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
|
||||||
import clanAutocomplete from '../core/autocomplete/clan.js';
|
|
||||||
import getBlitzClan from '../core/blitz/getBlitzClan.js';
|
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
|
||||||
import cmdName from '../core/interaction/cmdName.js';
|
|
||||||
import addClanChoices from '../core/options/addClanChoices.js';
|
|
||||||
import { args } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
|
||||||
import { ClanInfo } from '../types/clanInfo.js';
|
|
||||||
|
|
||||||
const DEFAULT_THRESHOLD = 7;
|
|
||||||
|
|
||||||
export default {
|
|
||||||
inProduction: true,
|
|
||||||
inDevelopment: false,
|
|
||||||
inPublic: true,
|
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
|
||||||
.setName(cmdName('inactive'))
|
|
||||||
.setDescription('Lists all inactive players')
|
|
||||||
.addStringOption(addClanChoices)
|
|
||||||
.addNumberOption((option) =>
|
|
||||||
option
|
|
||||||
.setName('threshold')
|
|
||||||
.setDescription(
|
|
||||||
`The number of days inactive (default: ${DEFAULT_THRESHOLD})`,
|
|
||||||
)
|
|
||||||
.setMinValue(0),
|
|
||||||
),
|
|
||||||
|
|
||||||
async execute(interaction) {
|
|
||||||
const clanName = interaction.options.getString('clan')!;
|
|
||||||
const clan = await getBlitzClan(interaction, clanName);
|
|
||||||
const { server, id } = clan;
|
|
||||||
|
|
||||||
const threshold =
|
|
||||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
|
||||||
const time = new Date().getTime() / 1000;
|
|
||||||
const clanInfo = await getWargamingResponse<ClanInfo>(
|
|
||||||
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${id}`,
|
|
||||||
);
|
|
||||||
const memberIds = clanInfo[id].members_ids;
|
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${
|
|
||||||
args['wargaming-application-id']
|
|
||||||
}&account_id=${memberIds.join(',')}`,
|
|
||||||
);
|
|
||||||
const inactiveInfo = memberIds
|
|
||||||
.map((memberId) => {
|
|
||||||
const member = accountInfo[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 `**${markdownEscape(nickname)}**: ${days} day${
|
|
||||||
days === 1 ? '' : 's'
|
|
||||||
}`;
|
|
||||||
});
|
|
||||||
const hasInactiveMembers = inactiveInfo.length > 0;
|
|
||||||
|
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setColor(hasInactiveMembers ? NEGATIVE_COLOR : POSITIVE_COLOR)
|
|
||||||
.setTitle(
|
|
||||||
hasInactiveMembers
|
|
||||||
? `${markdownEscape(clanInfo[id].name)}'s inactive members`
|
|
||||||
: `No inactive members in ${markdownEscape(clanInfo[id].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 ${clanInfo[id].name} for ${threshold} days`,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
autocomplete: clanAutocomplete,
|
|
||||||
} satisfies CommandRegistry;
|
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
|
import GenericStats from '../components/GenericStats/index.js';
|
||||||
|
import NoData, { NoDataType } from '../components/NoData.js';
|
||||||
|
import PoweredByWargaming from '../components/PoweredByWargaming.js';
|
||||||
|
import TitleBar from '../components/TitleBar.js';
|
||||||
|
import Wrapper from '../components/Wrapper.js';
|
||||||
|
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||||
|
import clanAutocomplete from '../core/autocomplete/clan.js';
|
||||||
|
import getBlitzClan from '../core/blitz/getBlitzClan.js';
|
||||||
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
|
import cmdName from '../core/interaction/cmdName.js';
|
||||||
|
import addClanChoices from '../core/options/addClanChoices.js';
|
||||||
|
import { args } from '../core/process/args.js';
|
||||||
|
import render from '../core/ui/render.js';
|
||||||
|
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||||
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
|
import { ClanInfo } from '../types/clanInfo.js';
|
||||||
|
|
||||||
|
const DEFAULT_THRESHOLD = 7;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
inProduction: true,
|
||||||
|
inDevelopment: false,
|
||||||
|
inPublic: true,
|
||||||
|
|
||||||
|
command: new SlashCommandBuilder()
|
||||||
|
.setName(cmdName('inactive'))
|
||||||
|
.setDescription('Lists all inactive players')
|
||||||
|
.addStringOption(addClanChoices)
|
||||||
|
.addNumberOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('threshold')
|
||||||
|
.setDescription(
|
||||||
|
`The number of days inactive (default: ${DEFAULT_THRESHOLD})`,
|
||||||
|
)
|
||||||
|
.setMinValue(0),
|
||||||
|
),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
const clanName = interaction.options.getString('clan')!;
|
||||||
|
const { server, id } = await getBlitzClan(interaction, clanName);
|
||||||
|
const threshold =
|
||||||
|
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||||
|
const time = new Date().getTime() / 1000;
|
||||||
|
const clanData = (
|
||||||
|
await getWargamingResponse<ClanInfo>(
|
||||||
|
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${id}`,
|
||||||
|
)
|
||||||
|
)[id];
|
||||||
|
const memberIds = clanData.members_ids;
|
||||||
|
const accounts = await getWargamingResponse<AccountInfo>(
|
||||||
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${
|
||||||
|
args['wargaming-application-id']
|
||||||
|
}&account_id=${memberIds.join(',')}`,
|
||||||
|
);
|
||||||
|
const inactive = memberIds
|
||||||
|
.map((memberId) => {
|
||||||
|
const member = accounts[memberId];
|
||||||
|
const inactiveDays = (time - member.last_battle_time) / 60 / 60 / 24;
|
||||||
|
|
||||||
|
return [member.nickname, inactiveDays] as [string, number];
|
||||||
|
})
|
||||||
|
.filter(([, inactiveDays]) => inactiveDays >= threshold)
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.map(
|
||||||
|
([name, days]) => [name, `${days.toFixed(0)} days`] as [string, string],
|
||||||
|
);
|
||||||
|
const hasInactiveMembers = inactive.length > 0;
|
||||||
|
|
||||||
|
const image = await render(
|
||||||
|
<Wrapper>
|
||||||
|
<TitleBar
|
||||||
|
name={clanData.name}
|
||||||
|
nameDiscriminator="(Inactivity)"
|
||||||
|
image={`https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData.emblem_set_id}.png`}
|
||||||
|
description={`${threshold}+ Days • ${new Date().toDateString()} • ${
|
||||||
|
BLITZ_SERVERS[server]
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!hasInactiveMembers && <NoData type={NoDataType.PlayersInPeriod} />}
|
||||||
|
{hasInactiveMembers && <GenericStats stats={inactive} />}
|
||||||
|
|
||||||
|
<PoweredByWargaming />
|
||||||
|
</Wrapper>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await interaction.editReply({ files: [image] });
|
||||||
|
},
|
||||||
|
|
||||||
|
autocomplete: clanAutocomplete,
|
||||||
|
} satisfies CommandRegistry;
|
||||||
@@ -1,17 +1,22 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { SlashCommandBuilder } from 'discord.js';
|
||||||
import markdownEscape from 'markdown-escape';
|
import NoData, { NoDataType } from '../components/NoData.js';
|
||||||
|
import PoweredByWargaming from '../components/PoweredByWargaming.js';
|
||||||
|
import * as Tanks from '../components/Tanks/index.js';
|
||||||
|
import TitleBar from '../components/TitleBar.js';
|
||||||
|
import Wrapper from '../components/Wrapper.js';
|
||||||
|
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||||
import getTankStats from '../core/blitz/getTankStats.js';
|
import getTankStats from '../core/blitz/getTankStats.js';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import resolveTankName from '../core/blitz/resolveTankName.js';
|
import { TIER_ROMAN_NUMERALS, tankopedia } from '../core/blitz/tankopedia.js';
|
||||||
import { TANK_TYPE_EMOJIS, tankopedia } from '../core/blitz/tankopedia.js';
|
|
||||||
import cmdName from '../core/interaction/cmdName.js';
|
import cmdName from '../core/interaction/cmdName.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import { args } from '../core/process/args.js';
|
import { args } from '../core/process/args.js';
|
||||||
|
import render from '../core/ui/render.js';
|
||||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
|
import { PlayerClanData } from '../types/playerClanData.js';
|
||||||
|
|
||||||
const COMP_TANKS = [
|
const COMP_TANKS = [
|
||||||
// light tanks
|
// light tanks
|
||||||
@@ -36,7 +41,7 @@ const COMP_TANKS = [
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inDevelopment: false,
|
inDevelopment: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
@@ -54,8 +59,7 @@ export default {
|
|||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const tier = interaction.options.getInteger('tier')!;
|
const tier = interaction.options.getInteger('tier')!;
|
||||||
const name = interaction.options.getString('username')!;
|
const account = await getBlitzAccount(interaction);
|
||||||
const account = await getBlitzAccount(interaction, name);
|
|
||||||
const { id, server } = account;
|
const { id, server } = account;
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
@@ -64,40 +68,48 @@ export default {
|
|||||||
const tanks = tankStats
|
const tanks = tankStats
|
||||||
.map((tankData) => tankopedia[tankData.tank_id])
|
.map((tankData) => tankopedia[tankData.tank_id])
|
||||||
.filter((tank) => tank?.tier === tier);
|
.filter((tank) => tank?.tier === tier);
|
||||||
|
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||||
await interaction.editReply({
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
|
||||||
embeds: [
|
|
||||||
infoEmbed(
|
|
||||||
`${markdownEscape(accountInfo[id].nickname)}'s owned ${
|
|
||||||
tier === null ? '' : `tier ${tier} `
|
|
||||||
}tanks`,
|
|
||||||
`${
|
|
||||||
tanks.length === 0
|
|
||||||
? `No tanks found in tier ${tier}`
|
|
||||||
: tanks
|
|
||||||
.map(
|
|
||||||
(tank) =>
|
|
||||||
`${TANK_TYPE_EMOJIS[tank.type]} ${markdownEscape(
|
|
||||||
resolveTankName(tank.tank_id),
|
|
||||||
)} ${tank.is_premium ? '⭐' : ''}${
|
|
||||||
COMP_TANKS.includes(tank.tank_id) ? '🏆' : ''
|
|
||||||
}`,
|
|
||||||
)
|
|
||||||
.join('\n')
|
|
||||||
}\n\n**Legend**\n⭐ = Premium/Collector\n${
|
|
||||||
tier === 10 ? '🏆 = Comp Tank\n' : ''
|
|
||||||
}${TANK_TYPE_EMOJIS.heavyTank} = Heavy\n${
|
|
||||||
TANK_TYPE_EMOJIS.mediumTank
|
|
||||||
} = Medium\n${TANK_TYPE_EMOJIS.lightTank} = Light\n${
|
|
||||||
TANK_TYPE_EMOJIS['AT-SPG']
|
|
||||||
} = Tank Destroyer`,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Displaying ${accountInfo[id].nickname}'s owned tanks in tier ${tier}`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.time('ownedtanks');
|
||||||
|
const image = await render(
|
||||||
|
<Wrapper>
|
||||||
|
{/* TODO: integrate some of these into title bar */}
|
||||||
|
<TitleBar
|
||||||
|
name={accountInfo[id].nickname}
|
||||||
|
nameDiscriminator={`(Tier ${TIER_ROMAN_NUMERALS[tier]})`}
|
||||||
|
image={
|
||||||
|
clanData[id]?.clan
|
||||||
|
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
description={`Owned tanks • ${new Date().toDateString()} • ${
|
||||||
|
BLITZ_SERVERS[server]
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{tanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
|
||||||
|
|
||||||
|
{tanks.length > 0 && (
|
||||||
|
<Tanks.Root>
|
||||||
|
{tanks.map((tank) => (
|
||||||
|
<Tanks.Item
|
||||||
|
key={tank.tank_id}
|
||||||
|
name={tank.name}
|
||||||
|
type={tank.type}
|
||||||
|
icon={tank.images.normal}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Tanks.Root>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<PoweredByWargaming />
|
||||||
|
</Wrapper>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await interaction.editReply({ files: [image] });
|
||||||
|
console.timeEnd('ownedtanks');
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
@@ -36,8 +36,7 @@ export default {
|
|||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
||||||
const name = interaction.options.getString('username')!;
|
const account = await getBlitzAccount(interaction);
|
||||||
const account = await getBlitzAccount(interaction, name);
|
|
||||||
const { id, server } = account;
|
const { id, server } = account;
|
||||||
const accounts = await getWargamingResponse<AccountInfo>(
|
const accounts = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
@@ -76,8 +75,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Displaying player info for ${accounts[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ export default {
|
|||||||
.addStringOption(addUsernameOption),
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const name = interaction.options.getString('username')!;
|
const account = await getBlitzAccount(interaction);
|
||||||
const account = await getBlitzAccount(interaction, name);
|
|
||||||
const { id, server } = account;
|
const { id, server } = account;
|
||||||
const accounts = await getWargamingResponse<AccountInfo>(
|
const accounts = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
@@ -60,8 +59,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Displaying player info for ${accountInfo.nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -50,7 +50,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Clan search results for "${clan}"`);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -2,7 +2,7 @@ import { SlashCommandBuilder } from 'discord.js';
|
|||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import { usernameRegex } from '../core/blitz/listAccountsPanServer.js';
|
import { usernamePattern } from '../core/blitz/listAccountsPanServer.js';
|
||||||
import cmdName from '../core/interaction/cmdName.js';
|
import cmdName from '../core/interaction/cmdName.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||||
import addServerChoices from '../core/options/addServerChoices.js';
|
import addServerChoices from '../core/options/addServerChoices.js';
|
||||||
@@ -21,7 +21,7 @@ export default {
|
|||||||
.setDescription('Search players in a Blitz server')
|
.setDescription('Search players in a Blitz server')
|
||||||
.addStringOption(addServerChoices)
|
.addStringOption(addServerChoices)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
addUsernameOption(option).setAutocomplete(false),
|
addUsernameOption(option).setAutocomplete(false).setRequired(true),
|
||||||
)
|
)
|
||||||
.addIntegerOption((option) =>
|
.addIntegerOption((option) =>
|
||||||
option
|
option
|
||||||
@@ -36,7 +36,7 @@ export default {
|
|||||||
const name = interaction.options.getString('username')!;
|
const name = interaction.options.getString('username')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
const trimmedSearch = name.trim();
|
const trimmedSearch = name.trim();
|
||||||
const players = usernameRegex.test(trimmedSearch)
|
const players = usernamePattern.test(trimmedSearch)
|
||||||
? await getWargamingResponse<AccountList>(
|
? await getWargamingResponse<AccountList>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${
|
||||||
args['wargaming-application-id']
|
args['wargaming-application-id']
|
||||||
@@ -58,7 +58,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Player search results for "${name}"`);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -41,7 +41,5 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Tank search results for "${tank}"`);
|
|
||||||
},
|
},
|
||||||
} satisfies CommandRegistry;
|
} satisfies CommandRegistry;
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import GenericAllStats from '../components/GenericAllStats.js';
|
import GenericAllStats from '../components/GenericAllStats.js';
|
||||||
import NoBattlesInPeriod from '../components/NoBattlesInPeriod.js';
|
import NoData, { NoDataType } from '../components/NoData.js';
|
||||||
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
||||||
import TitleBar from '../components/TitleBar.js';
|
import TitleBar from '../components/TitleBar.js';
|
||||||
import Wrapper from '../components/Wrapper.js';
|
import Wrapper from '../components/Wrapper.js';
|
||||||
@@ -51,9 +51,7 @@ export default {
|
|||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const period = interaction.options.getString('period') as StatPeriod;
|
const period = interaction.options.getString('period') as StatPeriod;
|
||||||
const username = interaction.options.getString('username')!;
|
const { id, server } = await getBlitzAccount(interaction);
|
||||||
const blitzAccount = await getBlitzAccount(interaction, username);
|
|
||||||
const { id, server } = blitzAccount;
|
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
);
|
);
|
||||||
@@ -153,7 +151,7 @@ export default {
|
|||||||
} • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`}
|
} • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{stats.battles === 0 && <NoBattlesInPeriod />}
|
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
{stats.battles > 0 && (
|
{stats.battles > 0 && (
|
||||||
<GenericAllStats
|
<GenericAllStats
|
||||||
stats={stats}
|
stats={stats}
|
||||||
@@ -174,8 +172,6 @@ export default {
|
|||||||
files: [image],
|
files: [image],
|
||||||
components: [actionRow],
|
components: [actionRow],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing stats for ${accountInfo[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import GenericAllStats from '../components/GenericAllStats.js';
|
import GenericAllStats from '../components/GenericAllStats.js';
|
||||||
import NoBattlesInPeriod from '../components/NoBattlesInPeriod.js';
|
import NoData, { NoDataType } from '../components/NoData.js';
|
||||||
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
||||||
import TitleBar from '../components/TitleBar.js';
|
import TitleBar from '../components/TitleBar.js';
|
||||||
import Wrapper from '../components/Wrapper.js';
|
import Wrapper from '../components/Wrapper.js';
|
||||||
@@ -56,8 +56,7 @@ export default {
|
|||||||
interaction.options.getString('tank')!,
|
interaction.options.getString('tank')!,
|
||||||
);
|
);
|
||||||
const period = interaction.options.getString('period') as StatPeriod;
|
const period = interaction.options.getString('period') as StatPeriod;
|
||||||
const username = interaction.options.getString('username')!;
|
const blitzAccount = await getBlitzAccount(interaction);
|
||||||
const blitzAccount = await getBlitzAccount(interaction, username);
|
|
||||||
const { id, server } = blitzAccount;
|
const { id, server } = blitzAccount;
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
@@ -93,7 +92,7 @@ export default {
|
|||||||
} • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`}
|
} • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{stats.battles === 0 && <NoBattlesInPeriod />}
|
{stats.battles === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
{stats.battles > 0 && (
|
{stats.battles > 0 && (
|
||||||
<GenericAllStats
|
<GenericAllStats
|
||||||
stats={stats}
|
stats={stats}
|
||||||
@@ -117,8 +116,6 @@ export default {
|
|||||||
files: [image],
|
files: [image],
|
||||||
components: [actionRow],
|
components: [actionRow],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing stats for ${accountInfo[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
autocomplete: (interaction) => {
|
||||||
|
|||||||
+5
-10
@@ -4,10 +4,10 @@ import {
|
|||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import * as Breakdown from '../components/Breakdown/index.js';
|
import * as Breakdown from '../components/Breakdown/index.js';
|
||||||
import NoBattlesInPeriod from '../components/NoBattlesInPeriod.js';
|
import NoData, { NoDataType } from '../components/NoData.js';
|
||||||
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js';
|
||||||
import TitleBar from '../components/TitleBar.js';
|
import TitleBar from '../components/TitleBar.js';
|
||||||
import Wrapper, { WrapperSize } from '../components/Wrapper.js';
|
import Wrapper from '../components/Wrapper.js';
|
||||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||||
@@ -41,9 +41,7 @@ export default {
|
|||||||
.addStringOption(addUsernameOption),
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const username = interaction.options.getString('username')!;
|
const { id, server } = await getBlitzAccount(interaction);
|
||||||
const blitzAccount = await getBlitzAccount(interaction, username);
|
|
||||||
const { id, server } = blitzAccount;
|
|
||||||
const tankStatsOverTime = await getTankStatsOverTime(
|
const tankStatsOverTime = await getTankStatsOverTime(
|
||||||
interaction,
|
interaction,
|
||||||
server,
|
server,
|
||||||
@@ -162,7 +160,7 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const image = await render(
|
const image = await render(
|
||||||
<Wrapper size={WrapperSize.Roomy}>
|
<Wrapper>
|
||||||
<TitleBar
|
<TitleBar
|
||||||
name={accountInfo[id].nickname}
|
name={accountInfo[id].nickname}
|
||||||
nameDiscriminator={
|
nameDiscriminator={
|
||||||
@@ -178,12 +176,11 @@ export default {
|
|||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{rows.length === 0 && <NoBattlesInPeriod />}
|
{rows.length === 0 && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
{rows.length > 0 && <Breakdown.Root>{rows}</Breakdown.Root>}
|
{rows.length > 0 && <Breakdown.Root>{rows}</Breakdown.Root>}
|
||||||
|
|
||||||
<PoweredByBlitzStars />
|
<PoweredByBlitzStars />
|
||||||
</Wrapper>,
|
</Wrapper>,
|
||||||
WrapperSize.Roomy,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||||
@@ -195,8 +192,6 @@ export default {
|
|||||||
files: [image],
|
files: [image],
|
||||||
components: [actionRow],
|
components: [actionRow],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Showing daily breakdown for ${accountInfo[id].nickname}`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: usernameAutocomplete,
|
autocomplete: usernameAutocomplete,
|
||||||
|
|||||||
+3
-18
@@ -20,11 +20,10 @@ export default {
|
|||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
.setName(cmdName('verify'))
|
.setName(cmdName('verify'))
|
||||||
.setDescription("Set's the user's username to their in-game name")
|
.setDescription("Set's the user's username to their in-game name")
|
||||||
.addStringOption(addUsernameOption),
|
.addStringOption((option) => addUsernameOption(option).setRequired(true)),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const name = interaction.options.getString('username')!;
|
const blitzAccount = await getBlitzAccount(interaction);
|
||||||
const blitzAccount = await getBlitzAccount(interaction, name);
|
|
||||||
const { id, server } = blitzAccount;
|
const { id, server } = blitzAccount;
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||||
@@ -49,10 +48,6 @@ export default {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.warn(
|
|
||||||
`${interaction.user.username} failed to verify because of no nickname permission.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +79,6 @@ export default {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.warn(
|
|
||||||
`${interaction.user.username} failed to verify because of no manage roles permission.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +98,6 @@ export default {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
|
||||||
`${interaction.user.username} verified as ${accountInfo[id].nickname}${clanTag}`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
@@ -118,12 +105,10 @@ export default {
|
|||||||
.setColor(NEGATIVE_COLOR)
|
.setColor(NEGATIVE_COLOR)
|
||||||
.setTitle(`${interaction.user.username} failed to verify`)
|
.setTitle(`${interaction.user.username} failed to verify`)
|
||||||
.setDescription(
|
.setDescription(
|
||||||
"I can't change your nickname because you have higher permissions than me.",
|
"I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.warn('Failed to verify because of higher permissions.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export function Row({
|
|||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', gap: 16 }}>
|
<div style={{ display: 'flex', gap: 16 }}>
|
||||||
<RowDiscriminator name={name} icon={icon} />
|
<RowDiscriminator name={name} icon={icon} />
|
||||||
|
|
||||||
<RowStat
|
<RowStat
|
||||||
name="Winrate"
|
name="Winrate"
|
||||||
value={`${(winrate * 100).toFixed(2)}%`}
|
value={`${(winrate * 100).toFixed(2)}%`}
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ export function RowDiscriminator({ name, icon }: RowDiscriminatorProps) {
|
|||||||
{icon && (
|
{icon && (
|
||||||
<img
|
<img
|
||||||
src={icon}
|
src={icon}
|
||||||
style={{ width: '100%', flex: 1, objectFit: 'cover' }}
|
height={0}
|
||||||
|
style={{ flex: 1, width: '100%', objectFit: 'contain' }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
color: theme.colors.textLowContrast,
|
color: theme.colors.textLowContrast,
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { theme } from '../stitches.config.js';
|
|
||||||
|
|
||||||
export default function NoBattlesInPeriod() {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span style={{ fontSize: 16, color: theme.colors.textLowContrast }}>
|
|
||||||
No battles played in this period
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { theme } from '../stitches.config.js';
|
||||||
|
|
||||||
|
export enum NoDataType {
|
||||||
|
BattlesInPeriod,
|
||||||
|
PlayersInPeriod,
|
||||||
|
TanksFound,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NoDataProps {
|
||||||
|
type: NoDataType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NO_DATA_MESSAGES: Record<NoDataType, string> = {
|
||||||
|
[NoDataType.BattlesInPeriod]: 'No battles played in this period',
|
||||||
|
[NoDataType.PlayersInPeriod]: 'No players in this period',
|
||||||
|
[NoDataType.TanksFound]: 'No tanks found',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function NoData({ type }: NoDataProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span style={{ fontSize: 16, color: theme.colors.textLowContrast }}>
|
||||||
|
{NO_DATA_MESSAGES[type]}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { theme } from '../stitches.config.js';
|
||||||
|
|
||||||
|
export default function PoweredByWargaming() {
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', gap: 4, justifyContent: 'flex-end' }}>
|
||||||
|
<img
|
||||||
|
src="https://i.imgur.com/jADGWm0.png"
|
||||||
|
style={{ height: 16, width: 16 }}
|
||||||
|
/>
|
||||||
|
<span style={{ color: theme.colors.textLowContrast, fontSize: 16 }}>
|
||||||
|
Powered by Wargaming
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { TANK_ICONS, TankType } from '../../../core/blitz/tankopedia.js';
|
||||||
|
|
||||||
|
export interface ItemProps {
|
||||||
|
icon?: string;
|
||||||
|
type: TankType;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Item({ icon, type, name }: ItemProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 128,
|
||||||
|
height: 128,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{icon && <img src={icon} style={{ flex: 1, objectFit: 'contain' }} />}
|
||||||
|
|
||||||
|
<div style={{ display: 'flex', margin: 'auto', gap: 4 }}>
|
||||||
|
<img src={TANK_ICONS[type]} style={{ width: 14, height: 14 }} />
|
||||||
|
<span
|
||||||
|
style={{ fontSize: 16, textAlign: 'center', whiteSpace: 'nowrap' }}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
|
||||||
|
export interface RootProps {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Root({ children }: RootProps) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: 16,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './components/Item.js';
|
||||||
|
export * from './components/Root.js';
|
||||||
@@ -1,25 +1,11 @@
|
|||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { theme } from '../stitches.config.js';
|
import { theme } from '../stitches.config.js';
|
||||||
|
|
||||||
export enum WrapperSize {
|
|
||||||
Regular,
|
|
||||||
Roomy,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WrapperProps {
|
export interface WrapperProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
size?: WrapperSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WRAPPER_SIZE_WIDTHS: Record<WrapperSize, number> = {
|
export default function Wrapper({ children }: WrapperProps) {
|
||||||
[WrapperSize.Regular]: 640,
|
|
||||||
[WrapperSize.Roomy]: 800,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function Wrapper({
|
|
||||||
children,
|
|
||||||
size = WrapperSize.Regular,
|
|
||||||
}: WrapperProps) {
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -27,7 +13,7 @@ export default function Wrapper({
|
|||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
padding: 16,
|
padding: 16,
|
||||||
gap: 32,
|
gap: 32,
|
||||||
width: WRAPPER_SIZE_WIDTHS[size],
|
width: 640,
|
||||||
background: 'url(https://i.imgur.com/PhS06NJ.png)',
|
background: 'url(https://i.imgur.com/PhS06NJ.png)',
|
||||||
color: theme.colors.textHighContrast,
|
color: theme.colors.textHighContrast,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,14 +1,28 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { BlitzServer } from '../../constants/servers.js';
|
import { BlitzServer } from '../../constants/servers.js';
|
||||||
import errorEmbed from '../interaction/errorEmbed.js';
|
import errorWithCause from '../process/errorWithCause.js';
|
||||||
import listAccountsPanServer from './listAccountsPanServer.js';
|
import listAccountsPanServer, {
|
||||||
|
usernamePatternWithoutPosition,
|
||||||
|
} from './listAccountsPanServer.js';
|
||||||
|
|
||||||
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||||
|
|
||||||
export default async function getBlitzAccount(
|
export default async function getBlitzAccount(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
username: string,
|
|
||||||
) {
|
) {
|
||||||
|
const commandUsername = interaction.options.getString('username');
|
||||||
|
const displayName = interaction.guild?.members.cache
|
||||||
|
.get(interaction.user.id)
|
||||||
|
?.displayName.match(usernamePatternWithoutPosition)?.[0];
|
||||||
|
const username = commandUsername ?? displayName;
|
||||||
|
|
||||||
|
if (username === undefined) {
|
||||||
|
throw errorWithCause(
|
||||||
|
'Username could not be inferred',
|
||||||
|
"You didn't provide me a username in the command nor was I able to infer your Blitz username from your Discord nickname. Try providing a username manually in the command or using the `/verify` command to set your Discord nickname to your Blitz username.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (serverAndIdPattern.test(username)) {
|
if (serverAndIdPattern.test(username)) {
|
||||||
const [server, accountId] = username.split('/');
|
const [server, accountId] = username.split('/');
|
||||||
return { server: server as BlitzServer, id: Number(accountId) };
|
return { server: server as BlitzServer, id: Number(accountId) };
|
||||||
@@ -18,16 +32,10 @@ export default async function getBlitzAccount(
|
|||||||
if (accounts[0]) {
|
if (accounts[0]) {
|
||||||
return { server: accounts[0].server, id: accounts[0].account_id };
|
return { server: accounts[0].server, id: accounts[0].account_id };
|
||||||
} else {
|
} else {
|
||||||
await interaction.editReply({
|
throw errorWithCause(
|
||||||
embeds: [
|
|
||||||
errorEmbed(
|
|
||||||
'Could not find user',
|
'Could not find user',
|
||||||
`I couldn't find user \`${username}\`. Try selecting a username from the search result.`,
|
`I couldn't find user \`${username}\`. Try providing a valid username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`,
|
||||||
),
|
);
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
throw new Error(`Could not find user "${username}"`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { BlitzServer } from '../../constants/servers.js';
|
import { BlitzServer } from '../../constants/servers.js';
|
||||||
import errorEmbed from '../interaction/errorEmbed.js';
|
import errorWithCause from '../process/errorWithCause.js';
|
||||||
import { serverAndIdPattern } from './getBlitzAccount.js';
|
import { serverAndIdPattern } from './getBlitzAccount.js';
|
||||||
import listClansPanServer from './listClansPanServer.js';
|
import listClansPanServer from './listClansPanServer.js';
|
||||||
|
|
||||||
@@ -17,16 +17,10 @@ export default async function getBlitzClan(
|
|||||||
if (accounts[0]) {
|
if (accounts[0]) {
|
||||||
return { server: accounts[0].server, id: accounts[0].clan_id };
|
return { server: accounts[0].server, id: accounts[0].clan_id };
|
||||||
} else {
|
} else {
|
||||||
await interaction.editReply({
|
throw errorWithCause(
|
||||||
embeds: [
|
|
||||||
errorEmbed(
|
|
||||||
'Could not find clan',
|
'Could not find clan',
|
||||||
`I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`,
|
`I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`,
|
||||||
),
|
);
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
throw new Error(`Could not find clan "${clan}"`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
|
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
|
||||||
import { TanksStats } from '../../types/tanksStats.js';
|
import { TanksStats } from '../../types/tanksStats.js';
|
||||||
import errorEmbed from '../interaction/errorEmbed.js';
|
|
||||||
import { args } from '../process/args.js';
|
import { args } from '../process/args.js';
|
||||||
|
import errorWithCause from '../process/errorWithCause.js';
|
||||||
import getWargamingResponse from './getWargamingResponse.js';
|
import getWargamingResponse from './getWargamingResponse.js';
|
||||||
|
|
||||||
export default async function getTankStats(
|
export default async function getTankStats(
|
||||||
@@ -15,16 +15,10 @@ export default async function getTankStats(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (tankStats[id] === null) {
|
if (tankStats[id] === null) {
|
||||||
interaction.editReply({
|
throw errorWithCause(
|
||||||
embeds: [
|
|
||||||
errorEmbed(
|
|
||||||
'No tank stats available',
|
'No tank stats available',
|
||||||
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${BLITZ_SERVERS[server]} server.`,
|
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${BLITZ_SERVERS[server]} server.`,
|
||||||
),
|
);
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
throw new Error(`No tank stats available for ${server}/${id}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tankStats[id];
|
return tankStats[id];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Percentile } from '../../constants/percentiles.js';
|
import { Percentile } from '../../constants/percentiles.js';
|
||||||
|
|
||||||
const WN8_PERCENTILES: [number, Percentile][] = [
|
export const WN8_PERCENTILES: [number, Percentile][] = [
|
||||||
[0, Percentile.VeryBad],
|
[0, Percentile.VeryBad],
|
||||||
[300, Percentile.Bad],
|
[300, Percentile.Bad],
|
||||||
[450, Percentile.BelowAverage],
|
[450, Percentile.BelowAverage],
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||||
|
import errorWithCause from '../process/errorWithCause.js';
|
||||||
|
|
||||||
export default async function getWargamingResponse<Data extends object>(
|
export default async function getWargamingResponse<Data extends object>(
|
||||||
url: string,
|
url: string,
|
||||||
@@ -11,8 +12,9 @@ export default async function getWargamingResponse<Data extends object>(
|
|||||||
if (parsed.status === 'ok') {
|
if (parsed.status === 'ok') {
|
||||||
return parsed.data;
|
return parsed.data;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw errorWithCause(
|
||||||
`Wargaming response error status:"${parsed.status}" message: "${parsed.error.message}" url: "${url}"`,
|
`Wargaming response error status:"${parsed.status}"`,
|
||||||
|
`Message: "${parsed.error.message}"\nURL: "${url}"`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,14 +7,15 @@ export type AccountListWithServer = (Account & {
|
|||||||
server: 'com' | 'eu' | 'asia';
|
server: 'com' | 'eu' | 'asia';
|
||||||
})[];
|
})[];
|
||||||
|
|
||||||
export const usernameRegex = /^[a-zA-Z0-9_]{3,24}$/;
|
export const usernamePattern = /^[a-zA-Z0-9_]{3,24}$/;
|
||||||
|
export const usernamePatternWithoutPosition = /[a-zA-Z0-9_]{3,24}/;
|
||||||
|
|
||||||
export default async function listAccountsPanServer(search: string, limit = 9) {
|
export default async function listAccountsPanServer(search: string, limit = 9) {
|
||||||
const trimmedSearch = search.trim();
|
const trimmedSearch = search.trim();
|
||||||
const normalizedLimit = Math.round(limit / 3);
|
const normalizedLimit = Math.round(limit / 3);
|
||||||
const encodedSearch = encodeURIComponent(trimmedSearch);
|
const encodedSearch = encodeURIComponent(trimmedSearch);
|
||||||
|
|
||||||
if (usernameRegex.test(trimmedSearch)) {
|
if (usernamePattern.test(trimmedSearch)) {
|
||||||
return (
|
return (
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
getWargamingResponse<AccountList>(
|
getWargamingResponse<AccountList>(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import errorEmbed from '../interaction/errorEmbed.js';
|
import errorWithCause from '../process/errorWithCause.js';
|
||||||
import { TANKS, tankopedia } from './tankopedia.js';
|
import { TANKS, tankopedia } from './tankopedia.js';
|
||||||
|
|
||||||
export default async function resolveTankId(
|
export default async function resolveTankId(
|
||||||
@@ -13,16 +13,10 @@ export default async function resolveTankId(
|
|||||||
const searchResult = go(tank, TANKS, { keys: ['name'], limit: 1 });
|
const searchResult = go(tank, TANKS, { keys: ['name'], limit: 1 });
|
||||||
|
|
||||||
if (searchResult.length === 0) {
|
if (searchResult.length === 0) {
|
||||||
await interaction.editReply({
|
throw errorWithCause(
|
||||||
embeds: [
|
|
||||||
errorEmbed(
|
|
||||||
'Tank not found',
|
'Tank not found',
|
||||||
`Could not find tank by the name "${tank}".`,
|
`Could not find tank by the name "${tank}".`,
|
||||||
),
|
);
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
throw new Error(`Tank not found by name "${tank}"`);
|
|
||||||
} else {
|
} else {
|
||||||
return searchResult[0].obj.tank_id;
|
return searchResult[0].obj.tank_id;
|
||||||
}
|
}
|
||||||
@@ -30,16 +24,10 @@ export default async function resolveTankId(
|
|||||||
if (tankopedia[number]) {
|
if (tankopedia[number]) {
|
||||||
return number;
|
return number;
|
||||||
} else {
|
} else {
|
||||||
await interaction.editReply({
|
throw errorWithCause(
|
||||||
embeds: [
|
|
||||||
errorEmbed(
|
|
||||||
'Tank not found',
|
'Tank not found',
|
||||||
`Could not find tank by the ID "${number}".`,
|
`Could not find tank by the ID "${number}".`,
|
||||||
),
|
);
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
throw new Error(`Tank not found by ID "${number}"`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,8 @@
|
|||||||
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||||
|
|
||||||
/*
|
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
||||||
"1": {
|
|
||||||
"name": "T-34",
|
|
||||||
"nation": "ussr",
|
|
||||||
"is_premium": false,
|
|
||||||
"tier": 5,
|
|
||||||
"cost": {
|
|
||||||
"price_credit": 400000,
|
|
||||||
"price_gold": 0
|
|
||||||
},
|
|
||||||
"images": {
|
|
||||||
"preview": "/api/bs-cache/tank-icons/https%3A%2F%2Fglossary-eu-static.gcdn.co%2Ficons%2Fwotb%2Fcurrent%2Fuploaded%2Fvehicles%2Fhd_thumbnail%2FT-34.png",
|
|
||||||
"normal": "http://glossary-eu-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd/T-34.png"
|
|
||||||
},
|
|
||||||
"tank_id": 1,
|
|
||||||
"type": "mediumTank",
|
|
||||||
"description": "The legend of the Soviet armored forces and the most widely-produced Soviet tank of World War II, with a total of 33,805 vehicles manufactured. Three variants of this model were produced at several Soviet factories from 1940 through 1944."
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface Tankopedia {
|
export interface TankopediaEntry {
|
||||||
[id: number]: {
|
|
||||||
name: string;
|
name: string;
|
||||||
nation: string;
|
nation: string;
|
||||||
is_premium: boolean;
|
is_premium: boolean;
|
||||||
@@ -29,9 +10,12 @@ export interface Tankopedia {
|
|||||||
cost: { price_credit: number; price_gold: number };
|
cost: { price_credit: number; price_gold: number };
|
||||||
images: { preview: string; normal: string };
|
images: { preview: string; normal: string };
|
||||||
tank_id: number;
|
tank_id: number;
|
||||||
type: string;
|
type: TankType;
|
||||||
description: string;
|
description: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export interface Tankopedia {
|
||||||
|
[id: number]: TankopediaEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Caching tankopedia...');
|
console.log('Caching tankopedia...');
|
||||||
@@ -42,30 +26,26 @@ export const tankopedia = (
|
|||||||
).data;
|
).data;
|
||||||
console.log('Cached tankopedia');
|
console.log('Cached tankopedia');
|
||||||
|
|
||||||
/**
|
export const TANK_ICONS: Record<TankType, string> = {
|
||||||
* @deprecated
|
'AT-SPG': 'https://i.imgur.com/BIHSEH0.png',
|
||||||
*/
|
lightTank: 'https://i.imgur.com/CSNha5V.png',
|
||||||
export const TANK_TYPE_EMOJIS: Record<string, string> = {
|
mediumTank: 'https://i.imgur.com/wvf3ltm.png',
|
||||||
'AT-SPG': '🔽',
|
heavyTank: 'https://i.imgur.com/ECeqlZa.png',
|
||||||
heavyTank: '🇭',
|
};
|
||||||
mediumTank: '🇲',
|
|
||||||
lightTank: '🇱',
|
export const TIER_ROMAN_NUMERALS: Record<number, string> = {
|
||||||
|
1: 'I',
|
||||||
|
2: 'II',
|
||||||
|
3: 'III',
|
||||||
|
4: 'IV',
|
||||||
|
5: 'V',
|
||||||
|
6: 'VI',
|
||||||
|
7: 'VII',
|
||||||
|
8: 'VIII',
|
||||||
|
9: 'IX',
|
||||||
|
10: 'X',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TANK_IDS = Object.keys(tankopedia).map((id) => Number(id));
|
export const TANK_IDS = Object.keys(tankopedia).map((id) => Number(id));
|
||||||
export const TANKS = TANK_IDS.map((id) => tankopedia[id]);
|
export const TANKS = TANK_IDS.map((id) => tankopedia[id]);
|
||||||
export const TANK_NAMES = TANKS.map((tank) => tank.name);
|
export const TANK_NAMES = TANKS.map((tank) => tank.name);
|
||||||
|
|
||||||
// console.log('Encoding tank images...');
|
|
||||||
// await Promise.all(
|
|
||||||
// Object.entries(tankopedia).map(async ([, tank]) => {
|
|
||||||
// try {
|
|
||||||
// tank.images.normal = await URLToBase64(tank.images.normal);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.warn(
|
|
||||||
// `Failed to encode tank image for ${tank.images.normal}: ${error}`,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }),
|
|
||||||
// );
|
|
||||||
// console.log('Encoded tank images');
|
|
||||||
@@ -22,5 +22,5 @@ export default async function wargamingError(
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Wargaming returned an error`);
|
console.log(`Wargaming returned an error`);
|
||||||
handleError(error, client, command);
|
handleError(error, command);
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,5 @@ export default async function blitzStarsError(
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log(`BlitzStars returned an error`);
|
console.log(`BlitzStars returned an error`);
|
||||||
handleError(error, client, command);
|
handleError(error, command);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { EmbedBuilder } from 'discord.js';
|
import { EmbedBuilder } from 'discord.js';
|
||||||
import { NEGATIVE_COLOR } from '../../constants/colors.js';
|
import { NEGATIVE_COLOR } from '../../constants/colors.js';
|
||||||
|
|
||||||
export default function errorEmbed(title: string, description: string) {
|
export default function negativeEmbed(title: string, description: string) {
|
||||||
return new EmbedBuilder()
|
return new EmbedBuilder()
|
||||||
.setColor(NEGATIVE_COLOR)
|
.setColor(NEGATIVE_COLOR)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import errorEmbed from './errorEmbed.js';
|
import negativeEmbed from './negativeEmbed.js';
|
||||||
|
|
||||||
export const noMember = errorEmbed(
|
export const noMember = negativeEmbed(
|
||||||
'User of command is not a member',
|
'User of command is not a member',
|
||||||
'Discord claims that the user of this command does not have an account... strange!',
|
'Discord claims that the user of this command does not have an account... strange!',
|
||||||
);
|
);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import errorEmbed from './errorEmbed.js';
|
import negativeEmbed from './negativeEmbed.js';
|
||||||
|
|
||||||
export const notTrackedByBlitzStars = errorEmbed(
|
export const notTrackedByBlitzStars = negativeEmbed(
|
||||||
'No data to display',
|
'No data to display',
|
||||||
'Player is not tracked by BlitzStars.',
|
'Player is not tracked by BlitzStars.',
|
||||||
);
|
);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { EmbedBuilder } from 'discord.js';
|
||||||
|
import { POSITIVE_COLOR } from '../../constants/colors.js';
|
||||||
|
|
||||||
|
export default function positiveEmbed(title: string, description: string) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setColor(POSITIVE_COLOR)
|
||||||
|
.setTitle(title)
|
||||||
|
.setDescription(description);
|
||||||
|
}
|
||||||
@@ -4,6 +4,5 @@ export default function addUsernameOption(option: SlashCommandStringOption) {
|
|||||||
return option
|
return option
|
||||||
.setName('username')
|
.setName('username')
|
||||||
.setDescription('The username you use in Blitz')
|
.setDescription('The username you use in Blitz')
|
||||||
.setAutocomplete(true)
|
.setAutocomplete(true);
|
||||||
.setRequired(true);
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { argv } from 'process';
|
import { argv } from 'process';
|
||||||
|
import errorWithCause from './errorWithCause.js';
|
||||||
|
|
||||||
type ArgumentName = 'discord-token' | 'wargaming-application-id';
|
type ArgumentName = 'discord-token' | 'wargaming-application-id';
|
||||||
|
|
||||||
@@ -16,6 +17,9 @@ argv.forEach((arg) => {
|
|||||||
|
|
||||||
Object.keys(args).forEach((arg) => {
|
Object.keys(args).forEach((arg) => {
|
||||||
if (args[arg as ArgumentName] === '') {
|
if (args[arg as ArgumentName] === '') {
|
||||||
throw new Error(`Missing argument: ${arg}`);
|
throw errorWithCause(
|
||||||
|
`Missing argument: ${arg}`,
|
||||||
|
'Missing required auth key.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function errorWithCause(message: string, cause: string) {
|
||||||
|
return new Error(message, { cause });
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
export default async function URLToBase64(URL: string) {
|
|
||||||
const response = await fetch(URL);
|
|
||||||
const blob = await response.arrayBuffer();
|
|
||||||
const base64 = `data:${response.headers.get(
|
|
||||||
'content-type',
|
|
||||||
)};base64,${Buffer.from(blob).toString('base64')}`;
|
|
||||||
|
|
||||||
return base64;
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ import { Resvg } from '@resvg/resvg-js';
|
|||||||
import { readFile } from 'fs';
|
import { readFile } from 'fs';
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import satori from 'satori';
|
import satori from 'satori';
|
||||||
import { WRAPPER_SIZE_WIDTHS, WrapperSize } from '../../components/Wrapper.js';
|
|
||||||
|
|
||||||
const FONT_NAME = 'Roboto';
|
const FONT_NAME = 'Roboto';
|
||||||
const FONT_FILES = ['Roboto', 'Roboto-Bold', 'Roboto-Black'];
|
const FONT_FILES = ['Roboto', 'Roboto-Bold', 'Roboto-Black'];
|
||||||
@@ -21,12 +20,9 @@ const [robotoFlex, robotoFlexBold, robotoFlexBlack] = await Promise.all(
|
|||||||
);
|
);
|
||||||
console.log('Fonts imported');
|
console.log('Fonts imported');
|
||||||
|
|
||||||
export default async function render(
|
export default async function render(element: ReactNode) {
|
||||||
element: ReactNode,
|
|
||||||
size: WrapperSize = WrapperSize.Regular,
|
|
||||||
) {
|
|
||||||
const svg = await satori(element, {
|
const svg = await satori(element, {
|
||||||
width: WRAPPER_SIZE_WIDTHS[size],
|
width: 640,
|
||||||
fonts: [
|
fonts: [
|
||||||
{ data: robotoFlex, name: FONT_NAME, weight: 400 },
|
{ data: robotoFlex, name: FONT_NAME, weight: 400 },
|
||||||
{ data: robotoFlexBold, name: FONT_NAME, weight: 700 },
|
{ data: robotoFlexBold, name: FONT_NAME, weight: 700 },
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
import { Client, EmbedBuilder, TextChannel } from 'discord.js';
|
import { EmbedBuilder, TextChannel } from 'discord.js';
|
||||||
import discord from '../../discord.json' assert { type: 'json' };
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||||
import isDev from '../core/process/isDev.js';
|
import isDev from '../core/process/isDev.js';
|
||||||
@@ -7,7 +7,7 @@ import { client } from '../index.js';
|
|||||||
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
||||||
const CLIENT_ERROR_EVENTS = ['error'];
|
const CLIENT_ERROR_EVENTS = ['error'];
|
||||||
|
|
||||||
export function handleError(error: Error, client: Client, command: string) {
|
export function handleError(error: Error, command: string) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -31,10 +31,10 @@ export function handleError(error: Error, client: Client, command: string) {
|
|||||||
export function registerErrorHandlers() {
|
export function registerErrorHandlers() {
|
||||||
if (!isDev()) {
|
if (!isDev()) {
|
||||||
PROCESS_ERROR_EVENTS.forEach((name) =>
|
PROCESS_ERROR_EVENTS.forEach((name) =>
|
||||||
process.on(name, (error) => handleError(error, client, 'process error')),
|
process.on(name, (error) => handleError(error, 'process error')),
|
||||||
);
|
);
|
||||||
CLIENT_ERROR_EVENTS.forEach((name) =>
|
CLIENT_ERROR_EVENTS.forEach((name) =>
|
||||||
client.on(name, (error) => handleError(error, client, 'client error')),
|
client.on(name, (error) => handleError(error, 'client error')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
|
ActionRowBuilder,
|
||||||
AutocompleteInteraction,
|
AutocompleteInteraction,
|
||||||
|
ButtonBuilder,
|
||||||
|
ButtonStyle,
|
||||||
CacheType,
|
CacheType,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
Collection,
|
Collection,
|
||||||
@@ -11,9 +14,11 @@ import {
|
|||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
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 negativeEmbed from '../core/interaction/negativeEmbed.js';
|
||||||
import { args } from '../core/process/args.js';
|
import { args } from '../core/process/args.js';
|
||||||
import getClientId from '../core/process/getClientId.js';
|
import getClientId from '../core/process/getClientId.js';
|
||||||
import isDev from '../core/process/isDev.js';
|
import isDev from '../core/process/isDev.js';
|
||||||
|
import { handleError } from './error.js';
|
||||||
|
|
||||||
export interface CommandRegistry {
|
export interface CommandRegistry {
|
||||||
inDevelopment: boolean;
|
inDevelopment: boolean;
|
||||||
@@ -58,11 +63,19 @@ try {
|
|||||||
console.log(`Successfully refreshed ${publicData.length} public command(s).`);
|
console.log(`Successfully refreshed ${publicData.length} public command(s).`);
|
||||||
|
|
||||||
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
|
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
|
||||||
const guildData = (await rest.put(
|
const guildData = [
|
||||||
|
...((await rest.put(
|
||||||
Routes.applicationGuildCommands(getClientId(), discord.sklld_guild_id),
|
Routes.applicationGuildCommands(getClientId(), discord.sklld_guild_id),
|
||||||
{ body: guildCommands },
|
{ body: guildCommands },
|
||||||
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
|
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[]),
|
||||||
console.log(`Successfully refreshed ${guildData.length} guild command(s).`);
|
...((await rest.put(
|
||||||
|
Routes.applicationGuildCommands(getClientId(), discord.tres_guild_id),
|
||||||
|
{ body: guildCommands },
|
||||||
|
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[]),
|
||||||
|
];
|
||||||
|
console.log(
|
||||||
|
`Successfully refreshed ${guildData.length / 2} guild command(s).`,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
@@ -93,6 +106,30 @@ export default async function interactionCreate(
|
|||||||
|
|
||||||
console.log(interaction.toString());
|
console.log(interaction.toString());
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
command.execute(interaction);
|
|
||||||
|
try {
|
||||||
|
await command.execute(interaction);
|
||||||
|
} catch (error) {
|
||||||
|
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel('Get Help on Discord Server')
|
||||||
|
.setURL('https://discord.gg/nDt7AjGJQH')
|
||||||
|
.setStyle(ButtonStyle.Link),
|
||||||
|
);
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
negativeEmbed(
|
||||||
|
(error as Error).message,
|
||||||
|
`${
|
||||||
|
(error as Error).cause ?? 'No further information is available.'
|
||||||
|
}`,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
components: [actionRow],
|
||||||
|
});
|
||||||
|
|
||||||
|
handleError(error as Error, interaction.commandName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user