From a12afae45a10695bc4ecb62f506e82b2dbe88b4a Mon Sep 17 00:00:00 2001 From: Kira Date: Sat, 13 Dec 2025 08:09:40 -0500 Subject: [PATCH] auto generate on start --- commands/utility/updateUpgrades.js | 2 +- index.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/commands/utility/updateUpgrades.js b/commands/utility/updateUpgrades.js index 041155c..9b48d28 100644 --- a/commands/utility/updateUpgrades.js +++ b/commands/utility/updateUpgrades.js @@ -112,7 +112,7 @@ module.exports = { } // Wrap and measure lines while preserving group and level - const fontSizes = { 0: 28, 1: 24, 2: 20 }; + const fontSizes = { 0: 26, 1: 22, 2: 18 }; const lineHeightFactor = 1.3; let visualLines = []; // { text, group, level, fontSize, lineHeight } diff --git a/index.js b/index.js index 59aa733..27db821 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ const torn = require('./torn.js'); const express = require('express'); let config, state; +let stateWasCreated = false; try { console.debug("Core: Loading config") config = require('./config.json'); @@ -23,6 +24,7 @@ try { "itemAlertLast": "2025-01-01T00:00:00.000Z" } fs.writeFileSync('./state.json', JSON.stringify(state)); + stateWasCreated = true; } @@ -80,6 +82,33 @@ const commandFolders = fs.readdirSync(foldersPath); } } } + +// On client ready, generate upgrades image if missing or on first run +client.on(Events.ClientReady, async () => { + try { + const imgDir = path.resolve(__dirname, 'public', 'images'); + if (!fs.existsSync(imgDir)) fs.mkdirSync(imgDir, { recursive: true }); + const imgPath = path.join(imgDir, 'upgrades.png'); + if (stateWasCreated || !fs.existsSync(imgPath)) { + const cmd = client.commands.get('updateupgrades'); + if (cmd && typeof cmd.execute === 'function') { + console.debug('Startup: Generating upgrades image (missing or first run)'); + const mockInteraction = { + deferReply: async () => {}, + editReply: async () => {} + }; + try { + await cmd.execute(mockInteraction); + console.debug('Startup: upgrades image generation complete'); + } catch (err) { + console.error('Startup: failed to generate upgrades image', err); + } + } + } + } catch (err) { + console.error('Startup: error while ensuring upgrades image', err); + } +}); client.on(Events.InteractionCreate, async interaction => { if (interaction.isButton()) {