From 49545bcae00551501cd37a332e816facd744a537 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 27 May 2023 18:15:02 +0000 Subject: [PATCH] feat: blitz stars links --- package.json | 2 +- src/commands/stats.ts | 18 ++++++++++++++++-- src/commands/today.ts | 20 +++++++++++++++++--- src/core/actions/fullBlitzStarsStats.ts | 12 ++++++++++++ src/core/actions/supportBlitzStars.ts | 6 ++++++ src/core/blitz/listAccountsPanServer.ts | 12 +++++++++--- 6 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 src/core/actions/fullBlitzStarsStats.ts create mode 100644 src/core/actions/supportBlitzStars.ts diff --git a/package.json b/package.json index 01aa91906..bb5f084ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blitzkrieg", - "version": "0.6.0", + "version": "1.2.0", "description": "", "main": "index.js", "type": "module", diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 13cf5f874..b5e5d4dc6 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -1,4 +1,8 @@ -import { SlashCommandBuilder } from 'discord.js'; +import { + ActionRowBuilder, + ButtonBuilder, + SlashCommandBuilder, +} from 'discord.js'; import escapeHTML from 'escape-html'; import GenericStats from '../components/GenericStats/index.js'; import NoBattlesInPeriod from '../components/NoBattlesInPeriod.js'; @@ -6,6 +10,8 @@ import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js'; import TitleBar from '../components/TitleBar.js'; import Wrapper from '../components/Wrapper.js'; import { BLITZ_SERVERS } from '../constants/servers.js'; +import fullBlitzStarsStats from '../core/actions/fullBlitzStarsStats.js'; +import { supportBlitzStars } from '../core/actions/supportBlitzStars.js'; import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; @@ -183,7 +189,15 @@ export default { ), ); - await interaction.editReply({ files: [screenshot] }); + const actionRow = new ActionRowBuilder().addComponents( + fullBlitzStarsStats(server, accountInfo[id].nickname), + supportBlitzStars, + ); + + await interaction.editReply({ + files: [screenshot], + components: [actionRow], + }); console.log(`Showing stats for ${blitzStarsAccount.nickname}`); }, diff --git a/src/commands/today.ts b/src/commands/today.ts index 015ad3be9..ee2824dd2 100644 --- a/src/commands/today.ts +++ b/src/commands/today.ts @@ -1,4 +1,8 @@ -import { SlashCommandBuilder } from 'discord.js'; +import { + ActionRowBuilder, + ButtonBuilder, + SlashCommandBuilder, +} from 'discord.js'; import escapeHTML from 'escape-html'; import Breakdown from '../components/Breakdown.js'; import NoBattlesInPeriod from '../components/NoBattlesInPeriod.js'; @@ -6,6 +10,8 @@ import PoweredByBlitzStars from '../components/PoweredByBlitzStars.js'; import TitleBar from '../components/TitleBar.js'; import Wrapper from '../components/Wrapper.js'; import { BLITZ_SERVERS } from '../constants/servers.js'; +import fullBlitzStarsStats from '../core/actions/fullBlitzStarsStats.js'; +import { supportBlitzStars } from '../core/actions/supportBlitzStars.js'; import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; @@ -24,7 +30,7 @@ import resolveTankName from '../utilities/resolveTankName.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: new SlashCommandBuilder() @@ -105,7 +111,15 @@ export default { ), ); - await interaction.editReply({ files: [screenshot] }); + const actionRow = new ActionRowBuilder().addComponents( + fullBlitzStarsStats(server, accountInfo[id].nickname), + supportBlitzStars, + ); + + await interaction.editReply({ + files: [screenshot], + components: [actionRow], + }); console.log(`Showing daily breakdown for ${accountInfo[id].nickname}`); }, diff --git a/src/core/actions/fullBlitzStarsStats.ts b/src/core/actions/fullBlitzStarsStats.ts new file mode 100644 index 000000000..362e202c5 --- /dev/null +++ b/src/core/actions/fullBlitzStarsStats.ts @@ -0,0 +1,12 @@ +import { ButtonBuilder, ButtonStyle } from 'discord.js'; +import { BlitzServer } from '../../constants/servers.js'; + +export default function fullBlitzStarsStats( + server: BlitzServer, + username: string, +) { + return new ButtonBuilder() + .setLabel('View on BlitzStars') + .setURL(`https://www.blitzstars.com/player/${server}/${username}`) + .setStyle(ButtonStyle.Link); +} diff --git a/src/core/actions/supportBlitzStars.ts b/src/core/actions/supportBlitzStars.ts new file mode 100644 index 000000000..f7d40c6ee --- /dev/null +++ b/src/core/actions/supportBlitzStars.ts @@ -0,0 +1,6 @@ +import { ButtonBuilder, ButtonStyle } from 'discord.js'; + +export const supportBlitzStars = new ButtonBuilder() + .setLabel('Support BlitzStars') + .setURL('https://www.blitzstars.com/supporters') + .setStyle(ButtonStyle.Link); diff --git a/src/core/blitz/listAccountsPanServer.ts b/src/core/blitz/listAccountsPanServer.ts index aaf5676bd..8a5b66229 100644 --- a/src/core/blitz/listAccountsPanServer.ts +++ b/src/core/blitz/listAccountsPanServer.ts @@ -15,7 +15,9 @@ 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=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/account/list/?application_id=${ + args['wargaming-application-id'] + }&search=${encodeURIComponent(search)}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -25,7 +27,9 @@ export default async function listAccountsPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/account/list/?application_id=${ + args['wargaming-application-id'] + }&search=${encodeURIComponent(search)}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -35,7 +39,9 @@ export default async function listAccountsPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/account/list/?application_id=${ + args['wargaming-application-id'] + }&search=${encodeURIComponent(search)}&limit=${normalizedLimit}`, ).then( (value) => value &&