mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: bug fixes and error safety
This commit is contained in:
1 parent
0b6b2ecedc
commit
780d9d5f8e
25 files changed
+136
-182
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<ClanInfo>(
|
||||
`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<AccountInfo>(
|
||||
`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];
|
||||
|
||||
+28
-35
@@ -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<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accountInfo) return;
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`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`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -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<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accounts) return;
|
||||
const accountsAchievements =
|
||||
await getWargamingResponse<AccountAchievements>(
|
||||
`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,
|
||||
|
||||
@@ -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<AccountInfo>(
|
||||
`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({
|
||||
|
||||
@@ -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<ClanList>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${clan}&limit=${limit}`,
|
||||
);
|
||||
if (!clanList) return;
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -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<AccountList>(
|
||||
`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<AccountList>(
|
||||
`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')
|
||||
}\`\`\``,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: false,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
@@ -35,7 +35,7 @@ const periodNames: Record<Period, string> = {
|
||||
|
||||
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<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accountInfo) return;
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`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(
|
||||
<Wrapper>
|
||||
|
||||
@@ -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<AccountInfo>(
|
||||
`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) {
|
||||
|
||||
@@ -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<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accountInfo) return;
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`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<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!careerTankStatsRaw) return;
|
||||
const careerStats: Record<number, AllStats> = {};
|
||||
|
||||
Object.entries(careerTankStatsRaw[id]).forEach(([, tankStats]) => {
|
||||
|
||||
@@ -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<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accountInfo) return;
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`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}]` : '';
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export const INFO_COLOR = '#8e3cf5';
|
||||
export const ACCENT_COLOR = '#ffffff';
|
||||
export const POSITIVE_COLOR = '#82ff29';
|
||||
export const NEGATIVE_COLOR = '#ff4747';
|
||||
@@ -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<string>),
|
||||
)
|
||||
: [],
|
||||
);
|
||||
try {
|
||||
await interaction.respond(
|
||||
players
|
||||
? players.map(
|
||||
(player) =>
|
||||
({
|
||||
name: `${player.nickname} (${BLITZ_SERVERS[player.server]})`,
|
||||
value: `${player.server}/${player.account_id}`,
|
||||
} satisfies ApplicationCommandOptionChoiceData<string>),
|
||||
)
|
||||
: [],
|
||||
);
|
||||
|
||||
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`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||
export default async function getBlitzAccount(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
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}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import listClansPanServer from './listClansPanServer.js';
|
||||
export default async function getBlitzClan(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
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}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,8 @@ export default async function getWargamingResponse<Data extends object>(
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<AccountList>(
|
||||
`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<AccountList>(
|
||||
`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<AccountList>(
|
||||
`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<AccountList>(
|
||||
`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<AccountList>(
|
||||
`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<AccountList>(
|
||||
`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 [];
|
||||
}
|
||||
}
|
||||
@@ -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.`);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,6 @@ export default async function getTankStatsOverTime(
|
||||
const latestTankStatsRaw = await getWargamingResponse<TanksStats>(
|
||||
`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}/`,
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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\``,
|
||||
|
||||
Reference in new issue
Block a user