From db881f44d4577d34ff097e7b08893a065ac7322a Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 3 Jun 2023 18:05:09 +0000 Subject: [PATCH 01/10] feat: username inferring from discord nickname --- package.json | 2 +- src/commands/debug.ts | 2 +- src/commands/help.ts | 2 +- src/commands/inactive.ts | 2 +- src/commands/ownedtanks.ts | 5 ++--- src/commands/playerachievements.ts | 5 ++--- src/commands/playerinfo.ts | 5 ++--- src/commands/searchclans.ts | 2 +- src/commands/searchplayers.ts | 8 +++---- src/commands/searchtanks.ts | 2 +- src/commands/stats.tsx | 5 ++--- src/commands/tankstats.tsx | 5 ++--- src/commands/today.tsx | 6 ++---- src/commands/verify.ts | 9 ++++---- src/core/blitz/getBlitzAccount.ts | 28 ++++++++++++++++++++++--- src/core/blitz/listAccountsPanServer.ts | 5 +++-- src/core/options/addUsernameOption.ts | 3 +-- 17 files changed, 55 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 3ee9576c2..5b17c3ff9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blitzkrieg", - "version": "1.5.4", + "version": "1.6.0", "description": "", "main": "index.js", "type": "module", diff --git a/src/commands/debug.ts b/src/commands/debug.ts index e7630f90d..17afcc4e8 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -13,7 +13,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/help.ts b/src/commands/help.ts index 6e50b7798..f9cc7a4bd 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -11,7 +11,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts index 9fc91a20d..38cdc0f9e 100644 --- a/src/commands/inactive.ts +++ b/src/commands/inactive.ts @@ -15,7 +15,7 @@ const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/ownedtanks.ts b/src/commands/ownedtanks.ts index 7e9e41ea5..26205ca59 100644 --- a/src/commands/ownedtanks.ts +++ b/src/commands/ownedtanks.ts @@ -36,7 +36,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -54,8 +54,7 @@ export default { async execute(interaction) { const tier = interaction.options.getInteger('tier')!; - const name = interaction.options.getString('username')!; - const account = await getBlitzAccount(interaction, name); + const account = await getBlitzAccount(interaction); const { id, server } = account; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index 59b3c0048..38fb9f084 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -17,7 +17,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -36,8 +36,7 @@ export default { async execute(interaction) { const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy; - const name = interaction.options.getString('username')!; - const account = await getBlitzAccount(interaction, name); + const account = await getBlitzAccount(interaction); const { id, server } = account; const accounts = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index bb0f5634d..179d7c295 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -13,7 +13,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -22,8 +22,7 @@ export default { .addStringOption(addUsernameOption), async execute(interaction) { - const name = interaction.options.getString('username')!; - const account = await getBlitzAccount(interaction, name); + const account = await getBlitzAccount(interaction); const { id, server } = account; const accounts = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index a52e50ddf..b680c6d27 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 9ea41a53a..e996b85a8 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -2,7 +2,7 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.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 infoEmbed from '../core/interaction/infoEmbed.js'; import addServerChoices from '../core/options/addServerChoices.js'; @@ -13,7 +13,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -21,7 +21,7 @@ export default { .setDescription('Search players in a Blitz server') .addStringOption(addServerChoices) .addStringOption((option) => - addUsernameOption(option).setAutocomplete(false), + addUsernameOption(option).setAutocomplete(false).setRequired(true), ) .addIntegerOption((option) => option @@ -36,7 +36,7 @@ export default { const name = interaction.options.getString('username')!; const limit = interaction.options.getInteger('limit') ?? 25; const trimmedSearch = name.trim(); - const players = usernameRegex.test(trimmedSearch) + const players = usernamePattern.test(trimmedSearch) ? await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/list/?application_id=${ args['wargaming-application-id'] diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index f14361372..49610e1f0 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index f24192947..5c9f0ff83 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -40,7 +40,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -51,8 +51,7 @@ export default { async execute(interaction) { const period = interaction.options.getString('period') as StatPeriod; - const username = interaction.options.getString('username')!; - const blitzAccount = await getBlitzAccount(interaction, username); + const blitzAccount = await getBlitzAccount(interaction); const { id, server } = blitzAccount; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index 305b420f3..6bf9b949a 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -40,7 +40,7 @@ import { AccountInfo, AllStats } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -56,8 +56,7 @@ export default { interaction.options.getString('tank')!, ); const period = interaction.options.getString('period') as StatPeriod; - const username = interaction.options.getString('username')!; - const blitzAccount = await getBlitzAccount(interaction, username); + const blitzAccount = await getBlitzAccount(interaction); const { id, server } = blitzAccount; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, diff --git a/src/commands/today.tsx b/src/commands/today.tsx index c6f3e4d4d..bef142af5 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -32,7 +32,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -41,9 +41,7 @@ export default { .addStringOption(addUsernameOption), async execute(interaction) { - const username = interaction.options.getString('username')!; - const blitzAccount = await getBlitzAccount(interaction, username); - const { id, server } = blitzAccount; + const { id, server } = await getBlitzAccount(interaction); const tankStatsOverTime = await getTankStatsOverTime( interaction, server, diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 41c89157e..163339825 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -14,17 +14,16 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() .setName(cmdName('verify')) .setDescription("Set's the user's username to their in-game name") - .addStringOption(addUsernameOption), + .addStringOption((option) => addUsernameOption(option).setRequired(true)), async execute(interaction) { - const name = interaction.options.getString('username')!; - const blitzAccount = await getBlitzAccount(interaction, name); + const blitzAccount = await getBlitzAccount(interaction); const { id, server } = blitzAccount; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, @@ -118,7 +117,7 @@ export default { .setColor(NEGATIVE_COLOR) .setTitle(`${interaction.user.username} failed to verify`) .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.", ), ], }); diff --git a/src/core/blitz/getBlitzAccount.ts b/src/core/blitz/getBlitzAccount.ts index e0fe4c4ea..5b3c8e72c 100644 --- a/src/core/blitz/getBlitzAccount.ts +++ b/src/core/blitz/getBlitzAccount.ts @@ -1,14 +1,36 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BlitzServer } from '../../constants/servers.js'; import errorEmbed from '../interaction/errorEmbed.js'; -import listAccountsPanServer from './listAccountsPanServer.js'; +import listAccountsPanServer, { + usernamePatternWithoutPosition, +} from './listAccountsPanServer.js'; export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/; export default async function getBlitzAccount( interaction: ChatInputCommandInteraction, - 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) { + await interaction.editReply({ + embeds: [ + errorEmbed( + '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.", + ), + ], + }); + + throw new Error( + `No username provided commandUsername: ${commandUsername} displayName: ${displayName} username: ${username}`, + ); + } + if (serverAndIdPattern.test(username)) { const [server, accountId] = username.split('/'); return { server: server as BlitzServer, id: Number(accountId) }; @@ -22,7 +44,7 @@ export default async function getBlitzAccount( embeds: [ errorEmbed( '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 username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`, ), ], }); diff --git a/src/core/blitz/listAccountsPanServer.ts b/src/core/blitz/listAccountsPanServer.ts index 70643e540..13137e432 100644 --- a/src/core/blitz/listAccountsPanServer.ts +++ b/src/core/blitz/listAccountsPanServer.ts @@ -7,14 +7,15 @@ export type AccountListWithServer = (Account & { 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) { const trimmedSearch = search.trim(); const normalizedLimit = Math.round(limit / 3); const encodedSearch = encodeURIComponent(trimmedSearch); - if (usernameRegex.test(trimmedSearch)) { + if (usernamePattern.test(trimmedSearch)) { return ( await Promise.all([ getWargamingResponse( diff --git a/src/core/options/addUsernameOption.ts b/src/core/options/addUsernameOption.ts index 8c0a45911..d9f323d77 100644 --- a/src/core/options/addUsernameOption.ts +++ b/src/core/options/addUsernameOption.ts @@ -4,6 +4,5 @@ export default function addUsernameOption(option: SlashCommandStringOption) { return option .setName('username') .setDescription('The username you use in Blitz') - .setAutocomplete(true) - .setRequired(true); + .setAutocomplete(true); } From 1d0b428921fc366808d7868676e5d9875e567bf6 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 3 Jun 2023 18:25:33 +0000 Subject: [PATCH 02/10] fix: skip encoding tanks without images --- src/commands/debug.ts | 2 +- src/commands/help.ts | 2 +- src/commands/inactive.ts | 2 +- src/commands/ownedtanks.ts | 2 +- src/commands/playerachievements.ts | 2 +- src/commands/playerinfo.ts | 2 +- src/commands/searchclans.ts | 2 +- src/commands/searchplayers.ts | 2 +- src/commands/searchtanks.ts | 2 +- src/commands/stats.tsx | 2 +- src/commands/tankstats.tsx | 2 +- src/commands/today.tsx | 2 +- src/commands/verify.ts | 2 +- src/core/blitz/tankopedia.ts | 65 ++++++++++-------------------- 14 files changed, 35 insertions(+), 56 deletions(-) diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 17afcc4e8..e7630f90d 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -13,7 +13,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/help.ts b/src/commands/help.ts index f9cc7a4bd..6e50b7798 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -11,7 +11,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts index 38cdc0f9e..9fc91a20d 100644 --- a/src/commands/inactive.ts +++ b/src/commands/inactive.ts @@ -15,7 +15,7 @@ const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/ownedtanks.ts b/src/commands/ownedtanks.ts index 26205ca59..0e05cd92f 100644 --- a/src/commands/ownedtanks.ts +++ b/src/commands/ownedtanks.ts @@ -36,7 +36,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index 38fb9f084..a985f216f 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -17,7 +17,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index 179d7c295..e4de7de85 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -13,7 +13,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index b680c6d27..a52e50ddf 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index e996b85a8..b6e16a3fe 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -13,7 +13,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index 49610e1f0..f14361372 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 5c9f0ff83..7fec4bc15 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -40,7 +40,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index 6bf9b949a..fd73f439b 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -40,7 +40,7 @@ import { AccountInfo, AllStats } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/today.tsx b/src/commands/today.tsx index bef142af5..dfd6bb634 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -32,7 +32,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 163339825..57ab15ab6 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index 3889df0c3..b37a7a694 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -1,37 +1,20 @@ import { WargamingResponse } from '../../types/wargamingResponse.js'; +import URLToBase64 from '../ui/URLToBase64.js'; -/* -"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 TankopediaEntry { + name: string; + nation: string; + is_premium: boolean; + tier: number; + cost: { price_credit: number; price_gold: number }; + images: { preview: string; normal: string }; + tank_id: number; + type: string; + description: string; +} export interface Tankopedia { - [id: number]: { - name: string; - nation: string; - is_premium: boolean; - tier: number; - cost: { price_credit: number; price_gold: number }; - images: { preview: string; normal: string }; - tank_id: number; - type: string; - description: string; - }; + [id: number]: TankopediaEntry; } console.log('Caching tankopedia...'); @@ -56,16 +39,12 @@ export const TANK_IDS = Object.keys(tankopedia).map((id) => Number(id)); export const TANKS = TANK_IDS.map((id) => tankopedia[id]); 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'); +console.log('Encoding tank images...'); +await Promise.all( + Object.entries(tankopedia).map(async ([, tank]) => { + if (tank.images.normal) { + tank.images.normal = await URLToBase64(tank.images.normal); + } + }), +); +console.log('Encoded tank images'); From 804fa58d274169631f8fbc3bdbb0a29fe716d439 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sun, 4 Jun 2023 00:01:10 +0000 Subject: [PATCH 03/10] feat: eligible command --- .vscode/settings.json | 1 + src/commands/eligible.ts | 179 ++++++++++++++++++ src/commands/stats.tsx | 3 +- src/core/blitz/getBlitzAccount.ts | 6 +- src/core/blitz/getBlitzClan.ts | 4 +- src/core/blitz/getTankStats.ts | 4 +- src/core/blitz/getWN8Percentile.ts | 2 +- src/core/blitz/resolveTankId.ts | 6 +- .../{errorEmbed.ts => negativeEmbed.ts} | 2 +- src/core/interaction/noMember.ts | 4 +- .../interaction/notTrackedByBlitzStars.ts | 4 +- src/core/interaction/positiveEmbed.ts | 9 + src/events/interactionCreate.ts | 18 +- 13 files changed, 219 insertions(+), 23 deletions(-) create mode 100644 src/commands/eligible.ts rename src/core/interaction/{errorEmbed.ts => negativeEmbed.ts} (74%) create mode 100644 src/core/interaction/positiveEmbed.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 862f08758..3c3d7a00f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "ownedtanks", "Resvg", "searchplayers", + "SKLLD", "Smri", "strvk", "tankopedia", diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts new file mode 100644 index 000000000..56c16db5f --- /dev/null +++ b/src/commands/eligible.ts @@ -0,0 +1,179 @@ +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 = { + SKLLD: 'Skilled', + SMRI: 'Samurai', +}; + +export default { + inProduction: true, + inDevelopment: true, + 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( + `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)], + }); + + console.log( + `Displaying ${server}/${id}'s eligibility information for ${clan}`, + ); + }, +} satisfies CommandRegistry; diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 7fec4bc15..866c6c8ce 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -51,8 +51,7 @@ export default { async execute(interaction) { const period = interaction.options.getString('period') as StatPeriod; - const blitzAccount = await getBlitzAccount(interaction); - const { id, server } = blitzAccount; + const { id, server } = await getBlitzAccount(interaction); const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); diff --git a/src/core/blitz/getBlitzAccount.ts b/src/core/blitz/getBlitzAccount.ts index 5b3c8e72c..7a16d341b 100644 --- a/src/core/blitz/getBlitzAccount.ts +++ b/src/core/blitz/getBlitzAccount.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BlitzServer } from '../../constants/servers.js'; -import errorEmbed from '../interaction/errorEmbed.js'; +import negativeEmbed from '../interaction/negativeEmbed.js'; import listAccountsPanServer, { usernamePatternWithoutPosition, } from './listAccountsPanServer.js'; @@ -19,7 +19,7 @@ export default async function getBlitzAccount( if (username === undefined) { await interaction.editReply({ embeds: [ - errorEmbed( + negativeEmbed( '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.", ), @@ -42,7 +42,7 @@ export default async function getBlitzAccount( } else { await interaction.editReply({ embeds: [ - errorEmbed( + negativeEmbed( 'Could not find user', `I couldn't find user \`${username}\`. Try providing a username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`, ), diff --git a/src/core/blitz/getBlitzClan.ts b/src/core/blitz/getBlitzClan.ts index 343711c11..e15c103be 100644 --- a/src/core/blitz/getBlitzClan.ts +++ b/src/core/blitz/getBlitzClan.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BlitzServer } from '../../constants/servers.js'; -import errorEmbed from '../interaction/errorEmbed.js'; +import negativeEmbed from '../interaction/negativeEmbed.js'; import { serverAndIdPattern } from './getBlitzAccount.js'; import listClansPanServer from './listClansPanServer.js'; @@ -19,7 +19,7 @@ export default async function getBlitzClan( } else { await interaction.editReply({ embeds: [ - errorEmbed( + negativeEmbed( 'Could not find clan', `I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`, ), diff --git a/src/core/blitz/getTankStats.ts b/src/core/blitz/getTankStats.ts index 6569c694c..d41b3a9c6 100644 --- a/src/core/blitz/getTankStats.ts +++ b/src/core/blitz/getTankStats.ts @@ -1,7 +1,7 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js'; import { TanksStats } from '../../types/tanksStats.js'; -import errorEmbed from '../interaction/errorEmbed.js'; +import negativeEmbed from '../interaction/negativeEmbed.js'; import { args } from '../process/args.js'; import getWargamingResponse from './getWargamingResponse.js'; @@ -17,7 +17,7 @@ export default async function getTankStats( if (tankStats[id] === null) { interaction.editReply({ embeds: [ - errorEmbed( + negativeEmbed( '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.`, ), diff --git a/src/core/blitz/getWN8Percentile.ts b/src/core/blitz/getWN8Percentile.ts index 870bf83d4..e153cad4e 100644 --- a/src/core/blitz/getWN8Percentile.ts +++ b/src/core/blitz/getWN8Percentile.ts @@ -1,6 +1,6 @@ import { Percentile } from '../../constants/percentiles.js'; -const WN8_PERCENTILES: [number, Percentile][] = [ +export const WN8_PERCENTILES: [number, Percentile][] = [ [0, Percentile.VeryBad], [300, Percentile.Bad], [450, Percentile.BelowAverage], diff --git a/src/core/blitz/resolveTankId.ts b/src/core/blitz/resolveTankId.ts index 95507f5d9..c480d0fee 100644 --- a/src/core/blitz/resolveTankId.ts +++ b/src/core/blitz/resolveTankId.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { go } from 'fuzzysort'; -import errorEmbed from '../interaction/errorEmbed.js'; +import negativeEmbed from '../interaction/negativeEmbed.js'; import { TANKS, tankopedia } from './tankopedia.js'; export default async function resolveTankId( @@ -15,7 +15,7 @@ export default async function resolveTankId( if (searchResult.length === 0) { await interaction.editReply({ embeds: [ - errorEmbed( + negativeEmbed( 'Tank not found', `Could not find tank by the name "${tank}".`, ), @@ -32,7 +32,7 @@ export default async function resolveTankId( } else { await interaction.editReply({ embeds: [ - errorEmbed( + negativeEmbed( 'Tank not found', `Could not find tank by the ID "${number}".`, ), diff --git a/src/core/interaction/errorEmbed.ts b/src/core/interaction/negativeEmbed.ts similarity index 74% rename from src/core/interaction/errorEmbed.ts rename to src/core/interaction/negativeEmbed.ts index e4e6ed1e1..f01024c82 100644 --- a/src/core/interaction/errorEmbed.ts +++ b/src/core/interaction/negativeEmbed.ts @@ -1,7 +1,7 @@ import { EmbedBuilder } from 'discord.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() .setColor(NEGATIVE_COLOR) .setTitle(title) diff --git a/src/core/interaction/noMember.ts b/src/core/interaction/noMember.ts index 9737ece2a..6b2071220 100644 --- a/src/core/interaction/noMember.ts +++ b/src/core/interaction/noMember.ts @@ -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', 'Discord claims that the user of this command does not have an account... strange!', ); diff --git a/src/core/interaction/notTrackedByBlitzStars.ts b/src/core/interaction/notTrackedByBlitzStars.ts index 907f3342c..566551cf3 100644 --- a/src/core/interaction/notTrackedByBlitzStars.ts +++ b/src/core/interaction/notTrackedByBlitzStars.ts @@ -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', 'Player is not tracked by BlitzStars.', ); diff --git a/src/core/interaction/positiveEmbed.ts b/src/core/interaction/positiveEmbed.ts new file mode 100644 index 000000000..29a86adc5 --- /dev/null +++ b/src/core/interaction/positiveEmbed.ts @@ -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); +} diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index b64e953ac..5fb7c2b75 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -58,11 +58,19 @@ try { console.log(`Successfully refreshed ${publicData.length} public command(s).`); console.log(`Refreshing ${guildCommands.length} guild command(s).`); - const guildData = (await rest.put( - Routes.applicationGuildCommands(getClientId(), discord.sklld_guild_id), - { body: guildCommands }, - )) as RESTPostAPIChatInputApplicationCommandsJSONBody[]; - console.log(`Successfully refreshed ${guildData.length} guild command(s).`); + const guildData = [ + ...((await rest.put( + Routes.applicationGuildCommands(getClientId(), discord.sklld_guild_id), + { body: guildCommands }, + )) as RESTPostAPIChatInputApplicationCommandsJSONBody[]), + ...((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) { console.error(error); } From 58c68968e7741be210df0f3b3256eec900fe9fbb Mon Sep 17 00:00:00 2001 From: tresabhi Date: Mon, 5 Jun 2023 17:46:22 +0000 Subject: [PATCH 04/10] feat: encode images on a separate thread --- package.json | 1 + src/commands/debug.ts | 2 -- src/commands/eligible.ts | 4 --- src/commands/help.ts | 2 -- src/commands/inactive.ts | 4 --- src/commands/ownedtanks.ts | 4 --- src/commands/playerachievements.ts | 2 -- src/commands/playerinfo.ts | 2 -- src/commands/searchclans.ts | 2 -- src/commands/searchplayers.ts | 2 -- src/commands/searchtanks.ts | 2 -- src/commands/stats.tsx | 1 - src/commands/tankstats.tsx | 2 -- src/commands/today.tsx | 1 - src/commands/verify.ts | 14 --------- src/core/blitz/tankopedia.ts | 46 +++++++++++++++++++++++------- src/core/ui/URLToBase64.ts | 9 ------ yarn.lock | 5 ++++ 18 files changed, 42 insertions(+), 63 deletions(-) delete mode 100644 src/core/ui/URLToBase64.ts diff --git a/package.json b/package.json index 5b17c3ff9..545aed3fe 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "fuzzysort": "^2.0.4", "lodash.startcase": "^4.4.0", "markdown-escape": "^2.0.0", + "node-worker-threads-pool": "^1.5.1", "react": "^18.2.0", "satori": "^0.9.1" }, diff --git a/src/commands/debug.ts b/src/commands/debug.ts index e7630f90d..278060b45 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -46,7 +46,5 @@ export default { ), ], }); - - console.log("Displaying bot's debug information"); }, } satisfies CommandRegistry; diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 56c16db5f..24060f7c8 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -171,9 +171,5 @@ export default { ? [positiveEmbed(title, body)] : [negativeEmbed(title, body)], }); - - console.log( - `Displaying ${server}/${id}'s eligibility information for ${clan}`, - ); }, } satisfies CommandRegistry; diff --git a/src/commands/help.ts b/src/commands/help.ts index 6e50b7798..0b1511cb8 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -39,7 +39,5 @@ export default { ), ], }); - - console.log('Displaying help information'); }, } satisfies CommandRegistry; diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts index 9fc91a20d..1b8b5d257 100644 --- a/src/commands/inactive.ts +++ b/src/commands/inactive.ts @@ -83,10 +83,6 @@ export default { ), ], }); - - console.log( - `Displaying inactive members in ${clanInfo[id].name} for ${threshold} days`, - ); }, autocomplete: clanAutocomplete, diff --git a/src/commands/ownedtanks.ts b/src/commands/ownedtanks.ts index 0e05cd92f..214b37e81 100644 --- a/src/commands/ownedtanks.ts +++ b/src/commands/ownedtanks.ts @@ -93,10 +93,6 @@ export default { ), ], }); - - console.log( - `Displaying ${accountInfo[id].nickname}'s owned tanks in tier ${tier}`, - ); }, autocomplete: usernameAutocomplete, diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index a985f216f..536e1bed9 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -75,8 +75,6 @@ export default { ), ], }); - - console.log(`Displaying player info for ${accounts[id].nickname}`); }, autocomplete: usernameAutocomplete, diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index e4de7de85..82c83a05d 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -59,8 +59,6 @@ export default { ), ], }); - - console.log(`Displaying player info for ${accountInfo.nickname}`); }, autocomplete: usernameAutocomplete, diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index a52e50ddf..db07881eb 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -50,7 +50,5 @@ export default { ), ], }); - - console.log(`Clan search results for "${clan}"`); }, } satisfies CommandRegistry; diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index b6e16a3fe..d0f731cd8 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -58,7 +58,5 @@ export default { ), ], }); - - console.log(`Player search results for "${name}"`); }, } satisfies CommandRegistry; diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index f14361372..2d525cdc0 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -41,7 +41,5 @@ export default { ), ], }); - - console.log(`Tank search results for "${tank}"`); }, } satisfies CommandRegistry; diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 866c6c8ce..06235a9a9 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -173,7 +173,6 @@ export default { components: [actionRow], }); - console.log(`Showing stats for ${accountInfo[id].nickname}`); }, autocomplete: usernameAutocomplete, diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index fd73f439b..c1b62f507 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -116,8 +116,6 @@ export default { files: [image], components: [actionRow], }); - - console.log(`Showing stats for ${accountInfo[id].nickname}`); }, autocomplete: (interaction) => { diff --git a/src/commands/today.tsx b/src/commands/today.tsx index dfd6bb634..b8212150e 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -194,7 +194,6 @@ export default { components: [actionRow], }); - console.log(`Showing daily breakdown for ${accountInfo[id].nickname}`); }, autocomplete: usernameAutocomplete, diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 57ab15ab6..7ffa34a8b 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -48,10 +48,6 @@ export default { ], }); - console.warn( - `${interaction.user.username} failed to verify because of no nickname permission.`, - ); - return; } @@ -83,10 +79,6 @@ export default { ], }); - console.warn( - `${interaction.user.username} failed to verify because of no manage roles permission.`, - ); - return; } @@ -106,10 +98,6 @@ export default { ), ], }); - - console.log( - `${interaction.user.username} verified as ${accountInfo[id].nickname}${clanTag}`, - ); } catch (error) { await interaction.editReply({ embeds: [ @@ -121,8 +109,6 @@ export default { ), ], }); - - console.warn('Failed to verify because of higher permissions.'); } } } diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index b37a7a694..526772e74 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -1,5 +1,5 @@ +import { StaticPool } from 'node-worker-threads-pool'; import { WargamingResponse } from '../../types/wargamingResponse.js'; -import URLToBase64 from '../ui/URLToBase64.js'; export interface TankopediaEntry { name: string; @@ -39,12 +39,38 @@ export const TANK_IDS = Object.keys(tankopedia).map((id) => Number(id)); export const TANKS = TANK_IDS.map((id) => tankopedia[id]); export const TANK_NAMES = TANKS.map((tank) => tank.name); -console.log('Encoding tank images...'); -await Promise.all( - Object.entries(tankopedia).map(async ([, tank]) => { - if (tank.images.normal) { - tank.images.normal = await URLToBase64(tank.images.normal); - } - }), -); -console.log('Encoded tank images'); +const imageEncodingStaticPool = new StaticPool({ + size: 1, + task: async (data: Tankopedia) => { + console.log('Encoding tank images...'); + + const encoded: [number, string][] = []; + + await Promise.all( + Object.entries(data as Tankopedia).map( + async ([, tank]: [string, TankopediaEntry]) => { + if (tank.images.normal) { + const response = await fetch(tank.images.normal); + const blob = await response.arrayBuffer(); + const base64 = `data:${response.headers.get( + 'content-type', + )};base64,${Buffer.from(blob).toString('base64')}`; + encoded.push([tank.tank_id, base64]); + } + }, + ), + ); + + console.log('Encoded tank images'); + + return encoded; + }, +}); + +imageEncodingStaticPool.exec(tankopedia).then((encoded) => { + console.log('Implementing encoded images...'); + encoded.forEach(([tankId, image]) => { + tankopedia[tankId].images.normal = image; + }); + console.log('Implemented encoded images'); +}); diff --git a/src/core/ui/URLToBase64.ts b/src/core/ui/URLToBase64.ts deleted file mode 100644 index 31b7c9954..000000000 --- a/src/core/ui/URLToBase64.ts +++ /dev/null @@ -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; -} diff --git a/yarn.lock b/yarn.lock index 36e6a48e2..171754751 100644 --- a/yarn.lock +++ b/yarn.lock @@ -577,6 +577,11 @@ nanoid@^3.3.6: resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz" integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA== +node-worker-threads-pool@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/node-worker-threads-pool/-/node-worker-threads-pool-1.5.1.tgz#1034303e10bb63a541ec74ae26559e9dff355f27" + integrity sha512-7TXAhpMm+jO4MfESxYLtMGSnJWv+itdNHMdaFmeZuPXxwFGU90mtEB42BciUULXOUAxYBfXILAuvrSG3rQZ7mw== + pako@^0.2.5: version "0.2.9" resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75" From 9e97c4a5ec844ba52464c74734debb5b2acff615 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Mon, 5 Jun 2023 18:47:00 +0000 Subject: [PATCH 05/10] feat: applied new renderer to ownedtanks --- .../{ownedtanks.ts => ownedtanks.tsx} | 80 +++++++++++-------- src/commands/stats.tsx | 1 - src/components/PoweredByWargaming.tsx | 15 ++++ src/components/Tanks/components/Item.tsx | 35 ++++++++ src/components/Tanks/components/Root.tsx | 21 +++++ src/components/Tanks/index.ts | 2 + src/core/blitz/tankopedia.ts | 30 ++++--- 7 files changed, 140 insertions(+), 44 deletions(-) rename src/commands/{ownedtanks.ts => ownedtanks.tsx} (54%) create mode 100644 src/components/PoweredByWargaming.tsx create mode 100644 src/components/Tanks/components/Item.tsx create mode 100644 src/components/Tanks/components/Root.tsx create mode 100644 src/components/Tanks/index.ts diff --git a/src/commands/ownedtanks.ts b/src/commands/ownedtanks.tsx similarity index 54% rename from src/commands/ownedtanks.ts rename to src/commands/ownedtanks.tsx index 214b37e81..55f7a434d 100644 --- a/src/commands/ownedtanks.ts +++ b/src/commands/ownedtanks.tsx @@ -1,17 +1,21 @@ import { SlashCommandBuilder } from 'discord.js'; -import markdownEscape from 'markdown-escape'; +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 getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getTankStats from '../core/blitz/getTankStats.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; -import resolveTankName from '../core/blitz/resolveTankName.js'; -import { TANK_TYPE_EMOJIS, tankopedia } from '../core/blitz/tankopedia.js'; +import { TIER_ROMAN_NUMERALS, tankopedia } from '../core/blitz/tankopedia.js'; import cmdName from '../core/interaction/cmdName.js'; -import infoEmbed from '../core/interaction/infoEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.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 { PlayerClanData } from '../types/playerClanData.js'; const COMP_TANKS = [ // light tanks @@ -36,7 +40,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -63,36 +67,44 @@ export default { const tanks = tankStats .map((tankData) => tankopedia[tankData.tank_id]) .filter((tank) => tank?.tier === tier); + const clanData = await getWargamingResponse( + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, + ); - await interaction.editReply({ - 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.time('ownedtanks'); + const image = await render( + + {/* TODO: integrate some of these into title bar */} + + + + {tanks.map((tank) => ( + + ))} + + + + , + ); + + await interaction.editReply({ files: [image] }); + console.timeEnd('ownedtanks'); }, autocomplete: usernameAutocomplete, diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 06235a9a9..f9354e72e 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -172,7 +172,6 @@ export default { files: [image], components: [actionRow], }); - }, autocomplete: usernameAutocomplete, diff --git a/src/components/PoweredByWargaming.tsx b/src/components/PoweredByWargaming.tsx new file mode 100644 index 000000000..e18ad7e7f --- /dev/null +++ b/src/components/PoweredByWargaming.tsx @@ -0,0 +1,15 @@ +import { theme } from '../stitches.config.js'; + +export default function PoweredByWargaming() { + return ( +
+ + + Powered by Wargaming + +
+ ); +} diff --git a/src/components/Tanks/components/Item.tsx b/src/components/Tanks/components/Item.tsx new file mode 100644 index 000000000..91f7061e4 --- /dev/null +++ b/src/components/Tanks/components/Item.tsx @@ -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 ( +
+ {icon && } + +
+ + + {name} + +
+
+ ); +} diff --git a/src/components/Tanks/components/Root.tsx b/src/components/Tanks/components/Root.tsx new file mode 100644 index 000000000..1a23e18ea --- /dev/null +++ b/src/components/Tanks/components/Root.tsx @@ -0,0 +1,21 @@ +import { ReactNode } from 'react'; + +export interface RootProps { + children: ReactNode; +} + +export function Root({ children }: RootProps) { + return ( +
+ {children} +
+ ); +} diff --git a/src/components/Tanks/index.ts b/src/components/Tanks/index.ts new file mode 100644 index 000000000..9ac57386e --- /dev/null +++ b/src/components/Tanks/index.ts @@ -0,0 +1,2 @@ +export * from './components/Item.js'; +export * from './components/Root.js'; diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index 526772e74..def1090eb 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -1,6 +1,8 @@ import { StaticPool } from 'node-worker-threads-pool'; import { WargamingResponse } from '../../types/wargamingResponse.js'; +export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; + export interface TankopediaEntry { name: string; nation: string; @@ -9,7 +11,7 @@ export interface TankopediaEntry { cost: { price_credit: number; price_gold: number }; images: { preview: string; normal: string }; tank_id: number; - type: string; + type: TankType; description: string; } @@ -25,14 +27,24 @@ export const tankopedia = ( ).data; console.log('Cached tankopedia'); -/** - * @deprecated - */ -export const TANK_TYPE_EMOJIS: Record = { - 'AT-SPG': 'šŸ”½', - heavyTank: 'šŸ‡­', - mediumTank: 'šŸ‡²', - lightTank: 'šŸ‡±', +export const TANK_ICONS: Record = { + 'AT-SPG': 'https://i.imgur.com/BIHSEH0.png', + lightTank: 'https://i.imgur.com/CSNha5V.png', + mediumTank: 'https://i.imgur.com/wvf3ltm.png', + heavyTank: 'https://i.imgur.com/ECeqlZa.png', +}; + +export const TIER_ROMAN_NUMERALS: Record = { + 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)); From 632881c6b082b68313224c2688a7280e96afea12 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Mon, 5 Jun 2023 18:47:37 +0000 Subject: [PATCH 06/10] feat: removed `node-worker-threads-pool` as satori seems to be faster without it --- package.json | 1 - src/core/blitz/tankopedia.ts | 37 ------------------------------------ yarn.lock | 5 ----- 3 files changed, 43 deletions(-) diff --git a/package.json b/package.json index 545aed3fe..5b17c3ff9 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "fuzzysort": "^2.0.4", "lodash.startcase": "^4.4.0", "markdown-escape": "^2.0.0", - "node-worker-threads-pool": "^1.5.1", "react": "^18.2.0", "satori": "^0.9.1" }, diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index def1090eb..8408d1559 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -1,4 +1,3 @@ -import { StaticPool } from 'node-worker-threads-pool'; import { WargamingResponse } from '../../types/wargamingResponse.js'; export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; @@ -50,39 +49,3 @@ export const TIER_ROMAN_NUMERALS: Record = { export const TANK_IDS = Object.keys(tankopedia).map((id) => Number(id)); export const TANKS = TANK_IDS.map((id) => tankopedia[id]); export const TANK_NAMES = TANKS.map((tank) => tank.name); - -const imageEncodingStaticPool = new StaticPool({ - size: 1, - task: async (data: Tankopedia) => { - console.log('Encoding tank images...'); - - const encoded: [number, string][] = []; - - await Promise.all( - Object.entries(data as Tankopedia).map( - async ([, tank]: [string, TankopediaEntry]) => { - if (tank.images.normal) { - const response = await fetch(tank.images.normal); - const blob = await response.arrayBuffer(); - const base64 = `data:${response.headers.get( - 'content-type', - )};base64,${Buffer.from(blob).toString('base64')}`; - encoded.push([tank.tank_id, base64]); - } - }, - ), - ); - - console.log('Encoded tank images'); - - return encoded; - }, -}); - -imageEncodingStaticPool.exec(tankopedia).then((encoded) => { - console.log('Implementing encoded images...'); - encoded.forEach(([tankId, image]) => { - tankopedia[tankId].images.normal = image; - }); - console.log('Implemented encoded images'); -}); diff --git a/yarn.lock b/yarn.lock index 171754751..36e6a48e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -577,11 +577,6 @@ nanoid@^3.3.6: resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz" integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA== -node-worker-threads-pool@^1.5.1: - version "1.5.1" - resolved "https://registry.yarnpkg.com/node-worker-threads-pool/-/node-worker-threads-pool-1.5.1.tgz#1034303e10bb63a541ec74ae26559e9dff355f27" - integrity sha512-7TXAhpMm+jO4MfESxYLtMGSnJWv+itdNHMdaFmeZuPXxwFGU90mtEB42BciUULXOUAxYBfXILAuvrSG3rQZ7mw== - pako@^0.2.5: version "0.2.9" resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75" From 26e78c72b932e09d5cfc3fa7ee807dcee8386f63 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Tue, 6 Jun 2023 00:25:23 +0000 Subject: [PATCH 07/10] fix: images in /today expanding parent --- src/commands/eligible.ts | 2 +- src/commands/ownedtanks.tsx | 2 +- src/commands/today.tsx | 8 +++----- src/components/Breakdown/components/Row.tsx | 1 + .../Breakdown/components/RowDiscriminator.tsx | 4 +++- src/components/Wrapper.tsx | 18 ++---------------- src/core/ui/render.tsx | 8 ++------ 7 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 24060f7c8..f4091a0b3 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -26,7 +26,7 @@ export const SKILLED_CLANS: Record = { export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: false, command: new SlashCommandBuilder() diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index 55f7a434d..bf4d02291 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -40,7 +40,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/today.tsx b/src/commands/today.tsx index b8212150e..ee4fa1a71 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -7,7 +7,7 @@ import * as Breakdown from '../components/Breakdown/index.js'; import NoBattlesInPeriod from '../components/NoBattlesInPeriod.js'; import PoweredByBlitzStars from '../components/PoweredByBlitzStars.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 usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; @@ -32,7 +32,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -160,7 +160,7 @@ export default { }); const image = await render( - + , - WrapperSize.Roomy, ); const actionRow = new ActionRowBuilder().addComponents( @@ -193,7 +192,6 @@ export default { files: [image], components: [actionRow], }); - }, autocomplete: usernameAutocomplete, diff --git a/src/components/Breakdown/components/Row.tsx b/src/components/Breakdown/components/Row.tsx index 11eac9794..f5e6c8786 100644 --- a/src/components/Breakdown/components/Row.tsx +++ b/src/components/Breakdown/components/Row.tsx @@ -34,6 +34,7 @@ export function Row({ return (
+ )} + = { - [WrapperSize.Regular]: 640, - [WrapperSize.Roomy]: 800, -}; - -export default function Wrapper({ - children, - size = WrapperSize.Regular, -}: WrapperProps) { +export default function Wrapper({ children }: WrapperProps) { return (
Date: Tue, 6 Jun 2023 01:31:16 +0000 Subject: [PATCH 08/10] feat: /inactive face lift --- src/commands/inactive.ts | 89 --------------------------- src/commands/inactive.tsx | 92 ++++++++++++++++++++++++++++ src/commands/stats.tsx | 4 +- src/commands/tankstats.tsx | 4 +- src/commands/today.tsx | 4 +- src/components/NoBattlesInPeriod.tsx | 17 ----- src/components/NoData.tsx | 31 ++++++++++ 7 files changed, 129 insertions(+), 112 deletions(-) delete mode 100644 src/commands/inactive.ts create mode 100644 src/commands/inactive.tsx delete mode 100644 src/components/NoBattlesInPeriod.tsx create mode 100644 src/components/NoData.tsx diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts deleted file mode 100644 index 1b8b5d257..000000000 --- a/src/commands/inactive.ts +++ /dev/null @@ -1,89 +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( - `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( - `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.`, - ), - ], - }); - }, - - autocomplete: clanAutocomplete, -} satisfies CommandRegistry; diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx new file mode 100644 index 000000000..3fd4a59c5 --- /dev/null +++ b/src/commands/inactive.tsx @@ -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: true, + 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( + `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( + `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( + + + + {!hasInactiveMembers && } + {hasInactiveMembers && } + + + , + ); + + await interaction.editReply({ files: [image] }); + }, + + autocomplete: clanAutocomplete, +} satisfies CommandRegistry; diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index f9354e72e..e5f13ae4e 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -4,7 +4,7 @@ import { SlashCommandBuilder, } from 'discord.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 TitleBar from '../components/TitleBar.js'; import Wrapper from '../components/Wrapper.js'; @@ -151,7 +151,7 @@ export default { } • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`} /> - {stats.battles === 0 && } + {stats.battles === 0 && } {stats.battles > 0 && ( - {stats.battles === 0 && } + {stats.battles === 0 && } {stats.battles > 0 && ( - {rows.length === 0 && } + {rows.length === 0 && } {rows.length > 0 && {rows}} diff --git a/src/components/NoBattlesInPeriod.tsx b/src/components/NoBattlesInPeriod.tsx deleted file mode 100644 index 1f30a4913..000000000 --- a/src/components/NoBattlesInPeriod.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { theme } from '../stitches.config.js'; - -export default function NoBattlesInPeriod() { - return ( -
- - No battles played in this period - -
- ); -} diff --git a/src/components/NoData.tsx b/src/components/NoData.tsx new file mode 100644 index 000000000..1b4231829 --- /dev/null +++ b/src/components/NoData.tsx @@ -0,0 +1,31 @@ +import { theme } from '../stitches.config.js'; + +export enum NoDataType { + Battles, + Players, +} + +export interface NoDataProps { + type: NoDataType; +} + +const NO_DATA_MESSAGES: Record = { + [NoDataType.Battles]: 'No battles played in this period', + [NoDataType.Players]: 'No players in this period', +}; + +export default function NoData({ type }: NoDataProps) { + return ( +
+ + {NO_DATA_MESSAGES[type]} + +
+ ); +} From 524edac615796c88e286352315cf948ded67ec34 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Tue, 6 Jun 2023 16:50:33 +0000 Subject: [PATCH 09/10] feat: mature error handling system --- src/commands/debug.ts | 2 +- src/commands/eligible.ts | 2 +- src/commands/help.ts | 2 +- src/commands/ownedtanks.tsx | 2 +- src/commands/playerachievements.ts | 2 +- src/commands/playerinfo.ts | 2 +- src/commands/searchclans.ts | 2 +- src/commands/searchplayers.ts | 2 +- src/commands/searchtanks.ts | 2 +- src/commands/stats.tsx | 2 +- src/commands/tankstats.tsx | 2 +- src/commands/verify.ts | 2 +- src/core/blitz/getBlitzAccount.ts | 30 +++++++------------------ src/core/blitz/getBlitzClan.ts | 16 +++++-------- src/core/blitz/getTankStats.ts | 16 +++++-------- src/core/blitz/getWargamingResponse.ts | 6 +++-- src/core/blitz/resolveTankId.ts | 30 ++++++++----------------- src/core/blitz/wargamingError.ts | 2 +- src/core/blitzstars/blitzStarsError.ts | 2 +- src/core/process/args.ts | 6 ++++- src/core/process/errorWithCause.ts | 3 +++ src/events/error.ts | 8 +++---- src/events/interactionCreate.ts | 31 +++++++++++++++++++++++++- 23 files changed, 87 insertions(+), 87 deletions(-) create mode 100644 src/core/process/errorWithCause.ts diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 278060b45..0c3b94b27 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -13,7 +13,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index f4091a0b3..24060f7c8 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -26,7 +26,7 @@ export const SKILLED_CLANS: Record = { export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: false, command: new SlashCommandBuilder() diff --git a/src/commands/help.ts b/src/commands/help.ts index 0b1511cb8..327e465bc 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -11,7 +11,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index bf4d02291..55f7a434d 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -40,7 +40,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index 536e1bed9..25847ac8f 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -17,7 +17,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index 82c83a05d..ae4dd54d9 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -13,7 +13,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index db07881eb..d3f3e88a1 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index d0f731cd8..b196d8d70 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -13,7 +13,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index 2d525cdc0..0e4d2d469 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index e5f13ae4e..31dd32681 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -40,7 +40,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index dbcd9d270..aa7bf062f 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -40,7 +40,7 @@ import { AccountInfo, AllStats } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 7ffa34a8b..cdbe4d674 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/core/blitz/getBlitzAccount.ts b/src/core/blitz/getBlitzAccount.ts index 7a16d341b..e25cfda1a 100644 --- a/src/core/blitz/getBlitzAccount.ts +++ b/src/core/blitz/getBlitzAccount.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BlitzServer } from '../../constants/servers.js'; -import negativeEmbed from '../interaction/negativeEmbed.js'; +import errorWithCause from '../process/errorWithCause.js'; import listAccountsPanServer, { usernamePatternWithoutPosition, } from './listAccountsPanServer.js'; @@ -17,17 +17,9 @@ export default async function getBlitzAccount( const username = commandUsername ?? displayName; if (username === undefined) { - await interaction.editReply({ - embeds: [ - negativeEmbed( - '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.", - ), - ], - }); - - throw new Error( - `No username provided commandUsername: ${commandUsername} displayName: ${displayName} username: ${username}`, + 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.", ); } @@ -40,16 +32,10 @@ export default async function getBlitzAccount( if (accounts[0]) { return { server: accounts[0].server, id: accounts[0].account_id }; } else { - await interaction.editReply({ - embeds: [ - negativeEmbed( - 'Could not find user', - `I couldn't find user \`${username}\`. Try providing a username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`, - ), - ], - }); - - throw new Error(`Could not find user "${username}"`); + throw errorWithCause( + 'Could not find user', + `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.`, + ); } } } diff --git a/src/core/blitz/getBlitzClan.ts b/src/core/blitz/getBlitzClan.ts index e15c103be..7d5c847c1 100644 --- a/src/core/blitz/getBlitzClan.ts +++ b/src/core/blitz/getBlitzClan.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BlitzServer } from '../../constants/servers.js'; -import negativeEmbed from '../interaction/negativeEmbed.js'; +import errorWithCause from '../process/errorWithCause.js'; import { serverAndIdPattern } from './getBlitzAccount.js'; import listClansPanServer from './listClansPanServer.js'; @@ -17,16 +17,10 @@ export default async function getBlitzClan( if (accounts[0]) { return { server: accounts[0].server, id: accounts[0].clan_id }; } else { - await interaction.editReply({ - embeds: [ - negativeEmbed( - 'Could not find clan', - `I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`, - ), - ], - }); - - throw new Error(`Could not find clan "${clan}"`); + throw errorWithCause( + 'Could not find clan', + `I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`, + ); } } } diff --git a/src/core/blitz/getTankStats.ts b/src/core/blitz/getTankStats.ts index d41b3a9c6..5dac94cf3 100644 --- a/src/core/blitz/getTankStats.ts +++ b/src/core/blitz/getTankStats.ts @@ -1,8 +1,8 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js'; import { TanksStats } from '../../types/tanksStats.js'; -import negativeEmbed from '../interaction/negativeEmbed.js'; import { args } from '../process/args.js'; +import errorWithCause from '../process/errorWithCause.js'; import getWargamingResponse from './getWargamingResponse.js'; export default async function getTankStats( @@ -15,16 +15,10 @@ export default async function getTankStats( ); if (tankStats[id] === null) { - interaction.editReply({ - embeds: [ - negativeEmbed( - '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.`, - ), - ], - }); - - throw new Error(`No tank stats available for ${server}/${id}`); + throw errorWithCause( + '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.`, + ); } return tankStats[id]; diff --git a/src/core/blitz/getWargamingResponse.ts b/src/core/blitz/getWargamingResponse.ts index 7a49afcef..59d30f9d5 100644 --- a/src/core/blitz/getWargamingResponse.ts +++ b/src/core/blitz/getWargamingResponse.ts @@ -1,4 +1,5 @@ import { WargamingResponse } from '../../types/wargamingResponse.js'; +import errorWithCause from '../process/errorWithCause.js'; export default async function getWargamingResponse( url: string, @@ -11,8 +12,9 @@ export default async function getWargamingResponse( if (parsed.status === 'ok') { return parsed.data; } else { - throw new Error( - `Wargaming response error status:"${parsed.status}" message: "${parsed.error.message}" url: "${url}"`, + throw errorWithCause( + `Wargaming response error status:"${parsed.status}"`, + `Message: "${parsed.error.message}"\nURL: "${url}"`, ); } } diff --git a/src/core/blitz/resolveTankId.ts b/src/core/blitz/resolveTankId.ts index c480d0fee..e71e6ff8f 100644 --- a/src/core/blitz/resolveTankId.ts +++ b/src/core/blitz/resolveTankId.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { go } from 'fuzzysort'; -import negativeEmbed from '../interaction/negativeEmbed.js'; +import errorWithCause from '../process/errorWithCause.js'; import { TANKS, tankopedia } from './tankopedia.js'; export default async function resolveTankId( @@ -13,16 +13,10 @@ export default async function resolveTankId( const searchResult = go(tank, TANKS, { keys: ['name'], limit: 1 }); if (searchResult.length === 0) { - await interaction.editReply({ - embeds: [ - negativeEmbed( - 'Tank not found', - `Could not find tank by the name "${tank}".`, - ), - ], - }); - - throw new Error(`Tank not found by name "${tank}"`); + throw errorWithCause( + 'Tank not found', + `Could not find tank by the name "${tank}".`, + ); } else { return searchResult[0].obj.tank_id; } @@ -30,16 +24,10 @@ export default async function resolveTankId( if (tankopedia[number]) { return number; } else { - await interaction.editReply({ - embeds: [ - negativeEmbed( - 'Tank not found', - `Could not find tank by the ID "${number}".`, - ), - ], - }); - - throw new Error(`Tank not found by ID "${number}"`); + throw errorWithCause( + 'Tank not found', + `Could not find tank by the ID "${number}".`, + ); } } } diff --git a/src/core/blitz/wargamingError.ts b/src/core/blitz/wargamingError.ts index a6daae8fb..e9e8258aa 100644 --- a/src/core/blitz/wargamingError.ts +++ b/src/core/blitz/wargamingError.ts @@ -22,5 +22,5 @@ export default async function wargamingError( }); console.log(`Wargaming returned an error`); - handleError(error, client, command); + handleError(error, command); } diff --git a/src/core/blitzstars/blitzStarsError.ts b/src/core/blitzstars/blitzStarsError.ts index 1278d3bf1..9f2b8443c 100644 --- a/src/core/blitzstars/blitzStarsError.ts +++ b/src/core/blitzstars/blitzStarsError.ts @@ -24,5 +24,5 @@ export default async function blitzStarsError( }); console.log(`BlitzStars returned an error`); - handleError(error, client, command); + handleError(error, command); } diff --git a/src/core/process/args.ts b/src/core/process/args.ts index 3b44eb03d..1e3f490c1 100644 --- a/src/core/process/args.ts +++ b/src/core/process/args.ts @@ -1,4 +1,5 @@ import { argv } from 'process'; +import errorWithCause from './errorWithCause.js'; type ArgumentName = 'discord-token' | 'wargaming-application-id'; @@ -16,6 +17,9 @@ argv.forEach((arg) => { Object.keys(args).forEach((arg) => { if (args[arg as ArgumentName] === '') { - throw new Error(`Missing argument: ${arg}`); + throw errorWithCause( + `Missing argument: ${arg}`, + 'Missing required auth key.', + ); } }); diff --git a/src/core/process/errorWithCause.ts b/src/core/process/errorWithCause.ts new file mode 100644 index 000000000..0e2ef81c7 --- /dev/null +++ b/src/core/process/errorWithCause.ts @@ -0,0 +1,3 @@ +export default function errorWithCause(message: string, cause: string) { + return new Error(message, { cause }); +} diff --git a/src/events/error.ts b/src/events/error.ts index bc99ced50..1f615cf63 100644 --- a/src/events/error.ts +++ b/src/events/error.ts @@ -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 { NEGATIVE_COLOR } from '../constants/colors.js'; import isDev from '../core/process/isDev.js'; @@ -7,7 +7,7 @@ import { client } from '../index.js'; const PROCESS_ERROR_EVENTS = ['uncaughtException']; const CLIENT_ERROR_EVENTS = ['error']; -export function handleError(error: Error, client: Client, command: string) { +export function handleError(error: Error, command: string) { console.error(error); ( @@ -31,10 +31,10 @@ export function handleError(error: Error, client: Client, command: string) { export function registerErrorHandlers() { if (!isDev()) { 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.on(name, (error) => handleError(error, client, 'client error')), + client.on(name, (error) => handleError(error, 'client error')), ); } diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 5fb7c2b75..236a3ecf5 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,5 +1,8 @@ import { + ActionRowBuilder, AutocompleteInteraction, + ButtonBuilder, + ButtonStyle, CacheType, ChatInputCommandInteraction, Collection, @@ -11,9 +14,11 @@ import { } from 'discord.js'; import { readdirSync } from 'fs'; import discord from '../../discord.json' assert { type: 'json' }; +import negativeEmbed from '../core/interaction/negativeEmbed.js'; import { args } from '../core/process/args.js'; import getClientId from '../core/process/getClientId.js'; import isDev from '../core/process/isDev.js'; +import { handleError } from './error.js'; export interface CommandRegistry { inDevelopment: boolean; @@ -101,6 +106,30 @@ export default async function interactionCreate( console.log(interaction.toString()); await interaction.deferReply(); - command.execute(interaction); + + try { + await command.execute(interaction); + } catch (error) { + const actionRow = new ActionRowBuilder().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); + } } } From 238661ac160b2a34704670ea3c5fbea274a6da4f Mon Sep 17 00:00:00 2001 From: tresabhi Date: Tue, 6 Jun 2023 16:53:13 +0000 Subject: [PATCH 10/10] fix: no tanks heads up in /ownedtanks --- src/commands/debug.ts | 2 +- src/commands/eligible.ts | 2 +- src/commands/help.ts | 2 +- src/commands/inactive.tsx | 4 ++-- src/commands/ownedtanks.tsx | 25 +++++++++++++++---------- src/commands/playerachievements.ts | 2 +- src/commands/playerinfo.ts | 2 +- src/commands/searchclans.ts | 2 +- src/commands/searchplayers.ts | 2 +- src/commands/searchtanks.ts | 2 +- src/commands/stats.tsx | 4 ++-- src/commands/tankstats.tsx | 4 ++-- src/commands/today.tsx | 4 ++-- src/commands/verify.ts | 2 +- src/components/NoData.tsx | 10 ++++++---- 15 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 0c3b94b27..278060b45 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -13,7 +13,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 24060f7c8..f4091a0b3 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -26,7 +26,7 @@ export const SKILLED_CLANS: Record = { export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: false, command: new SlashCommandBuilder() diff --git a/src/commands/help.ts b/src/commands/help.ts index 327e465bc..0b1511cb8 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -11,7 +11,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index 3fd4a59c5..8d4541ee5 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -20,7 +20,7 @@ const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() @@ -78,7 +78,7 @@ export default { }`} /> - {!hasInactiveMembers && } + {!hasInactiveMembers && } {hasInactiveMembers && } diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index 55f7a434d..5c98f039e 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -1,4 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; +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'; @@ -88,16 +89,20 @@ export default { }`} /> - - {tanks.map((tank) => ( - - ))} - + {tanks.length === 0 && } + + {tanks.length > 0 && ( + + {tanks.map((tank) => ( + + ))} + + )} , diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index 25847ac8f..536e1bed9 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -17,7 +17,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index ae4dd54d9..82c83a05d 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -13,7 +13,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index d3f3e88a1..db07881eb 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index b196d8d70..d0f731cd8 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -13,7 +13,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index 0e4d2d469..2d525cdc0 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 31dd32681..81602e500 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -40,7 +40,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() @@ -151,7 +151,7 @@ export default { } • ${new Date().toDateString()} • ${BLITZ_SERVERS[server]}`} /> - {stats.battles === 0 && } + {stats.battles === 0 && } {stats.battles > 0 && ( - {stats.battles === 0 && } + {stats.battles === 0 && } {stats.battles > 0 && ( - {rows.length === 0 && } + {rows.length === 0 && } {rows.length > 0 && {rows}} diff --git a/src/commands/verify.ts b/src/commands/verify.ts index cdbe4d674..7ffa34a8b 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -14,7 +14,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/components/NoData.tsx b/src/components/NoData.tsx index 1b4231829..003ed8040 100644 --- a/src/components/NoData.tsx +++ b/src/components/NoData.tsx @@ -1,8 +1,9 @@ import { theme } from '../stitches.config.js'; export enum NoDataType { - Battles, - Players, + BattlesInPeriod, + PlayersInPeriod, + TanksFound, } export interface NoDataProps { @@ -10,8 +11,9 @@ export interface NoDataProps { } const NO_DATA_MESSAGES: Record = { - [NoDataType.Battles]: 'No battles played in this period', - [NoDataType.Players]: 'No players in this period', + [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) {