configurationatifying
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const torn = require('../../torn.js');
|
||||
const config = require('../../config.json');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
@@ -79,11 +80,11 @@ module.exports = {
|
||||
}
|
||||
|
||||
const baseColors = {
|
||||
core: '#FFFFFF',
|
||||
peace: '#FFFFFF',
|
||||
peaceDim: '#AAAAAA',
|
||||
war: '#FFFFFF',
|
||||
warDim: '#AAAAAA'
|
||||
core: config.upgradeColors.core,
|
||||
peace: config.upgradeColors.peace,
|
||||
peaceDim: config.upgradeColors.peaceDim,
|
||||
war: config.upgradeColors.war,
|
||||
warDim: config.upgradeColors.warDim
|
||||
};
|
||||
|
||||
|
||||
@@ -148,7 +149,7 @@ module.exports = {
|
||||
|
||||
// rounded corners, if you think i wouldnt have an ai do this for me youre silly
|
||||
const cornerRadius = 24;
|
||||
ctx.fillStyle = '#0A2472';
|
||||
ctx.fillStyle = config.upgradeColors.background;
|
||||
(function roundedRect(ctx, x, y, w, h, r) {
|
||||
const radius = Math.max(0, Math.min(r, Math.min(w / 2, h / 2)));
|
||||
ctx.beginPath();
|
||||
@@ -177,7 +178,7 @@ module.exports = {
|
||||
y += vln.lineHeight;
|
||||
}
|
||||
|
||||
const outDir = path.resolve(__dirname, '..', '..', 'public', 'images');
|
||||
const outDir = path.resolve(__dirname, '..', '..', 'public');
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
|
||||
const outFile = path.join(outDir, 'upgrades.png');
|
||||
|
||||
@@ -3,7 +3,16 @@
|
||||
"client": "DISCORD CLIENT ID",
|
||||
"alerts": "YOUR DISCORD USER ID",
|
||||
"torn": "TORN API KEY",
|
||||
"httpPort": 3000,
|
||||
"channels": {
|
||||
"ocAlert": "000000000000000000"
|
||||
},
|
||||
"upgradeColors": {
|
||||
"core": "#FFFFFF",
|
||||
"peace": "#FFFFFF",
|
||||
"peaceDim": "#AAAAAA",
|
||||
"war": "#FFFFFF",
|
||||
"warDim": "#AAAAAA",
|
||||
"background": "#0A2472"
|
||||
}
|
||||
}
|
||||
30
index.js
30
index.js
@@ -185,37 +185,11 @@ client.on(Events.MessageCreate, message => {
|
||||
}
|
||||
});
|
||||
|
||||
// ensure public folder exists
|
||||
const publicDir = path.resolve(__dirname, 'public');
|
||||
fs.mkdirSync(publicDir, { recursive: true });
|
||||
|
||||
// load optional config.json (use httpPort) or PORT env var
|
||||
let cfg = {};
|
||||
const cfgPath = path.resolve(__dirname, 'config.json');
|
||||
if (fs.existsSync(cfgPath)) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
try { cfg = require(cfgPath); } catch (e) { /* ignore */ }
|
||||
}
|
||||
const port = process.env.PORT || cfg.httpPort || 3000;
|
||||
|
||||
// create simple static server
|
||||
const port = config.httpPort || 3000;
|
||||
const app = express();
|
||||
app.use(express.static(publicDir));
|
||||
|
||||
// convenience routes
|
||||
app.get('/upgrades.png', (req, res) => {
|
||||
const imgPath = path.join(publicDir, 'images', 'upgrades.png');
|
||||
if (fs.existsSync(imgPath)) return res.sendFile(imgPath);
|
||||
res.status(404).send('Not found');
|
||||
});
|
||||
|
||||
app.get('/images', (req, res) => {
|
||||
const imgDir = path.join(publicDir, 'images');
|
||||
if (!fs.existsSync(imgDir)) return res.status(404).send('No images');
|
||||
const files = fs.readdirSync(imgDir).filter(f => /\.(png|jpe?g|gif)$/i.test(f));
|
||||
res.send(`<pre>${files.join('\n')}</pre>`);
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Static server running: http://localhost:${port}/ (serving ${publicDir})`);
|
||||
console.log(`Web: http://localhost:${port}/ (serving ${publicDir})`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user