diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index f4091a0b3..934f80c1b 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -13,7 +13,7 @@ import cmdName from '../core/interaction/cmdName.js'; import negativeEmbed from '../core/interaction/negativeEmbed.js'; import positiveEmbed from '../core/interaction/positiveEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -51,7 +51,7 @@ export default { const clan = interaction.options.getString('clan') as SkilledClan; const { id, server } = await getBlitzAccount(interaction); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const problems: TableInput = []; const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`; diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index 8d4541ee5..ddca68934 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -10,7 +10,7 @@ import getBlitzClan from '../core/blitz/getBlitzClan.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cmdName from '../core/interaction/cmdName.js'; import addClanChoices from '../core/options/addClanChoices.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import render from '../core/ui/render.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -44,14 +44,14 @@ export default { const time = new Date().getTime() / 1000; const clanData = ( await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${id}`, + `https://api.wotblitz.${server}/wotb/clans/info/?application_id=${wargamingApplicationId}&clan_id=${id}`, ) )[id]; const memberIds = clanData.members_ids; const accounts = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${ - args['wargaming-application-id'] - }&account_id=${memberIds.join(',')}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${memberIds.join( + ',', + )}`, ); const inactive = memberIds .map((memberId) => { diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index 5c98f039e..c8af38ea8 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -12,7 +12,7 @@ import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import { TIER_ROMAN_NUMERALS, tankopedia } from '../core/blitz/tankopedia.js'; import cmdName from '../core/interaction/cmdName.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import render from '../core/ui/render.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -62,14 +62,14 @@ export default { const account = await getBlitzAccount(interaction); const { id, server } = account; const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const tankStats = await getTankStats(interaction, server, id); const tanks = tankStats .map((tankData) => tankopedia[tankData.tank_id]) .filter((tank) => tank?.tier === tier); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, ); console.time('ownedtanks'); diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index 536e1bed9..ed865dc40 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -8,7 +8,7 @@ import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.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 { wargamingApplicationId } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountAchievements } from '../types/accountAchievements.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -39,11 +39,11 @@ export default { const account = await getBlitzAccount(interaction); const { id, server } = account; const accounts = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const accountsAchievements = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const accountAchievements = accountsAchievements[id]; const compound = { diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index 82c83a05d..a6f91953e 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -7,7 +7,7 @@ import cleanTable from '../core/interaction/cleanTable.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 { wargamingApplicationId } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo } from '../types/accountInfo.js'; @@ -25,7 +25,7 @@ export default { const account = await getBlitzAccount(interaction); const { id, server } = account; const accounts = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const accountInfo = accounts[id]; diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index db07881eb..3b6a50345 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -6,7 +6,7 @@ import cmdName from '../core/interaction/cmdName.js'; import infoEmbed from '../core/interaction/infoEmbed.js'; import addClanChoices from '../core/options/addClanChoices.js'; import addServerChoices from '../core/options/addServerChoices.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { ClanList } from '../types/clanList.js'; @@ -33,7 +33,7 @@ export default { const clan = interaction.options.getString('clan')!; const limit = interaction.options.getInteger('limit') ?? 25; const clanList = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${clan}&limit=${limit}`, + `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${clan}&limit=${limit}`, ); await interaction.editReply({ diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index d0f731cd8..83bc9ae79 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -7,7 +7,7 @@ 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'; +import { wargamingApplicationId } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountList } from '../types/accountList.js'; @@ -38,9 +38,9 @@ export default { const trimmedSearch = name.trim(); const players = usernamePattern.test(trimmedSearch) ? await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/list/?application_id=${ - args['wargaming-application-id'] - }&search=${encodeURIComponent(trimmedSearch)}&limit=${limit}`, + `https://api.wotblitz.${server}/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodeURIComponent( + trimmedSearch, + )}&limit=${limit}`, ) : []; diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 81602e500..947eeba37 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -28,7 +28,7 @@ import addStatPeriodChoices, { statPeriodNames, } from '../core/options/addStatPeriodChoices.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import render from '../core/ui/render.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { @@ -53,10 +53,10 @@ export default { const period = interaction.options.getString('period') as StatPeriod; const { id, server } = await getBlitzAccount(interaction); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, ); const tankStats = await getTankStats(interaction, server, id); let stats: AllStats; diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index d359e82df..45e5207d9 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -33,7 +33,7 @@ import addStatPeriodChoices, { } from '../core/options/addStatPeriodChoices.js'; import addTankChoices from '../core/options/addTankChoices.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import render from '../core/ui/render.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo, AllStats } from '../types/accountInfo.js'; @@ -59,7 +59,7 @@ export default { const blitzAccount = await getBlitzAccount(interaction); const { id, server } = blitzAccount; const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const tankStats = await getTankStats(interaction, server, id); let stats: AllStats; diff --git a/src/commands/today.tsx b/src/commands/today.tsx index 5dff3675b..8aab43f1d 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -24,7 +24,7 @@ import cmdName from '../core/interaction/cmdName.js'; import fullBlitzStarsStats from '../core/interaction/fullBlitzStarsStats.js'; import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import render from '../core/ui/render.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo, AllStats } from '../types/accountInfo.js'; @@ -50,10 +50,10 @@ export default { new Date().getTime() / 1000, ); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, ); const careerTankStatsRaw = await getTankStats(interaction, server, id); const careerStats: Record = { diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 7ffa34a8b..b88566c6b 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -7,7 +7,7 @@ import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cmdName from '../core/interaction/cmdName.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { args } from '../core/process/args.js'; +import { wargamingApplicationId } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountInfo } from '../types/accountInfo.js'; import { PlayerClanData } from '../types/playerClanData.js'; @@ -26,10 +26,10 @@ export default { const blitzAccount = await getBlitzAccount(interaction); const { id, server } = blitzAccount; const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, ); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, ); const clan = clanData[id]?.clan; const clanTag = clan ? ` [${clan!.tag}]` : ''; diff --git a/src/core/blitz/getTankStats.ts b/src/core/blitz/getTankStats.ts index 5dac94cf3..912dbce02 100644 --- a/src/core/blitz/getTankStats.ts +++ b/src/core/blitz/getTankStats.ts @@ -1,7 +1,7 @@ import { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js'; import { TanksStats } from '../../types/tanksStats.js'; -import { args } from '../process/args.js'; +import { wargamingApplicationId } from '../process/args.js'; import errorWithCause from '../process/errorWithCause.js'; import getWargamingResponse from './getWargamingResponse.js'; @@ -11,7 +11,7 @@ export default async function getTankStats( id: number, ) { const tankStats = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${wargamingApplicationId}&account_id=${id}`, ); if (tankStats[id] === null) { diff --git a/src/core/blitz/listAccountsPanServer.ts b/src/core/blitz/listAccountsPanServer.ts index 13137e432..b868eb8a5 100644 --- a/src/core/blitz/listAccountsPanServer.ts +++ b/src/core/blitz/listAccountsPanServer.ts @@ -1,6 +1,6 @@ import { BlitzServer } from '../../constants/servers.js'; import { Account, AccountList } from '../../types/accountList.js'; -import { args } from '../process/args.js'; +import { wargamingApplicationId } from '../process/args.js'; import getWargamingResponse from './getWargamingResponse.js'; export type AccountListWithServer = (Account & { @@ -19,7 +19,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) { return ( await Promise.all([ getWargamingResponse( - `https://api.wotblitz.com/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -29,7 +29,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -39,7 +39,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && diff --git a/src/core/blitz/listClansPanServer.ts b/src/core/blitz/listClansPanServer.ts index 8822831e7..cf81c97ff 100644 --- a/src/core/blitz/listClansPanServer.ts +++ b/src/core/blitz/listClansPanServer.ts @@ -1,6 +1,6 @@ import { BlitzServer } from '../../constants/servers.js'; import { Clan, ClanList } from '../../types/clanList.js'; -import { args } from '../process/args.js'; +import { wargamingApplicationId } from '../process/args.js'; import getWargamingResponse from './getWargamingResponse.js'; export type ClanListWithServer = (Clan & { @@ -15,7 +15,7 @@ export default async function listClansPanServer(search: string, limit = 9) { return ( await Promise.all([ getWargamingResponse( - `https://api.wotblitz.com/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -25,7 +25,7 @@ export default async function listClansPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -35,7 +35,7 @@ export default async function listClansPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && diff --git a/src/core/process/args.ts b/src/core/process/args.ts index 1e3f490c1..ad5eaf730 100644 --- a/src/core/process/args.ts +++ b/src/core/process/args.ts @@ -3,7 +3,7 @@ import errorWithCause from './errorWithCause.js'; type ArgumentName = 'discord-token' | 'wargaming-application-id'; -export const args: Record = { +const args: Record = { 'discord-token': '', 'wargaming-application-id': '', }; @@ -23,3 +23,6 @@ Object.keys(args).forEach((arg) => { ); } }); + +export const discordToken = args['discord-token']; +export const wargamingApplicationId = args['wargaming-application-id']; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 236a3ecf5..1ff1a293c 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -15,7 +15,7 @@ import { import { readdirSync } from 'fs'; import discord from '../../discord.json' assert { type: 'json' }; import negativeEmbed from '../core/interaction/negativeEmbed.js'; -import { args } from '../core/process/args.js'; +import { discordToken } from '../core/process/args.js'; import getClientId from '../core/process/getClientId.js'; import isDev from '../core/process/isDev.js'; import { handleError } from './error.js'; @@ -30,7 +30,7 @@ export interface CommandRegistry { autocomplete?: (interaction: AutocompleteInteraction) => void; } -const rest = new REST().setToken(args['discord-token']); +const rest = new REST().setToken(discordToken); const commandFolders = readdirSync('src/commands/'); const commandCollection = new Collection(); diff --git a/src/index.ts b/src/index.ts index bd3cf6eee..e2770895a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { Client, GatewayIntentBits } from 'discord.js'; -import { args } from './core/process/args.js'; +import { discordToken } from './core/process/args.js'; import { registerErrorHandlers } from './events/error.js'; import guildMemberAdd from './events/guildMemberAdd.js'; import interactionCreate from './events/interactionCreate.js'; @@ -15,4 +15,4 @@ client .on('ready', ready) .on('guildMemberAdd', guildMemberAdd) .on('interactionCreate', interactionCreate) - .login(args['discord-token']); + .login(discordToken);