From 5e98bc988cedbc3571677d8fbaeb14fefa126ed0 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Fri, 16 Jun 2023 02:15:46 +0000 Subject: [PATCH] feat: implemented psa system --- package.json | 2 +- src/commands/debug.ts | 2 +- src/commands/eligible.ts | 2 +- src/commands/help.ts | 2 +- src/commands/inactive.tsx | 2 +- src/commands/ownedtanks.tsx | 2 +- src/commands/playerachievements.ts | 2 +- src/commands/playerinfo.ts | 2 +- src/commands/searchclans.ts | 2 +- src/commands/searchplayers.ts | 2 +- src/commands/searchtanks.ts | 2 +- src/commands/stats.tsx | 2 +- src/commands/tankstats.tsx | 2 +- src/commands/today.tsx | 2 +- src/commands/verify.ts | 2 +- src/constants/colors.ts | 3 ++- src/core/interaction/warningEmbed.ts | 9 +++++++++ src/core/process/psa.ts | 8 ++++---- src/events/interactionCreate.ts | 11 ++++++++++- 19 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 src/core/interaction/warningEmbed.ts diff --git a/package.json b/package.json index 6a3c36767..eb623b4c1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "dev": "yarn build --dev && yarn start", - "start": "node --enable-source-maps dist/index.cjs", + "start": "node --enable-source-maps --trace-warnings dist/index.cjs", "zip": "zip -r dist.zip dist", "build": "node scripts/build", "lint": "tsc" diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 4e2816c69..9b7175480 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -13,7 +13,7 @@ const executionStart = new Date().getTime(); export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 1e1fbb615..8dc80c208 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -26,7 +26,7 @@ export const SKILLED_CLANS: Record = { export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: false, command: new SlashCommandBuilder() diff --git a/src/commands/help.ts b/src/commands/help.ts index f8d466831..292c3d379 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -11,7 +11,7 @@ import { client } from '../index.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index 6b55d094d..8c781ee85 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -19,7 +19,7 @@ const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index e50578d3e..15d4deb09 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -40,7 +40,7 @@ const COMP_TANKS = [ export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index ec4346aa8..9846a2abc 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -17,7 +17,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index f4967ab9a..77b339508 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -13,7 +13,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index b230382a4..ef65b10b3 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 4c70a0f42..63a61d61a 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -13,7 +13,7 @@ import { AccountList } from '../types/accountList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index 77d716e08..c9760df1c 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -9,7 +9,7 @@ import { CommandRegistry } from '../events/interactionCreate.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index e28b77218..6c541451a 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -35,7 +35,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index 37c86f763..6585a2fca 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -35,7 +35,7 @@ import { AccountInfo, AllStats } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/today.tsx b/src/commands/today.tsx index 681b4ee1d..34fe10b29 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -27,7 +27,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 0f66939f3..cbc0643f8 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -15,7 +15,7 @@ import { PlayerClanData } from '../types/playerClanData.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/constants/colors.ts b/src/constants/colors.ts index ba9d56931..bb2c7f51d 100644 --- a/src/constants/colors.ts +++ b/src/constants/colors.ts @@ -1,3 +1,4 @@ -export const ACCENT_COLOR = '#ecedee'; // theme.colors.textHighContrast +export const ACCENT_COLOR = '#ecedee'; export const POSITIVE_COLOR = '#82ff29'; export const NEGATIVE_COLOR = '#ff4747'; +export const WARNING_COLOR = '#ffab00'; diff --git a/src/core/interaction/warningEmbed.ts b/src/core/interaction/warningEmbed.ts new file mode 100644 index 000000000..b8006d1c2 --- /dev/null +++ b/src/core/interaction/warningEmbed.ts @@ -0,0 +1,9 @@ +import { EmbedBuilder } from 'discord.js'; +import { WARNING_COLOR } from '../../constants/colors.js'; + +export default function warningEmbed(title: string, description: string) { + return new EmbedBuilder() + .setColor(WARNING_COLOR) + .setTitle(title) + .setDescription(description); +} diff --git a/src/core/process/psa.ts b/src/core/process/psa.ts index f4ee1df95..a08e90812 100644 --- a/src/core/process/psa.ts +++ b/src/core/process/psa.ts @@ -12,9 +12,9 @@ export const psa: PSA = {}; console.log('Caching PSA...'); fetch( 'https://gist.githubusercontent.com/tresabhi/ed4b136f08856e615212e573aabe1968/raw', -).then((response) => { - response.json().then((data) => { +) + .then((response) => response.json()) + .then((data) => { psa.data = data as PSAData; + console.log('PSA cached'); }); - console.log('PSA cached'); -}); diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 80d0d5ba6..dc71678e3 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -29,9 +29,11 @@ import tankstats from '../commands/tankstats.js'; import today from '../commands/today.js'; import verify from '../commands/verify.js'; import negativeEmbed from '../core/interaction/negativeEmbed.js'; +import warningEmbed from '../core/interaction/warningEmbed.js'; import { DISCORD_TOKEN } from '../core/process/args.js'; import getClientId from '../core/process/getClientId.js'; import isDev from '../core/process/isDev.js'; +import { psa } from '../core/process/psa.js'; import render from '../core/ui/render.js'; import { handleError } from './error.js'; @@ -149,10 +151,17 @@ export default async function interactionCreate( try { const result = await command.execute(interaction); + const normalizedResult = Array.isArray(result) ? result : [result]; const reply: InteractionEditReplyOptions = {}; + if (psa.data) { + normalizedResult.push( + warningEmbed(psa.data.title, psa.data.description), + ); + } + await Promise.all( - (Array.isArray(result) ? result : [result]).map(async (item) => { + normalizedResult.map(async (item) => { if (item instanceof EmbedBuilder) { if (!reply.embeds) reply.embeds = []; reply.embeds.push(item);