auto generate on start
This commit is contained in:
@@ -112,7 +112,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wrap and measure lines while preserving group and level
|
// 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;
|
const lineHeightFactor = 1.3;
|
||||||
|
|
||||||
let visualLines = []; // { text, group, level, fontSize, lineHeight }
|
let visualLines = []; // { text, group, level, fontSize, lineHeight }
|
||||||
|
|||||||
29
index.js
29
index.js
@@ -5,6 +5,7 @@ const torn = require('./torn.js');
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
|
||||||
let config, state;
|
let config, state;
|
||||||
|
let stateWasCreated = false;
|
||||||
try {
|
try {
|
||||||
console.debug("Core: Loading config")
|
console.debug("Core: Loading config")
|
||||||
config = require('./config.json');
|
config = require('./config.json');
|
||||||
@@ -23,6 +24,7 @@ try {
|
|||||||
"itemAlertLast": "2025-01-01T00:00:00.000Z"
|
"itemAlertLast": "2025-01-01T00:00:00.000Z"
|
||||||
}
|
}
|
||||||
fs.writeFileSync('./state.json', JSON.stringify(state));
|
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 => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
if (interaction.isButton()) {
|
if (interaction.isButton()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user