feat: bug fixes and error safety

This commit is contained in:
TresAbhi committed 2023-05-28 16:56:15 +00:00
1 parent 0b6b2ecedc
commit 780d9d5f8e
25 files changed
+136 -182

No files matched your search

+3 -3
View File
@@ -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,
+3 -3
View File
@@ -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
+1 -4
View File
@@ -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
View File
@@ -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`,
),
],
});
+1 -4
View File
@@ -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,
+1 -3
View File
@@ -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({
+1 -2
View File
@@ -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: [
+20 -21
View File
@@ -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')
}\`\`\``,
),
],
});
+1 -1
View File
@@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js';
export default {
inProduction: true,
inDevelopment: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
+1 -6
View File
@@ -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>
+1 -3
View File
@@ -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) {
+1 -6
View File
@@ -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]) => {
+1 -4
View File
@@ -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}]` : '';