diff --git a/src/behaviors/error.ts b/src/behaviors/error.ts index cf12ac0c5..37a08e84d 100644 --- a/src/behaviors/error.ts +++ b/src/behaviors/error.ts @@ -1,8 +1,8 @@ import { Client, 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'; import { client } from '../index.js'; -import isDev from '../utilities/isDev.js'; const PROCESS_ERROR_EVENTS = ['uncaughtException']; const CLIENT_ERROR_EVENTS = ['error']; diff --git a/src/behaviors/interactionCreate.ts b/src/behaviors/interactionCreate.ts index 5ff1b298c..00b725e78 100644 --- a/src/behaviors/interactionCreate.ts +++ b/src/behaviors/interactionCreate.ts @@ -11,9 +11,9 @@ import { } from 'discord.js'; import { readdirSync } from 'fs'; import discord from '../../discord.json' assert { type: 'json' }; -import { args } from '../utilities/args.js'; -import getClientId from '../utilities/getClientId.js'; -import isDev from '../utilities/isDev.js'; +import { args } from '../core/process/args.js'; +import getClientId from '../core/process/getClientId.js'; +import isDev from '../core/process/isDev.js'; export interface CommandRegistry { inDevelopment: boolean; // register with Skilled Bot (default: false) diff --git a/src/behaviors/ready.ts b/src/behaviors/ready.ts index b73c511ed..d69efdfd1 100644 --- a/src/behaviors/ready.ts +++ b/src/behaviors/ready.ts @@ -1,7 +1,7 @@ import { Client, EmbedBuilder, TextChannel } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; import { POSITIVE_COLOR } from '../constants/colors.js'; -import isDev from '../utilities/isDev.js'; +import isDev from '../core/process/isDev.js'; export default function ready(client: Client) { ( diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 2c93c0430..9aad2b627 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -2,17 +2,16 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import packageJSON from '../../package.json' assert { type: 'json' }; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { SKILLED_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'; import { client } from '../index.js'; -import cmdName from '../utilities/cmdName.js'; -import getClientId from '../utilities/getClientId.js'; -import { tankAverages } from '../utilities/tankAverages.js'; -import { tankopedia } from '../utilities/tankopedia.js'; const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -37,8 +36,6 @@ export default { uptime % 1000, )}ms\n**Tankopedia**: ${ tankopedia ? 'cached' : 'not cached' - }\n**Tank averages**: ${ - tankAverages ? 'cached' : 'not cached' }\n**Client ID**: ${getClientId()}\n**Tag**: ${ interaction.client.user.tag }`, diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 43339b393..334b2fb2d 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -3,13 +3,13 @@ import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; import { BlitzServer } from '../constants/servers.js'; -import addIGNOption from '../utilities/addIGNOption.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import blitzLinks from '../utilities/blitzLinks.js'; -import cmdName from '../utilities/cmdName.js'; -import getBlitzAccount from '../utilities/getBlitzAccount.js'; -import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js'; -import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js'; +import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; +import blitzStarsLinks from '../core/blitzstars/blitzStarsLinks.js'; +import getBlitzStarsAccount from '../core/blitzstars/getBlitzStarsAccount.js'; +import poweredByBlitzStars from '../core/blitzstars/poweredByBlitzStars.js'; +import cmdName from '../core/interaction/cmdName.js'; +import addIGNOption from '../core/options/addIGNOption.js'; +import addServerChoices from '../core/options/addServerChoices.js'; const CLANS = { sklld: { id: 71559, name: 'Skilled' }, @@ -18,7 +18,7 @@ const CLANS = { export default { inProduction: false, - inDevelopment: false, + inDevelopment: true, inPublic: false, command: new SlashCommandBuilder() @@ -133,7 +133,7 @@ export default { )}'s shortcomings for ${CLANS[clan].name} (${ clan === 'sklld' ? '30 days stats' : 'career stats' }):\n\n${issues.join('\n')}` - }\n\n${blitzLinks(server, blitzAccount.nickname)}`, + }\n\n${blitzStarsLinks(server, blitzAccount.nickname)}`, ), ), ], diff --git a/src/commands/help.ts b/src/commands/help.ts index fd693a4ab..30a58f9e1 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -6,12 +6,12 @@ import { publicCommands, } from '../behaviors/interactionCreate.js'; import { SKILLED_COLOR } from '../constants/colors.js'; +import cmdName from '../core/interaction/cmdName.js'; import { client } from '../index.js'; -import cmdName from '../utilities/cmdName.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 7623b87bb..5437da189 100644 --- a/src/commands/inactive.ts +++ b/src/commands/inactive.ts @@ -3,26 +3,26 @@ import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; import { BlitzServer } from '../constants/servers.js'; +import getClan from '../core/blitz/getClan.js'; +import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; +import cmdName from '../core/interaction/cmdName.js'; +import addServerChoices from '../core/options/addServerChoices.js'; +import { args } from '../core/process/args.js'; import { AccountInfo } from '../types/accountInfo.js'; import { ClanInfo } from '../types/clanInfo.js'; import { Clan } from '../types/clanList.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import { args } from '../utilities/args.js'; -import cmdName from '../utilities/cmdName.js'; -import getClan from '../utilities/getClan.js'; -import getWargamingResponse from '../utilities/getWargamingResponse.js'; const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() .setName(cmdName('inactive')) .setDescription('Lists all inactive players') - .addStringOption((option) => addServerChoices(option).setRequired(true)) + .addStringOption(addServerChoices) .addStringOption((option) => option .setName('name') @@ -48,19 +48,17 @@ export default { 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=${clan.clan_id}`, ); - + if (!clanInfo) return; const memberIds = clanInfo[clan.clan_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/searchplayers.ts b/src/commands/searchplayers.ts index aab60098c..2950fbce0 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -2,15 +2,15 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { SKILLED_COLOR } from '../constants/colors.js'; +import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; +import cmdName from '../core/interaction/cmdName.js'; +import addIGNOption from '../core/options/addIGNOption.js'; +import addServerChoices from '../core/options/addServerChoices.js'; +import { args } from '../core/process/args.js'; import { Players } from '../types/players.js'; -import addIGNOption from '../utilities/addIGNOption.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import { args } from '../utilities/args.js'; -import cmdName from '../utilities/cmdName.js'; -import getWargamingResponse from '../utilities/getWargamingResponse.js'; export default { - inDevelopment: false, + inDevelopment: true, inProduction: true, inPublic: true, @@ -31,10 +31,10 @@ export default { const server = interaction.options.getString('server')!; const name = interaction.options.getString('name')!; 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; await interaction.editReply({ embeds: [ diff --git a/src/commands/stats.ts b/src/commands/stats.ts index a0c301455..9b93c1e14 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -3,18 +3,18 @@ import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { SKILLED_COLOR } from '../constants/colors.js'; import { BlitzServer } from '../constants/servers.js'; +import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; +import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; +import blitzStarsLinks from '../core/blitzstars/blitzStarsLinks.js'; +import getBlitzStarsAccount from '../core/blitzstars/getBlitzStarsAccount.js'; +import poweredByBlitzStars from '../core/blitzstars/poweredByBlitzStars.js'; +import cleanTable from '../core/interaction/cleanTable.js'; +import cmdName from '../core/interaction/cmdName.js'; +import addIGNOption from '../core/options/addIGNOption.js'; +import addServerChoices from '../core/options/addServerChoices.js'; +import { args } from '../core/process/args.js'; import { AccountInfo, AllStats } from '../types/accountInfo.js'; import { BlitzStartsComputedPeriodicStatistics } from '../types/statistics.js'; -import addIGNOption from '../utilities/addIGNOption.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import { args } from '../utilities/args.js'; -import blitzLinks from '../utilities/blitzLinks.js'; -import cleanTable from '../utilities/cleanTable.js'; -import cmdName from '../utilities/cmdName.js'; -import getBlitzAccount from '../utilities/getBlitzAccount.js'; -import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js'; -import getWargamingResponse from '../utilities/getWargamingResponse.js'; -import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js'; type Period = 'today' | '30' | '90' | 'career'; @@ -27,7 +27,7 @@ const daysInPeriod: Record = { export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -201,7 +201,7 @@ export default { (stats.all.battles - stats.all.survived_battles) ).toFixed(2), ], - ])}\n\n${blitzLinks(server, blitzAccount.nickname)}` + ])}\n\n${blitzStarsLinks(server, blitzAccount.nickname)}` : 'No battles played in this period.', ), ), diff --git a/src/commands/tanks.ts b/src/commands/tanks.ts index 73a0582ed..6fdd6f5c2 100644 --- a/src/commands/tanks.ts +++ b/src/commands/tanks.ts @@ -3,14 +3,15 @@ import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { SKILLED_COLOR } from '../constants/colors.js'; import { BlitzServer } from '../constants/servers.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 addIGNOption from '../core/options/addIGNOption.js'; +import addServerChoices from '../core/options/addServerChoices.js'; +import { args } from '../core/process/args.js'; import { TanksStats } from '../types/tanksStats.js'; -import addIGNOption from '../utilities/addIGNOption.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import { args } from '../utilities/args.js'; -import cmdName from '../utilities/cmdName.js'; -import getBlitzAccount from '../utilities/getBlitzAccount.js'; -import getWargamingResponse from '../utilities/getWargamingResponse.js'; -import { TANK_TYPE_EMOJIS, tankopedia } from '../utilities/tankopedia.js'; +import resolveTankName from '../utilities/resolveTankName.js'; const COMP_TANKS = [ // light tanks @@ -35,7 +36,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -57,12 +58,11 @@ export default { const name = interaction.options.getString('name')!; const server = interaction.options.getString('server') as BlitzServer; const account = await getBlitzAccount(interaction, name, server); - if (!account) return; - const tankStats = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}`, ); + if (!tankStats) return; const tanks = tankStats[account.account_id] .map((tankData) => tankopedia.data[tankData.tank_id]) .filter((tank) => tank.tier === tier); @@ -82,8 +82,8 @@ export default { : tanks .map( (tank) => - `${TANK_TYPE_EMOJIS[tank.type]} ${markdownEscape( - tank.name, + `${TANK_TYPE_EMOJIS[tank.type]} ${resolveTankName( + tank, )} ${tank.is_premium ? '⭐' : ''}${ COMP_TANKS.includes(tank.tank_id) ? '🏆' : '' }`, diff --git a/src/commands/tankstats.ts b/src/commands/tankstats.ts index 4dcd87c2f..668b4bc86 100644 --- a/src/commands/tankstats.ts +++ b/src/commands/tankstats.ts @@ -3,24 +3,25 @@ import markdownEscape from 'markdown-escape'; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { BlitzServer } from '../constants/servers.js'; import tanksAutocomplete from '../core/autocomplete/tanks.js'; +import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; +import { tankopedia } from '../core/blitzstars/tankopedia.js'; import getPeriodicStats, { Period, } from '../core/blitztankstats/getPeriodicStats.js'; -import errorEmbed from '../core/embeds/errorEmbed.js'; -import sklldEmbed from '../core/embeds/sklldEmbed.js'; -import addIGNOption from '../utilities/addIGNOption.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import addTankChoices from '../utilities/addTankChoices.js'; -import cleanTable from '../utilities/cleanTable.js'; -import cmdName from '../utilities/cmdName.js'; -import getBlitzAccount from '../utilities/getBlitzAccount.js'; -import { tankopedia } from '../utilities/tankopedia.js'; +import cleanTable from '../core/interaction/cleanTable.js'; +import cmdName from '../core/interaction/cmdName.js'; +import errorEmbed from '../core/interaction/errorEmbed.js'; +import sklldEmbed from '../core/interaction/sklldEmbed.js'; +import addIGNOption from '../core/options/addIGNOption.js'; +import addServerChoices from '../core/options/addServerChoices.js'; +import addTankChoices from '../core/options/addTankChoices.js'; +import resolveTankName from '../utilities/resolveTankName.js'; type Periods = '30' | '60' | '90'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -76,9 +77,7 @@ export default { sklldEmbed( `${period} day stats for ${markdownEscape( blitzAccount.nickname, - )}'s ${ - tank.name ? markdownEscape(tank.name) : `Unknown Tank ${tankId}` - }`, + )}'s ${resolveTankName(tank)}`, periodicStats.length > 0 ? cleanTable([ [ diff --git a/src/commands/verify.ts b/src/commands/verify.ts index c51047f6e..7a3cb41b9 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -4,17 +4,17 @@ import discord from '../../discord.json' assert { type: 'json' }; import { CommandRegistry } from '../behaviors/interactionCreate.js'; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; import { BlitzServer } from '../constants/servers.js'; +import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; +import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; +import cmdName from '../core/interaction/cmdName.js'; +import addIGNOption from '../core/options/addIGNOption.js'; +import addServerChoices from '../core/options/addServerChoices.js'; +import { args } from '../core/process/args.js'; import { PlayerClanData } from '../types/playerClanData.js'; -import addIGNOption from '../utilities/addIGNOption.js'; -import addServerChoices from '../utilities/addServerChoices.js'; -import { args } from '../utilities/args.js'; -import cmdName from '../utilities/cmdName.js'; -import getBlitzAccount from '../utilities/getBlitzAccount.js'; -import getWargamingResponse from '../utilities/getWargamingResponse.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -24,17 +24,14 @@ export default { .addStringOption(addIGNOption), async execute(interaction) { - let name = interaction.options.getString('name')!; + const name = interaction.options.getString('name')!; const server = interaction.options.getString('server') as BlitzServer; const account = await getBlitzAccount(interaction, name, server); - if (!account) return; - - name = account.nickname; - const clanData = await getWargamingResponse( `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`, ); + if (!clanData) return; const clan = clanData[account.account_id]?.clan; const clanTag = clan ? ` [${clan!.tag}]` : ''; @@ -66,7 +63,7 @@ export default { if (member) { try { - await member.setNickname(`${name}${clanTag}`); + await member.setNickname(`${account.nickname}${clanTag}`); if (interaction.guildId === discord.guild_id) { if ( @@ -105,14 +102,14 @@ export default { .setTitle(`${interaction.user.username} is verified`) .setDescription( `The user is now verified as ${markdownEscape( - name, + account.nickname, )}${markdownEscape(clanTag)}`, ), ], }); console.log( - `${interaction.user.username} verified as ${name}${clanTag}`, + `${interaction.user.username} verified as ${account.nickname}${clanTag}`, ); } catch (error) { await interaction.editReply({ diff --git a/src/core/autocomplete/tanks.ts b/src/core/autocomplete/tanks.ts index aeb6dce0d..355a5b185 100644 --- a/src/core/autocomplete/tanks.ts +++ b/src/core/autocomplete/tanks.ts @@ -4,7 +4,8 @@ import { CacheType, } from 'discord.js'; import { go } from 'fuzzysort'; -import { tanks } from '../../utilities/tankopedia.js'; +import resolveTankName from '../../utilities/resolveTankName.js'; +import { tanks } from '../blitzstars/tankopedia.js'; export default async function tanksAutocomplete( interaction: AutocompleteInteraction, @@ -16,9 +17,7 @@ export default async function tanksAutocomplete( ? go(focusedValue, tanks, { keys: ['name'], limit: 10 }).map( (item) => ({ - name: item.obj.name - ? item.obj.name - : `Unknown Tank ${item.obj.tank_id}`, + name: item.obj.name ? item.obj.name : resolveTankName(item.obj), value: `${item.obj.tank_id}`, } satisfies ApplicationCommandOptionChoiceData), ) diff --git a/src/utilities/getBlitzAccount.ts b/src/core/blitz/getBlitzAccount.ts similarity index 87% rename from src/utilities/getBlitzAccount.ts rename to src/core/blitz/getBlitzAccount.ts index 9c39b73e1..c5c2f7597 100644 --- a/src/utilities/getBlitzAccount.ts +++ b/src/core/blitz/getBlitzAccount.ts @@ -4,10 +4,10 @@ import { EmbedBuilder, } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { NEGATIVE_COLOR } from '../constants/colors.js'; -import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; -import { Players } from '../types/players.js'; -import { args } from './args.js'; +import { NEGATIVE_COLOR } from '../../constants/colors.js'; +import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js'; +import { Players } from '../../types/players.js'; +import { args } from '../process/args.js'; import getWargamingResponse from './getWargamingResponse.js'; export default async function getBlitzAccount( diff --git a/src/utilities/getClan.ts b/src/core/blitz/getClan.ts similarity index 87% rename from src/utilities/getClan.ts rename to src/core/blitz/getClan.ts index 9db47da41..203fd1502 100644 --- a/src/utilities/getClan.ts +++ b/src/core/blitz/getClan.ts @@ -4,10 +4,10 @@ import { EmbedBuilder, } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { NEGATIVE_COLOR } from '../constants/colors.js'; -import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; -import { ClanList } from '../types/clanList.js'; -import { args } from './args.js'; +import { NEGATIVE_COLOR } from '../../constants/colors.js'; +import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js'; +import { ClanList } from '../../types/clanList.js'; +import { args } from '../process/args.js'; import getWargamingResponse from './getWargamingResponse.js'; export default async function getClan( diff --git a/src/utilities/getWargamingResponse.ts b/src/core/blitz/getWargamingResponse.ts similarity index 85% rename from src/utilities/getWargamingResponse.ts rename to src/core/blitz/getWargamingResponse.ts index 2a8501c54..71a3d58e6 100644 --- a/src/utilities/getWargamingResponse.ts +++ b/src/core/blitz/getWargamingResponse.ts @@ -1,5 +1,5 @@ import fetch from 'node-fetch'; -import { WargamingResponse } from '../types/wargamingResponse.js'; +import { WargamingResponse } from '../../types/wargamingResponse.js'; export default async function getWargamingResponse( url: string, diff --git a/src/utilities/wargamingError.ts b/src/core/blitz/wargamingError.ts similarity index 78% rename from src/utilities/wargamingError.ts rename to src/core/blitz/wargamingError.ts index 93f01c5bc..eab528da5 100644 --- a/src/utilities/wargamingError.ts +++ b/src/core/blitz/wargamingError.ts @@ -3,9 +3,9 @@ import { ChatInputCommandInteraction, EmbedBuilder, } from 'discord.js'; -import { handleError } from '../behaviors/error.js'; -import { NEGATIVE_COLOR } from '../constants/colors.js'; -import { client } from '../index.js'; +import { handleError } from '../../behaviors/error.js'; +import { NEGATIVE_COLOR } from '../../constants/colors.js'; +import { client } from '../../index.js'; export default async function wargamingError( interaction: ChatInputCommandInteraction, diff --git a/src/utilities/blitzStarsError.ts b/src/core/blitzstars/blitzStarsError.ts similarity index 100% rename from src/utilities/blitzStarsError.ts rename to src/core/blitzstars/blitzStarsError.ts diff --git a/src/utilities/blitzLinks.ts b/src/core/blitzstars/blitzStarsLinks.ts similarity index 52% rename from src/utilities/blitzLinks.ts rename to src/core/blitzstars/blitzStarsLinks.ts index e3aa3256a..619da67ea 100644 --- a/src/utilities/blitzLinks.ts +++ b/src/core/blitzstars/blitzStarsLinks.ts @@ -1,5 +1,5 @@ -import { BlitzServer } from '../constants/servers.js'; +import { BlitzServer } from '../../constants/servers.js'; -export default function blitzLinks(server: BlitzServer, nickname: string) { +export default function blitzStarsLinks(server: BlitzServer, nickname: string) { return `[View full stats](https://www.blitzstars.com/player/${server}/${nickname}) • [Support BlitzStars](https://www.blitzstars.com/supporters)`; } diff --git a/src/utilities/getBlitzStarsAccount.ts b/src/core/blitzstars/getBlitzStarsAccount.ts similarity index 83% rename from src/utilities/getBlitzStarsAccount.ts rename to src/core/blitzstars/getBlitzStarsAccount.ts index 882181cd6..459a25a70 100644 --- a/src/utilities/getBlitzStarsAccount.ts +++ b/src/core/blitzstars/getBlitzStarsAccount.ts @@ -1,7 +1,7 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import fetch from 'node-fetch'; -import { notTrackedByBlitzStars } from '../core/embeds/notTrackedByBlitzStars.js'; -import { PlayerPeriodicStatsCollection } from '../types/statistics.js'; +import { PlayerPeriodicStatsCollection } from '../../types/statistics.js'; +import { notTrackedByBlitzStars } from '../interaction/notTrackedByBlitzStars.js'; export default async function getBlitzStarsAccount( interaction: ChatInputCommandInteraction, diff --git a/src/utilities/getPlayerStats.ts b/src/core/blitzstars/getPlayerStats.ts similarity index 88% rename from src/utilities/getPlayerStats.ts rename to src/core/blitzstars/getPlayerStats.ts index 814e8f2d3..f5e5bbd3c 100644 --- a/src/utilities/getPlayerStats.ts +++ b/src/core/blitzstars/getPlayerStats.ts @@ -1,6 +1,6 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import fetch from 'node-fetch'; -import { PlayerStats } from '../types/playerStats.js'; +import { PlayerStats } from '../../types/playerStats.js'; export default async function getPlayerStats( interaction: ChatInputCommandInteraction, diff --git a/src/utilities/poweredByBlitzStars.ts b/src/core/blitzstars/poweredByBlitzStars.ts similarity index 100% rename from src/utilities/poweredByBlitzStars.ts rename to src/core/blitzstars/poweredByBlitzStars.ts diff --git a/src/utilities/tankopedia.ts b/src/core/blitzstars/tankopedia.ts similarity index 100% rename from src/utilities/tankopedia.ts rename to src/core/blitzstars/tankopedia.ts diff --git a/src/core/embeds/badNicknameFormat.ts b/src/core/embeds/badNicknameFormat.ts deleted file mode 100644 index bae003964..000000000 --- a/src/core/embeds/badNicknameFormat.ts +++ /dev/null @@ -1,6 +0,0 @@ -import errorEmbed from './errorEmbed.js'; - -export const badNicknameFormat = errorEmbed( - 'Bad nickname format', - 'I expected your nickname to be... \n\n```\nIN_GAME_NAME (SERVER) [CLAN_TAG]\n```\nUse the `/verify` command to setup your nickname correctly or manually provide me with your in-game name and server in the command.', -); diff --git a/src/utilities/cleanTable.ts b/src/core/interaction/cleanTable.ts similarity index 100% rename from src/utilities/cleanTable.ts rename to src/core/interaction/cleanTable.ts diff --git a/src/utilities/cmdName.ts b/src/core/interaction/cmdName.ts similarity index 68% rename from src/utilities/cmdName.ts rename to src/core/interaction/cmdName.ts index fe316b4a0..f53126d81 100644 --- a/src/utilities/cmdName.ts +++ b/src/core/interaction/cmdName.ts @@ -1,4 +1,4 @@ -import isDev from './isDev.js'; +import isDev from '../process/isDev.js'; export default function cmdName(name: string) { return isDev() ? `${name}dev` : name; diff --git a/src/core/embeds/errorEmbed.ts b/src/core/interaction/errorEmbed.ts similarity index 100% rename from src/core/embeds/errorEmbed.ts rename to src/core/interaction/errorEmbed.ts diff --git a/src/core/embeds/noMember.ts b/src/core/interaction/noMember.ts similarity index 100% rename from src/core/embeds/noMember.ts rename to src/core/interaction/noMember.ts diff --git a/src/core/embeds/notTrackedByBlitzStars.ts b/src/core/interaction/notTrackedByBlitzStars.ts similarity index 100% rename from src/core/embeds/notTrackedByBlitzStars.ts rename to src/core/interaction/notTrackedByBlitzStars.ts diff --git a/src/core/embeds/sklldEmbed.ts b/src/core/interaction/sklldEmbed.ts similarity index 100% rename from src/core/embeds/sklldEmbed.ts rename to src/core/interaction/sklldEmbed.ts diff --git a/src/utilities/addIGNOption.ts b/src/core/options/addIGNOption.ts similarity index 100% rename from src/utilities/addIGNOption.ts rename to src/core/options/addIGNOption.ts diff --git a/src/utilities/addServerChoices.ts b/src/core/options/addServerChoices.ts similarity index 87% rename from src/utilities/addServerChoices.ts rename to src/core/options/addServerChoices.ts index ee94f20ac..5c6ad5def 100644 --- a/src/utilities/addServerChoices.ts +++ b/src/core/options/addServerChoices.ts @@ -1,5 +1,5 @@ import { SlashCommandStringOption } from 'discord.js'; -import { BLITZ_SERVERS } from '../constants/servers.js'; +import { BLITZ_SERVERS } from '../../constants/servers.js'; export default function addServerChoices(option: SlashCommandStringOption) { return option diff --git a/src/utilities/addTankChoices.ts b/src/core/options/addTankChoices.ts similarity index 100% rename from src/utilities/addTankChoices.ts rename to src/core/options/addTankChoices.ts diff --git a/src/utilities/args.ts b/src/core/process/args.ts similarity index 100% rename from src/utilities/args.ts rename to src/core/process/args.ts diff --git a/src/utilities/getClientId.ts b/src/core/process/getClientId.ts similarity index 66% rename from src/utilities/getClientId.ts rename to src/core/process/getClientId.ts index fb554028a..bbc2506ed 100644 --- a/src/utilities/getClientId.ts +++ b/src/core/process/getClientId.ts @@ -1,4 +1,4 @@ -import discord from '../../discord.json' assert { type: 'json' }; +import discord from '../../../discord.json' assert { type: 'json' }; import isDev from './isDev.js'; export default function getClientId() { diff --git a/src/utilities/isDev.ts b/src/core/process/isDev.ts similarity index 100% rename from src/utilities/isDev.ts rename to src/core/process/isDev.ts diff --git a/src/index.ts b/src/index.ts index dbcc9b993..e399608e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { registerErrorHandlers } from './behaviors/error.js'; import guildMemberAdd from './behaviors/guildMemberAdd.js'; import interactionCreate from './behaviors/interactionCreate.js'; import ready from './behaviors/ready.js'; -import { args } from './utilities/args.js'; +import { args } from './core/process/args.js'; export const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers], diff --git a/src/utilities/compoundingAverage.ts b/src/utilities/compoundingAverage.ts deleted file mode 100644 index 7c75765f1..000000000 --- a/src/utilities/compoundingAverage.ts +++ /dev/null @@ -1,8 +0,0 @@ -export default function compoundingAverage( - average1: number, - battles1: number, - average2: number, - battles2: number, -) { - return (average2 * battles2 - average1 * battles1) / (battles2 - battles1); -} diff --git a/src/utilities/resolveTankName.ts b/src/utilities/resolveTankName.ts new file mode 100644 index 000000000..a3ab7855c --- /dev/null +++ b/src/utilities/resolveTankName.ts @@ -0,0 +1,8 @@ +import markdownEscape from 'markdown-escape'; + +export default function resolveTankName(tank: { + tank_id: number; + name?: string; +}) { + return tank.name ? markdownEscape(tank.name) : `Unknown Tank ${tank.tank_id}`; +} diff --git a/src/utilities/tankAverages.ts b/src/utilities/tankAverages.ts deleted file mode 100644 index 1acac2024..000000000 --- a/src/utilities/tankAverages.ts +++ /dev/null @@ -1,641 +0,0 @@ -import fetch from 'node-fetch'; -import { AllStats } from '../types/accountInfo.js'; - -/* -[ - { - "_id": 1, - "battle_life_time": 87518, - "total_battle_life_time": 875184684, - "number_of_players": 10000, - "tank_id": 1, - "all": { - "spotted": 616.4213, - "hits": 3994.2422, - "wins": 290.8189, - "losses": 265.5425, - "capture_points": 239.7655, - "battles": 567.3393, - "damage_dealt": 325559.6622, - "damage_received": 316424.7297, - "shots": 5125.5252, - "max_xp": 1199.4879, - "xp": 210141.9274, - "frags": 403.2506, - "survived_battles": 170.2097, - "dropped_capture_points": 619.8172 - }, - "special": { - "winrate": 51.2601, - "damageRatio": 1.0289, - "kdr": 1.0154, - "damagePerBattle": 573.8359, - "killsPerBattle": 0.7108, - "hitsPerBattle": 7.0403, - "spotsPerBattle": 1.0865, - "wpm": 0.1994, - "dpm": 223.1938, - "kpm": 0.2765, - "hitRate": 77.9284, - "survivalRate": 30.0014 - }, - "percentiles": { - "winRate": [ - 43.714, - 46.429, - 48.3395, - 50.101, - 51.835, - 53.755, - 55.8765, - 58.58, - 62.749 - ], - "damageRatio": [ - 0.622, - 0.7585, - 0.861, - 0.955, - 1.051, - 1.1535, - 1.269, - 1.428, - 1.686 - ], - "kdr": [ - 0.4935, - 0.655, - 0.79, - 0.9245, - 1.0665, - 1.226, - 1.424, - 1.702, - 2.2165 - ], - "damagePerBattle": [ - 361.925, - 437.475, - 493.325, - 544.06, - 593.75, - 645.125, - 702.875, - 776.97, - 896.835 - ], - "killsPerBattle": [ - 0.381, - 0.489, - 0.574, - 0.655, - 0.735, - 0.82, - 0.917, - 1.0425, - 1.2385 - ], - "hitsPerBattle": [ - 3.9295, - 4.6525, - 5.335, - 6.04, - 7.0145, - 8.14, - 9.343, - 10.594, - 12.313 - ], - "spotsPerBattle": [ - 0.648, - 0.789, - 0.903, - 1.008, - 1.11, - 1.214, - 1.337, - 1.474, - 1.671 - ], - "wpm": [ - 0.1582, - 0.1717, - 0.182, - 0.1908, - 0.1992, - 0.208, - 0.2179, - 0.2295, - 0.2459 - ], - "dpm": [ - 139.612, - 167.501, - 188.5304, - 207.8887, - 226.5041, - 246.3742, - 268.8646, - 297.8587, - 339.6516 - ], - "kpm": [ - 0.1511, - 0.1916, - 0.222, - 0.2502, - 0.2791, - 0.31, - 0.3448, - 0.39, - 0.463 - ], - "hitRate": [ - 69.3035, - 73.4495, - 75.77, - 77.587, - 79.0885, - 80.4375, - 81.807, - 83.251, - 84.895 - ], - "survivalRate": [ - 20.495, - 24.071, - 26.696, - 29.07, - 31.2725, - 33.632, - 36.387, - 39.651, - 44.9655 - ] - }, - "percentiles_player_count": 10000, - "meanSd": { - "winrateMean": 52.6691, - "winrateSd": 7.501, - "hitRateMean": 76.8419, - "hitRateSd": 11.8812, - "survivalRateMean": 31.8702, - "survivalRateSd": 10.2378, - "damageRatioMean": 1.1025, - "damageRatioSd": 0.4427, - "kdrMean": 1.2394, - "kdrSd": 0.7795, - "dpbMean": 608.4002, - "dpbSd": 217.8841, - "kpbMean": 0.774, - "kpbSd": 0.3449, - "hpbMean": 7.5795, - "hpbSd": 3.3543, - "spbMean": 1.1317, - "spbSd": 0.4135 - }, - "shotEff": 81.3044, - "last_update": 1678771055585 - }, - { - "_id": 17, - "battle_life_time": 106463, - "total_battle_life_time": 1064627816, - "number_of_players": 10000, - "tank_id": 17, - "all": { - "spotted": 707.8467, - "hits": 3128.9507, - "wins": 337.453, - "losses": 326.723, - "capture_points": 273.1936, - "battles": 673.9891, - "damage_dealt": 371207.8193, - "damage_received": 386415.786, - "shots": 4144.258, - "max_xp": 1191.7719, - "xp": 242667.5486, - "frags": 462.8709, - "survived_battles": 200.5843, - "dropped_capture_points": 595.6305 - }, - "special": { - "winrate": 50.068, - "damageRatio": 0.9606, - "kdr": 0.9777, - "damagePerBattle": 550.7623, - "killsPerBattle": 0.6868, - "hitsPerBattle": 4.6424, - "spotsPerBattle": 1.0502, - "wpm": 0.1902, - "dpm": 209.2043, - "kpm": 0.2609, - "hitRate": 75.5009, - "survivalRate": 29.7608 - }, - "percentiles": { - "winRate": [ - 43.103, - 45.24, - 46.8795, - 48.332, - 49.8065, - 51.196, - 52.918, - 55.1185, - 59.0235 - ], - "damageRatio": [ - 0.584, - 0.704, - 0.789, - 0.861, - 0.935, - 1.018, - 1.112, - 1.244, - 1.465 - ], - "kdr": [ - 0.485, - 0.617, - 0.726, - 0.827, - 0.9345, - 1.056, - 1.2155, - 1.428, - 1.845 - ], - "damagePerBattle": [ - 345.69, - 412.49, - 459.44, - 499.55, - 540.035, - 584.985, - 633.355, - 699.025, - 811.67 - ], - "killsPerBattle": [ - 0.375, - 0.465, - 0.533, - 0.596, - 0.659, - 0.73, - 0.811, - 0.918, - 1.102 - ], - "hitsPerBattle": [ - 3.195, - 3.69, - 4.068, - 4.362, - 4.647, - 4.9485, - 5.271, - 5.656, - 6.2055 - ], - "spotsPerBattle": [ - 0.629, - 0.752, - 0.8575, - 0.956, - 1.049, - 1.1465, - 1.262, - 1.4, - 1.603 - ], - "wpm": [ - 0.1528, - 0.1655, - 0.1743, - 0.1825, - 0.19, - 0.1979, - 0.2065, - 0.2171, - 0.2339 - ], - "dpm": [ - 131.2505, - 155.7725, - 174.1863, - 189.9051, - 205.3328, - 221.5702, - 240.8529, - 264.8677, - 307.253 - ], - "kpm": [ - 0.1463, - 0.1799, - 0.2042, - 0.2268, - 0.2493, - 0.2736, - 0.3036, - 0.3432, - 0.4089 - ], - "hitRate": [ - 65.617, - 70.051, - 72.553, - 74.549, - 76.2425, - 77.7385, - 79.2765, - 80.858, - 83.018 - ], - "survivalRate": [ - 20.444, - 23.447, - 25.6725, - 27.725, - 29.6715, - 31.6955, - 33.923, - 36.803, - 41.437 - ] - }, - "percentiles_player_count": 10000, - "meanSd": { - "winrateMean": 50.5356, - "winrateSd": 6.6334, - "hitRateMean": 74.5835, - "hitRateSd": 9.6505, - "survivalRateMean": 30.3145, - "survivalRateSd": 8.9155, - "damageRatioMean": 0.9912, - "damageRatioSd": 0.3822, - "kdrMean": 1.0923, - "kdrSd": 0.6887, - "dpbMean": 562.3008, - "dpbSd": 195.5684, - "kpbMean": 0.7088, - "kpbSd": 0.312, - "hpbMean": 4.6704, - "hpbSd": 1.2382, - "spbMean": 1.0833, - "spbSd": 0.3853 - }, - "shotEff": 154.9048, - "last_update": 1677561392794 - }, - { - "_id": 33, - "battle_life_time": 47339, - "total_battle_life_time": 473389371, - "number_of_players": 10000, - "tank_id": 33, - "all": { - "spotted": 318.6163, - "hits": 1918.026, - "wins": 161.9938, - "losses": 135.1226, - "capture_points": 163.6557, - "battles": 300.0921, - "damage_dealt": 199194.9486, - "damage_received": 183696.4883, - "shots": 2420.9167, - "max_xp": 1377.8881, - "xp": 148216.5586, - "frags": 257.9868, - "survived_battles": 103.0862, - "dropped_capture_points": 260.2245 - }, - "special": { - "winrate": 53.9814, - "damageRatio": 1.0844, - "kdr": 1.3095, - "damagePerBattle": 663.7794, - "killsPerBattle": 0.8597, - "hitsPerBattle": 6.3915, - "spotsPerBattle": 1.0617, - "wpm": 0.2053, - "dpm": 252.4707, - "kpm": 0.327, - "hitRate": 79.2273, - "survivalRate": 34.3515 - }, - "percentiles": { - "winRate": [ - 45.669, - 48.923, - 51.2915, - 53.4155, - 55.4195, - 57.519, - 59.783, - 62.553, - 66.882 - ], - "damageRatio": [ - 0.695, - 0.839, - 0.949, - 1.05, - 1.156, - 1.261, - 1.378, - 1.5385, - 1.7965 - ], - "kdr": [ - 0.705, - 0.915, - 1.086, - 1.254, - 1.424, - 1.617, - 1.86, - 2.1795, - 2.7895 - ], - "damagePerBattle": [ - 450.59, - 533.78, - 595.96, - 652.085, - 702.07, - 755.18, - 810.885, - 880.155, - 980.285 - ], - "killsPerBattle": [ - 0.521, - 0.653, - 0.743, - 0.831, - 0.912, - 0.994, - 1.09, - 1.208, - 1.382 - ], - "hitsPerBattle": [ - 4.8345, - 5.4535, - 5.933, - 6.3205, - 6.716, - 7.0945, - 7.508, - 8, - 8.7625 - ], - "spotsPerBattle": [ - 0.67, - 0.812, - 0.919, - 1.0105, - 1.096, - 1.188, - 1.284, - 1.401, - 1.568 - ], - "wpm": [ - 0.1667, - 0.1817, - 0.1923, - 0.2014, - 0.2098, - 0.2185, - 0.2272, - 0.2377, - 0.2524 - ], - "dpm": [ - 170.9212, - 203.7661, - 227.6935, - 247.3242, - 266.3126, - 284.356, - 303.8913, - 325.3216, - 359.4345 - ], - "kpm": [ - 0.2015, - 0.2506, - 0.2854, - 0.3168, - 0.3443, - 0.3722, - 0.4033, - 0.4413, - 0.4974 - ], - "hitRate": [ - 72.5495, - 75.8405, - 77.7595, - 79.216, - 80.451, - 81.597, - 82.783, - 83.9565, - 85.5015 - ], - "survivalRate": [ - 24.224, - 28.201, - 31.128, - 33.803, - 36.3355, - 38.8445, - 41.722, - 45.3425, - 51.186 - ] - }, - "percentiles_player_count": 10000, - "meanSd": { - "winrateMean": 55.9148, - "winrateSd": 8.2526, - "hitRateMean": 79.1161, - "hitRateSd": 8.4723, - "survivalRateMean": 36.9185, - "survivalRateSd": 10.7729, - "damageRatioMean": 1.2076, - "damageRatioSd": 0.454, - "kdrMean": 1.6293, - "kdrSd": 0.9557, - "dpbMean": 709.1817, - "dpbSd": 212.8413, - "kpbMean": 0.9358, - "kpbSd": 0.3445, - "hpbMean": 6.7378, - "hpbSd": 1.634, - "spbMean": 1.1089, - "spbSd": 0.3544 - }, - "shotEff": 117.2326, - "last_update": 1681791408996 - }, - { - "_id": 49, - "battle_life_time": 107010, - "total_battle_life_time": 1070098258, - "number_of_players": 10000, - "tank_id": 49, - "all": { - "spotted": 998.0054, - "hits": 3884.2635, - "wins": 334.7506, - "losses": 306.5336, - "capture_points": 69.2516, - "battles": 646.2226, - "damage_dealt": 789251.7596, - "damage_received": 715410.0777, - "shots": 4686.3514, - "max_xp": 1912.2171, - "xp": 465914.6865, - "frags": 489.4052, - "survived_battles": 205.6315, - "dropped_capture_points": 272.3055 - }, - "special": { - "winrate": 51.8011, - "damageRatio": 1.1032, - "kdr": 1.1108, - "damagePerBattle": 1221.3311, - "killsPerBattle": 0.7573, - "hitsPerBattle": 6.01 - } - } -] -*/ - -export const tankAverages = (await ( - await fetch('https://www.blitzstars.com/api/tankaverages.json') -).json()) as TankAverages; - -export type TankAverages = { - _id: number; - battle_life_time: number; - total_battle_life_time: number; - number_of_players: number; - tank_id: number; - all: AllStats; - special: { - winrate: number; - damageRatio: number; - kdr: number; - damagePerBattle: number; - killsPerBattle: number; - hitsPerBattle: number; - }; -}[]; diff --git a/src/utilities/wn8.ts b/src/utilities/wn8.ts deleted file mode 100644 index 0c35ecc02..000000000 --- a/src/utilities/wn8.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { PeriodStatistics } from '../types/statistics.js'; -import { tankAverages } from './tankAverages.js'; - -// const expDmg = 2300; -// const expSpot = 1; -// const expFrag = 0.5; -// const expDef = 5; -// const expWinRate = 48; - -const expDmg = - tankAverages.reduce((a, b) => a + b.special.damagePerBattle, 0) / tankAverages.length; -const expSpot = - tankAverages.reduce((a, b) => a + (b.all.spotted / b.all.battles), 0) / tankAverages.length; -const expFrag = - tankAverages.reduce((a, b) => a + b.special.killsPerBattle, 0) / tankAverages.length; -const expDef = - tankAverages.reduce((a, b) => a + b.all.capture_points / b.all.battles, 0) / - tankAverages.length; -const expWinRate = - tankAverages.reduce((a, b) => a + b.special.winrate, 0) / tankAverages.length; - -export default function wn8(stats: PeriodStatistics) { - const rDAMAGE = stats.special.dpb / expDmg; - - const rDAMAGEc = Math.max(0, (rDAMAGE - 0.22) / (1 - 0.22)); - - const rSPOT = stats.special.spb / expSpot; - const rFRAG = stats.special.kpb / expFrag; - const rDEF = stats.all.capture_points / stats.all.battles / expDef; - const rWIN = stats.special.winrate / expWinRate; - - const rFRAGc = Math.max( - 0, - Math.min(rDAMAGEc + 0.2, (rFRAG - 0.12) / (1 - 0.12)), - ); - const rSPOTc = Math.max( - 0, - Math.min(rDAMAGEc + 0.1, (rSPOT - 0.38) / (1 - 0.38)), - ); - const rDEFc = Math.max(0, Math.min(rDAMAGEc + 0.1, (rDEF - 0.1) / (1 - 0.1))); - - let rWINc = - 0.09 + - 0.613 * rDAMAGEc + - 0.131 * rFRAGc * rDAMAGEc + - 0.097 * rFRAGc * rSPOTc + - 0.047 * rFRAGc * rDEFc; - - rWINc = Math.max(0, (rWIN - 0.71) / (1 - 0.71)); - - const WN8 = - 980 * rDAMAGEc + - 210 * rDAMAGEc * rFRAGc + - 155 * rFRAGc * rSPOTc + - 75 * rDEFc * rFRAGc + - 145 * Math.min(1.8, rWINc); - - return WN8; -}