diff --git a/package.json b/package.json index e577660b8..15d164770 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blitzkrieg", - "version": "1.3.0", + "version": "1.3.1", "description": "", "main": "index.js", "type": "module", diff --git a/playwright.config.ts b/playwright.config.ts deleted file mode 100644 index 8d244eec3..000000000 --- a/playwright.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineConfig, devices } from '@playwright/test'; - -export default defineConfig({ - testDir: './tests', - fullyParallel: true, - forbidOnly: !!process.env.CI, - retries: process.env.CI ? 2 : 0, - workers: process.env.CI ? 1 : undefined, - reporter: 'html', - use: { trace: 'on-first-retry' }, - - projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], -}); diff --git a/src/commands/debug.ts b/src/commands/debug.ts index b194b7ea7..b00b1b387 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import packageJSON from '../../package.json' assert { type: 'json' }; -import { INFO_COLOR } from '../constants/colors.js'; +import { ACCENT_COLOR } from '../constants/colors.js'; import { tankopedia } from '../core/blitzstars/tankopedia.js'; import cmdName from '../core/interaction/cmdName.js'; import getClientId from '../core/process/getClientId.js'; @@ -11,7 +11,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -26,7 +26,7 @@ export default { embeds: [ new EmbedBuilder() .setTitle(`${client.user?.username} debug information`) - .setColor(INFO_COLOR) + .setColor(ACCENT_COLOR) .setDescription( `**Version**: ${packageJSON.version}\n**Uptime**: ${Math.floor( uptime / 1000 / 60 / 60 / 24, diff --git a/src/commands/help.ts b/src/commands/help.ts index a33476f49..f9cc7a4bd 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; -import { INFO_COLOR } from '../constants/colors.js'; +import { ACCENT_COLOR } from '../constants/colors.js'; import cmdName from '../core/interaction/cmdName.js'; import { CommandRegistry, @@ -11,7 +11,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -23,7 +23,7 @@ export default { embeds: [ new EmbedBuilder() .setTitle(`${client.user?.username} help`) - .setColor(INFO_COLOR) + .setColor(ACCENT_COLOR) .setDescription( `**About**\n${ client.user?.username diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts index 926358d55..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() @@ -34,7 +34,6 @@ export default { async execute(interaction) { const clanName = interaction.options.getString('clan')!; const clan = await getBlitzClan(interaction, clanName); - if (!clan) return; const { server, id } = clan; const threshold = @@ -43,14 +42,12 @@ export default { const clanInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${id}`, ); - if (!clanInfo) return; 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(',')}`, ); - if (!accountInfo) return; const inactiveInfo = memberIds .map((memberId) => { const member = accountInfo[memberId]; diff --git a/src/commands/ownedtanks.ts b/src/commands/ownedtanks.ts index 50e291f07..70211dadb 100644 --- a/src/commands/ownedtanks.ts +++ b/src/commands/ownedtanks.ts @@ -1,11 +1,11 @@ -import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { INFO_COLOR } from '../constants/colors.js'; import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import { TANK_TYPE_EMOJIS, tankopedia } from '../core/blitzstars/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 { CommandRegistry } from '../events/interactionCreate.js'; @@ -36,7 +36,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -56,51 +56,44 @@ export default { const tier = interaction.options.getInteger('tier')!; const name = interaction.options.getString('username')!; const account = await getBlitzAccount(interaction, name); - if (!account) return; const { id, server } = account; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accountInfo) return; const tankStats = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!tankStats) return; const tanks = tankStats[id] .map((tankData) => tankopedia.data[tankData.tank_id]) .filter((tank) => tank?.tier === tier); await interaction.editReply({ embeds: [ - new EmbedBuilder() - .setTitle( - `${markdownEscape(accountInfo[id].nickname)}'s owned ${ - tier === null ? '' : `tier ${tier} ` - }tanks`, - ) - .setDescription( - `${ - tanks.length === 0 - ? `No tanks found in tier ${tier}` - : tanks - .map( - (tank) => - `${TANK_TYPE_EMOJIS[tank.type]} ${resolveTankName( - tank, - )} ${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`, - ) - .setColor(INFO_COLOR), + 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]} ${resolveTankName( + tank, + )} ${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`, + ), ], }); diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index a9025c6d0..5d0e0fa32 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() @@ -38,17 +38,14 @@ export default { const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy; const name = interaction.options.getString('username')!; const account = await getBlitzAccount(interaction, name); - if (!account) return; const { id, server } = account; const accounts = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accounts) return; const accountsAchievements = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accountsAchievements) return; const accountAchievements = accountsAchievements[id]; const compound = { ...accountAchievements.achievements, diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index 9f6795494..162194f95 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() @@ -24,12 +24,10 @@ export default { async execute(interaction) { const name = interaction.options.getString('username')!; const account = await getBlitzAccount(interaction, name); - if (!account) return; const { id, server } = account; const accounts = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accounts) return; const accountInfo = accounts[id]; interaction.editReply({ diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index d55f18f0b..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() @@ -35,7 +35,6 @@ export default { const clanList = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${clan}&limit=${limit}`, ); - if (!clanList) return; await interaction.editReply({ embeds: [ diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index a2bea41fd..682c5e2f3 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -1,9 +1,9 @@ -import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { INFO_COLOR } from '../constants/colors.js'; import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cmdName from '../core/interaction/cmdName.js'; +import infoEmbed from '../core/interaction/infoEmbed.js'; import addServerChoices from '../core/options/addServerChoices.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { args } from '../core/process/args.js'; @@ -12,7 +12,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -34,27 +34,26 @@ export default { const server = interaction.options.getString('server') as BlitzServer; const name = interaction.options.getString('username')!; const limit = interaction.options.getInteger('limit') ?? 25; - const players = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}&limit=${limit}`, - ); - if (!players) return; + const normalizedSearch = encodeURIComponent(name.trim()); + const players = + normalizedSearch.length >= 3 && normalizedSearch.length <= 100 + ? await getWargamingResponse( + `https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${normalizedSearch}&limit=${limit}`, + ) + : []; await interaction.editReply({ embeds: [ - new EmbedBuilder() - .setColor(INFO_COLOR) - .setTitle( - `Player search for "${markdownEscape(name)}" in ${ - BLITZ_SERVERS[server] - }`, - ) - .setDescription( - `\`\`\`${ - players.length === 0 - ? 'No players found.' - : players.map((player) => player.nickname).join('\n') - }\`\`\``, - ), + infoEmbed( + `Player search for "${markdownEscape(name)}" in ${ + BLITZ_SERVERS[server] + }`, + `\`\`\`${ + players.length === 0 + ? 'No players found.' + : players.map((player) => player.nickname).join('\n') + }\`\`\``, + ), ], }); diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index bf7d49823..768c10e7c 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 8561d8957..e26255ac3 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -35,7 +35,7 @@ const periodNames: Record = { export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -59,19 +59,15 @@ export default { const period = interaction.options.getString('period') as Period; const username = interaction.options.getString('username')!; const blitzAccount = await getBlitzAccount(interaction, username); - if (!blitzAccount) return; const { id, server } = blitzAccount; let stats: BlitzStartsComputedPeriodicStatistics; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accountInfo) return; const clanData = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, ); - if (!clanData) return; const blitzStarsAccount = await getBlitzStarsAccount(interaction, id); - if (!blitzStarsAccount) return; if (period === 'today') { const a1 = blitzStarsAccount.statistics; @@ -115,7 +111,6 @@ export default { ? blitzStarsAccount.statistics : blitzStarsAccount[`period${period}d`]; } - if (!stats) return; const image = await render( diff --git a/src/commands/tankstats.ts b/src/commands/tankstats.ts index 4c5c12db6..68f5afbbc 100644 --- a/src/commands/tankstats.ts +++ b/src/commands/tankstats.ts @@ -23,7 +23,7 @@ type Periods = '30' | '60' | '90'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -48,12 +48,10 @@ export default { const tankId = interaction.options.getString('tank')!; const period = interaction.options.getString('period') as Periods; const blitzAccount = await getBlitzAccount(interaction, name); - if (!blitzAccount) return; const { server, id } = blitzAccount; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accountInfo) return; const tank = tankopedia.data[tankId as unknown as number]; if (tank) { diff --git a/src/commands/today.tsx b/src/commands/today.tsx index 8f9ef3dda..f815248f1 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -29,7 +29,7 @@ import resolveTankName from '../utilities/resolveTankName.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -40,7 +40,6 @@ export default { async execute(interaction) { const username = interaction.options.getString('username')!; const blitzAccount = await getBlitzAccount(interaction, username); - if (!blitzAccount) return; const { id, server } = blitzAccount; const tankStatsOverTime = await getTankStatsOverTime( server, @@ -48,19 +47,15 @@ export default { last5AM().getTime() / 1000, new Date().getTime() / 1000, ); - if (!tankStatsOverTime) return; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accountInfo) return; const clanData = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, ); - if (!clanData) return; const careerTankStatsRaw = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!careerTankStatsRaw) return; const careerStats: Record = {}; Object.entries(careerTankStatsRaw[id]).forEach(([, tankStats]) => { diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 90ccbf0f5..49b957b18 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() @@ -25,16 +25,13 @@ export default { async execute(interaction) { const name = interaction.options.getString('username')!; const blitzAccount = await getBlitzAccount(interaction, name); - if (!blitzAccount) return; const { id, server } = blitzAccount; const accountInfo = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!accountInfo) return; const clanData = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, ); - if (!clanData) return; const clan = clanData[id]?.clan; const clanTag = clan ? ` [${clan!.tag}]` : ''; diff --git a/src/constants/colors.ts b/src/constants/colors.ts index f81fdc6ad..1e4a518ff 100644 --- a/src/constants/colors.ts +++ b/src/constants/colors.ts @@ -1,3 +1,3 @@ -export const INFO_COLOR = '#8e3cf5'; +export const ACCENT_COLOR = '#ffffff'; export const POSITIVE_COLOR = '#82ff29'; export const NEGATIVE_COLOR = '#ff4747'; diff --git a/src/core/autocomplete/username.ts b/src/core/autocomplete/username.ts index 6bd85a2e7..e303e1a56 100644 --- a/src/core/autocomplete/username.ts +++ b/src/core/autocomplete/username.ts @@ -13,17 +13,23 @@ export default async function usernameAutocomplete( if (focusedOption.name !== 'username') return; const players = await listAccountsPanServer(focusedOption.value); - await interaction.respond( - players - ? players.map( - (player) => - ({ - name: `${player.nickname} (${BLITZ_SERVERS[player.server]})`, - value: `${player.server}/${player.account_id}`, - } satisfies ApplicationCommandOptionChoiceData), - ) - : [], - ); + try { + await interaction.respond( + players + ? players.map( + (player) => + ({ + name: `${player.nickname} (${BLITZ_SERVERS[player.server]})`, + value: `${player.server}/${player.account_id}`, + } satisfies ApplicationCommandOptionChoiceData), + ) + : [], + ); - console.log(`Username autocomplete for ${focusedOption.value}`); + console.log(`Username autocomplete for ${focusedOption.value}`); + } catch (error) { + console.warn( + `Failed to autocomplete username for ${focusedOption.value} in time`, + ); + } } diff --git a/src/core/blitz/getBlitzAccount.ts b/src/core/blitz/getBlitzAccount.ts index 9c2a1975d..e0fe4c4ea 100644 --- a/src/core/blitz/getBlitzAccount.ts +++ b/src/core/blitz/getBlitzAccount.ts @@ -8,7 +8,7 @@ export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/; export default async function getBlitzAccount( interaction: ChatInputCommandInteraction, username: string, -): Promise<{ server: BlitzServer; id: number } | null> { +) { if (serverAndIdPattern.test(username)) { const [server, accountId] = username.split('/'); return { server: server as BlitzServer, id: Number(accountId) }; @@ -27,7 +27,7 @@ export default async function getBlitzAccount( ], }); - return null; + throw new Error(`Could not find user "${username}"`); } } } diff --git a/src/core/blitz/getBlitzClan.ts b/src/core/blitz/getBlitzClan.ts index 381dfbe7d..343711c11 100644 --- a/src/core/blitz/getBlitzClan.ts +++ b/src/core/blitz/getBlitzClan.ts @@ -7,7 +7,7 @@ import listClansPanServer from './listClansPanServer.js'; export default async function getBlitzClan( interaction: ChatInputCommandInteraction, clan: string, -): Promise<{ server: BlitzServer; id: number } | null> { +) { if (serverAndIdPattern.test(clan)) { const [server, accountId] = clan.split('/'); return { server: server as BlitzServer, id: Number(accountId) }; @@ -20,13 +20,13 @@ export default async function getBlitzClan( await interaction.editReply({ embeds: [ errorEmbed( - 'Could not find user', + 'Could not find clan', `I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`, ), ], }); - return null; + throw new Error(`Could not find clan "${clan}"`); } } } diff --git a/src/core/blitz/getWargamingResponse.ts b/src/core/blitz/getWargamingResponse.ts index d4e58d7fb..7a49afcef 100644 --- a/src/core/blitz/getWargamingResponse.ts +++ b/src/core/blitz/getWargamingResponse.ts @@ -11,9 +11,8 @@ export default async function getWargamingResponse( if (parsed.status === 'ok') { return parsed.data; } else { - console.error( - `Wargaming response status ${parsed.status} ${parsed.error.message}`, + throw new Error( + `Wargaming response error status:"${parsed.status}" message: "${parsed.error.message}" url: "${url}"`, ); - return null; } } diff --git a/src/core/blitz/listAccountsPanServer.ts b/src/core/blitz/listAccountsPanServer.ts index 8a5b66229..0c021a44a 100644 --- a/src/core/blitz/listAccountsPanServer.ts +++ b/src/core/blitz/listAccountsPanServer.ts @@ -8,50 +8,47 @@ export type AccountListWithServer = (Account & { })[]; export default async function listAccountsPanServer(search: string, limit = 9) { - const trimmed = search.trim(); - if (trimmed.length < 3 && trimmed.length > 100) return []; + const normalizedSearch = encodeURIComponent(search.trim()); const normalizedLimit = Math.round(limit / 3); - return ( - await Promise.all([ - getWargamingResponse( - `https://api.wotblitz.com/wotb/account/list/?application_id=${ - args['wargaming-application-id'] - }&search=${encodeURIComponent(search)}&limit=${normalizedLimit}`, - ).then( - (value) => - value && - value.map((account) => ({ - ...account, - server: 'com' as BlitzServer, - })), - ), - getWargamingResponse( - `https://api.wotblitz.eu/wotb/account/list/?application_id=${ - args['wargaming-application-id'] - }&search=${encodeURIComponent(search)}&limit=${normalizedLimit}`, - ).then( - (value) => - value && - value.map((account) => ({ - ...account, - server: 'eu' as BlitzServer, - })), - ), - getWargamingResponse( - `https://api.wotblitz.asia/wotb/account/list/?application_id=${ - args['wargaming-application-id'] - }&search=${encodeURIComponent(search)}&limit=${normalizedLimit}`, - ).then( - (value) => - value && - value.map((account) => ({ - ...account, - server: 'asia' as BlitzServer, - })), - ), - ]) - ) - .filter(Boolean) - .flat(); + if (normalizedSearch.length >= 3 && normalizedSearch.length <= 100) { + return ( + await Promise.all([ + getWargamingResponse( + `https://api.wotblitz.com/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + ).then( + (value) => + value && + value.map((account) => ({ + ...account, + server: 'com' as BlitzServer, + })), + ), + getWargamingResponse( + `https://api.wotblitz.eu/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + ).then( + (value) => + value && + value.map((account) => ({ + ...account, + server: 'eu' as BlitzServer, + })), + ), + getWargamingResponse( + `https://api.wotblitz.asia/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + ).then( + (value) => + value && + value.map((account) => ({ + ...account, + server: 'asia' as BlitzServer, + })), + ), + ]) + ) + .filter(Boolean) + .flat(); + } else { + return []; + } } diff --git a/src/core/blitzstars/getBlitzStarsAccount.ts b/src/core/blitzstars/getBlitzStarsAccount.ts index 1d118e958..63ed9e601 100644 --- a/src/core/blitzstars/getBlitzStarsAccount.ts +++ b/src/core/blitzstars/getBlitzStarsAccount.ts @@ -20,8 +20,6 @@ export default async function getBlitzStarsAccount( embeds: [notTrackedByBlitzStars], }); - console.log(`Not tracked by BlitzStars.`); - - return null; + throw new Error(`${accountId} not tracked by BlitzStars.`); } } diff --git a/src/core/blitzstars/getTankStatsOverTime.ts b/src/core/blitzstars/getTankStatsOverTime.ts index bd6ebac39..20a5964f7 100644 --- a/src/core/blitzstars/getTankStatsOverTime.ts +++ b/src/core/blitzstars/getTankStatsOverTime.ts @@ -51,7 +51,6 @@ export default async function getTankStatsOverTime( const latestTankStatsRaw = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`, ); - if (!latestTankStatsRaw) return; const tankHistoriesResponse = await fetch( `https://www.blitzstars.com/api/tankhistories/for/${id}/`, ); diff --git a/src/core/interaction/infoEmbed.ts b/src/core/interaction/infoEmbed.ts index ee47b02c3..21976cd95 100644 --- a/src/core/interaction/infoEmbed.ts +++ b/src/core/interaction/infoEmbed.ts @@ -1,9 +1,9 @@ import { EmbedBuilder } from 'discord.js'; -import { INFO_COLOR } from '../../constants/colors.js'; +import { ACCENT_COLOR } from '../../constants/colors.js'; export default function infoEmbed(title: string, description: string) { return new EmbedBuilder() - .setColor(INFO_COLOR) + .setColor(ACCENT_COLOR) .setTitle(title) .setDescription(description); } diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index ee07d839e..60b0abb3a 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, GuildMember, TextChannel } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; -import { INFO_COLOR } from '../constants/colors.js'; +import { ACCENT_COLOR } from '../constants/colors.js'; export default async function (member: GuildMember) { if (member.guild.id === discord.sklld_guild_id) { @@ -12,7 +12,7 @@ export default async function (member: GuildMember) { content: member.toString(), embeds: [ new EmbedBuilder() - .setColor(INFO_COLOR) + .setColor(ACCENT_COLOR) .setTitle(`Welcome ${member.user.username}`) .setDescription( `Welcome to the Skilled server, **${member.user.username}**! To continue, please use the \`/verify\` command.\n\nExample: \`/verify Europe Sabina244\``,