diff --git a/package.dist.json b/package.dist.json index 5a2dc478b..8c2a9203f 100644 --- a/package.dist.json +++ b/package.dist.json @@ -1,6 +1,6 @@ { - "main": "server.js", + "main": "server.cjs", "scripts": { - "start": "node --enable-source-maps server.cjs" + "start": "node --enable-source-maps --trace-warnings server.cjs" } } diff --git a/scripts/build.js b/scripts/build.js index 9f56eafc5..49774e78b 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,5 +1,5 @@ import { build } from 'esbuild'; -import { mkdirSync, rmSync, writeFileSync } from 'fs'; +import { copyFile, mkdir, rm, writeFile } from 'fs/promises'; import { argv } from 'process'; const isProd = !argv.includes('--dev'); @@ -9,21 +9,21 @@ const buildServer = argv.includes('--build=server') | buildAll; if (isProd) { // only remove in production to ensure no time is wasted in dev - console.log('Removing dist...'); - rmSync('dist', { recursive: true, force: true }); + console.log('🟡 Removing dist...'); + await rm('dist', { recursive: true, force: true }); + console.log('✅ Dist removed'); - console.log('Creating dist...'); - mkdirSync('dist'); + console.log('🟡 Creating dist...'); + await mkdir('dist'); + console.log('✅ Dist created'); - console.log('Caching tankopedia...'); + console.log('🟡 Caching tankopedia...'); fetch('https://www.blitzstars.com/bs-tankopedia.json') .then((response) => response.text()) - .then((tankopedia) => { - writeFileSync('./dist/tankopedia.json', tankopedia); - console.log('Tankopedia cached'); - }); + .then((tankopedia) => writeFile('./dist/tankopedia.json', tankopedia)) + .then(() => console.log('✅ Tankopedia cached')); - console.log('Caching tank averages...'); + console.log('🟡 Caching tank averages...'); fetch('https://www.blitzstars.com/api/tankaverages.json') .then((response) => response.json()) .then((individualTankAverages) => { @@ -33,10 +33,17 @@ if (isProd) { tankAverages[individualTankAverage.tank_id] = individualTankAverage; }); - writeFileSync('./dist/tankaverages.json', JSON.stringify(tankAverages)); + return writeFile( + './dist/tankaverages.json', + JSON.stringify(tankAverages), + ); + }) + .then(() => console.log('✅ Tank averages cached')); - console.log('Tank averages cached'); - }); + console.log('🟡 Copying package.json...'); + copyFile('package.dist.json', 'dist/package.json').then(() => + console.log('✅ package.json copied'), + ); } const commonOptions = { @@ -56,25 +63,25 @@ const commonOptions = { }; if (buildBot) { - console.log('Building bot...'); + console.log('🟡 Building bot...'); build({ ...commonOptions, entryPoints: ['src/bot.ts'], outfile: 'dist/bot.cjs', }).then(() => { - console.log('Bot built'); + console.log('✅ Bot built'); }); } if (buildServer) { - console.log('Building server...'); + console.log('🟡 Building server...'); build({ ...commonOptions, entryPoints: ['src/server.ts'], outfile: 'dist/server.cjs', }).then(() => { - console.log('Server built'); + console.log('✅ Server built'); }); } diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 2c92ae620..4f29fbda2 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -20,7 +20,7 @@ import { AccountInfo } from '../types/accountInfo.js'; export default { inProduction: true, - inDevelopment: false, + inDevelopment: true, inPublic: true, command: addStatTypeSubCommandGroups( diff --git a/src/components/Graph/components/Margin.tsx b/src/components/Graph/components/Margin.tsx index f27275550..144a7904a 100644 --- a/src/components/Graph/components/Margin.tsx +++ b/src/components/Graph/components/Margin.tsx @@ -1,13 +1,13 @@ import { times } from 'lodash'; import { theme } from '../../../stitches.config.js'; -import { MarginProps as RootMarginProps } from './Root.js'; +import { MarginInputProps } from './Root.js'; export enum MarginOrientation { Vertical, Horizontal, } -export interface MarginProps extends RootMarginProps { +export interface MarginProps extends MarginInputProps { verticalSeparations: number; orientation?: MarginOrientation; } diff --git a/src/components/Graph/components/Root.tsx b/src/components/Graph/components/Root.tsx index a8761d905..5bc56b5db 100644 --- a/src/components/Graph/components/Root.tsx +++ b/src/components/Graph/components/Root.tsx @@ -6,7 +6,7 @@ import { Margin, MarginOrientation } from './Margin.js'; export const GRAPH_WIDTH = 544; export const GRAPH_HEIGHT = 320; -export interface MarginProps { +export interface MarginInputProps { min: number; max: number; suffix?: string; @@ -15,8 +15,8 @@ export interface MarginProps { export interface RootProps { children: ReactNode; - verticalMargin?: MarginProps; - horizontalMargin?: MarginProps; + verticalMargin?: MarginInputProps; + horizontalMargin?: MarginInputProps; separations?: number; xMinLabel: string; xMaxLabel: string; diff --git a/src/core/node/throwError.ts b/src/core/node/throwError.ts index 2aa57dec7..2a8a8585f 100644 --- a/src/core/node/throwError.ts +++ b/src/core/node/throwError.ts @@ -1,3 +1,3 @@ -export default function throwError(message: string, cause: string) { +export default function throwError(message: string, cause?: string) { return new Error(message, { cause }); } diff --git a/src/events/interactionCreate/handlers/button.tsx b/src/events/interactionCreate/handlers/button.tsx index 4bf3d0251..657a0bcc8 100644 --- a/src/events/interactionCreate/handlers/button.tsx +++ b/src/events/interactionCreate/handlers/button.tsx @@ -1,21 +1,31 @@ import { ButtonInteraction, CacheType } from 'discord.js'; import { CYCLIC_API } from '../../../constants/cyclic.js'; import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js'; +import throwError from '../../../core/node/throwError.js'; import { commands } from '../index.js'; export default async function handleButton( interaction: ButtonInteraction, ) { + await interaction.deferUpdate(); + const url = new URL(`${CYCLIC_API}/${interaction.customId}`); const commandName = url.pathname.split('/')[1]; const button = commands[commandName]?.button; if (!button) { - console.error(`Button handler not found for "${commandName}"`); + throwError(`Button handler not found for "${commandName}"`); + return; + } + + if (interaction.message.interaction?.user.id !== interaction.user.id) { + interaction.followUp({ + ephemeral: true, + content: 'You are not the author of this command.', + }); return; } - await interaction.deferUpdate(); await interaction.message.edit( await normalizeInteractionReturnable(button(interaction)), );