From 8b77baccab3354f35990034e95bdd2cc53493901 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Tue, 25 Apr 2023 23:14:23 +0000 Subject: [PATCH] feat: BlitzServer type --- src/commands/eligible.ts | 12 +++++------- src/commands/ownedTanks.ts | 14 ++++++-------- src/commands/stats.ts | 12 +++++------- src/commands/verify.ts | 12 +++++------- src/constants/servers.ts | 4 +++- src/utilities/getBlitzAccount.ts | 6 +++--- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 0d9cd5860..1e588bbbb 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -5,7 +5,7 @@ import { SlashCommandBuilder, } from 'discord.js'; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; -import { SERVERS } from '../constants/servers.js'; +import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import blitzLinks from '../utilities/blitzLinks.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js'; @@ -26,9 +26,7 @@ export async function execute( interaction: ChatInputCommandInteraction, ) { const ign = interaction.options.getString('ign')!; - const server = interaction.options.getString( - 'server', - ) as keyof typeof SERVERS; + const server = interaction.options.getString('server') as BlitzServer; const clan = interaction.options.getString('clan') as keyof typeof CLANS; getBlitzAccount(interaction, ign, server, async (account) => { @@ -140,9 +138,9 @@ export const data = new SlashCommandBuilder() .setName('server') .setDescription('The Blitz server you are in') .addChoices( - { name: SERVERS.com, value: 'com' }, - { name: SERVERS.eu, value: 'eu' }, - { name: SERVERS.asia, value: 'asia' }, + { name: BLITZ_SERVERS.com, value: 'com' }, + { name: BLITZ_SERVERS.eu, value: 'eu' }, + { name: BLITZ_SERVERS.asia, value: 'asia' }, ) .setRequired(true), ) diff --git a/src/commands/ownedTanks.ts b/src/commands/ownedTanks.ts index f96d461b6..e56096e6e 100644 --- a/src/commands/ownedTanks.ts +++ b/src/commands/ownedTanks.ts @@ -4,19 +4,17 @@ import { EmbedBuilder, SlashCommandBuilder, } from 'discord.js'; +import fetch from 'node-fetch'; import { SKILLED_COLOR } from '../constants/colors.js'; -import { SERVERS } from '../constants/servers.js'; +import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import { TanksStats } from '../types/tanksStats.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; import { tankTypeEmojis, tankopedia } from '../utilities/tankopedia.js'; -import fetch from 'node-fetch'; export async function execute( interaction: ChatInputCommandInteraction, ) { - const server = interaction.options.getString( - 'server', - ) as keyof typeof SERVERS; + const server = interaction.options.getString('server') as BlitzServer; const ign = interaction.options.getString('ign')!; let tier = interaction.options.getNumber('tier'); @@ -92,9 +90,9 @@ export const data = new SlashCommandBuilder() .setDescription('The Blitz server you are in') .setRequired(true) .addChoices( - { name: SERVERS.com, value: 'com' }, - { name: SERVERS.eu, value: 'eu' }, - { name: SERVERS.asia, value: 'asia' }, + { name: BLITZ_SERVERS.com, value: 'com' }, + { name: BLITZ_SERVERS.eu, value: 'eu' }, + { name: BLITZ_SERVERS.asia, value: 'asia' }, ), ) .addStringOption((option) => diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 6e564dc15..7e095ae53 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -5,7 +5,7 @@ import { SlashCommandBuilder, } from 'discord.js'; import { SKILLED_COLOR } from '../constants/colors.js'; -import { SERVERS } from '../constants/servers.js'; +import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import blitzLinks from '../utilities/blitzLinks.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js'; @@ -15,9 +15,7 @@ export async function execute( interaction: ChatInputCommandInteraction, ) { const ign = interaction.options.getString('ign')!; - const server = interaction.options.getString( - 'server', - ) as keyof typeof SERVERS; + const server = interaction.options.getString('server') as BlitzServer; const period = interaction.options.getString('period')! as | '30' | '90' @@ -111,9 +109,9 @@ export const data = new SlashCommandBuilder() .setName('server') .setDescription('The Blitz server you are in') .addChoices( - { name: SERVERS.com, value: 'com' }, - { name: SERVERS.eu, value: 'eu' }, - { name: SERVERS.asia, value: 'asia' }, + { name: BLITZ_SERVERS.com, value: 'com' }, + { name: BLITZ_SERVERS.eu, value: 'eu' }, + { name: BLITZ_SERVERS.asia, value: 'asia' }, ) .setRequired(true), ) diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 6f3a1e28f..1c70e1262 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -7,7 +7,7 @@ import { import fetch from 'node-fetch'; import discord from '../../discord.json' assert { type: 'json' }; import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; -import { SERVERS } from '../constants/servers.js'; +import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import { PlayerClanData } from '../types/playerClanData.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; @@ -15,9 +15,7 @@ export async function execute( interaction: ChatInputCommandInteraction, ) { const ign = interaction.options.getString('ign')!; - const server = interaction.options.getString( - 'server', - ) as keyof typeof SERVERS; + const server = interaction.options.getString('server') as BlitzServer; getBlitzAccount(interaction, ign, server, async (account) => { // good match @@ -79,9 +77,9 @@ export const data = new SlashCommandBuilder() .setDescription('The Blitz server you are in') .setRequired(true) .addChoices( - { name: SERVERS.com, value: 'com' }, - { name: SERVERS.eu, value: 'eu' }, - { name: SERVERS.asia, value: 'asia' }, + { name: BLITZ_SERVERS.com, value: 'com' }, + { name: BLITZ_SERVERS.eu, value: 'eu' }, + { name: BLITZ_SERVERS.asia, value: 'asia' }, ), ) .addStringOption((option) => diff --git a/src/constants/servers.ts b/src/constants/servers.ts index 5b72dd0fa..804640b19 100644 --- a/src/constants/servers.ts +++ b/src/constants/servers.ts @@ -1,5 +1,7 @@ -export const SERVERS = { +export const BLITZ_SERVERS = { com: 'North America', eu: 'Europe', asia: 'Asia', }; + +export type BlitzServer = keyof typeof BLITZ_SERVERS; diff --git a/src/utilities/getBlitzAccount.ts b/src/utilities/getBlitzAccount.ts index 753b87039..d4437494c 100644 --- a/src/utilities/getBlitzAccount.ts +++ b/src/utilities/getBlitzAccount.ts @@ -5,16 +5,16 @@ import { } from 'discord.js'; import fetch from 'node-fetch'; import { NEGATIVE_COLOR } from '../constants/colors.js'; -import { SERVERS } from '../constants/servers.js'; +import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import { Player, Players } from '../types/players.js'; export default async function getBlitzAccount( interaction: ChatInputCommandInteraction, ign: string, - server: keyof typeof SERVERS, + server: BlitzServer, callback: (account: Player) => void, ) { - const serverName = SERVERS[server]; + const serverName = BLITZ_SERVERS[server]; const players = (await fetch( `https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${ign}`, ).then((response) => response.json())) as Players;