configurationatifying
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const torn = require('../../torn.js');
|
const torn = require('../../torn.js');
|
||||||
|
const config = require('../../config.json');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
@@ -79,11 +80,11 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const baseColors = {
|
const baseColors = {
|
||||||
core: '#FFFFFF',
|
core: config.upgradeColors.core,
|
||||||
peace: '#FFFFFF',
|
peace: config.upgradeColors.peace,
|
||||||
peaceDim: '#AAAAAA',
|
peaceDim: config.upgradeColors.peaceDim,
|
||||||
war: '#FFFFFF',
|
war: config.upgradeColors.war,
|
||||||
warDim: '#AAAAAA'
|
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
|
// rounded corners, if you think i wouldnt have an ai do this for me youre silly
|
||||||
const cornerRadius = 24;
|
const cornerRadius = 24;
|
||||||
ctx.fillStyle = '#0A2472';
|
ctx.fillStyle = config.upgradeColors.background;
|
||||||
(function roundedRect(ctx, x, y, w, h, r) {
|
(function roundedRect(ctx, x, y, w, h, r) {
|
||||||
const radius = Math.max(0, Math.min(r, Math.min(w / 2, h / 2)));
|
const radius = Math.max(0, Math.min(r, Math.min(w / 2, h / 2)));
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
@@ -177,7 +178,7 @@ module.exports = {
|
|||||||
y += vln.lineHeight;
|
y += vln.lineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outDir = path.resolve(__dirname, '..', '..', 'public', 'images');
|
const outDir = path.resolve(__dirname, '..', '..', 'public');
|
||||||
fs.mkdirSync(outDir, { recursive: true });
|
fs.mkdirSync(outDir, { recursive: true });
|
||||||
|
|
||||||
const outFile = path.join(outDir, 'upgrades.png');
|
const outFile = path.join(outDir, 'upgrades.png');
|
||||||
|
|||||||
@@ -3,7 +3,16 @@
|
|||||||
"client": "DISCORD CLIENT ID",
|
"client": "DISCORD CLIENT ID",
|
||||||
"alerts": "YOUR DISCORD USER ID",
|
"alerts": "YOUR DISCORD USER ID",
|
||||||
"torn": "TORN API KEY",
|
"torn": "TORN API KEY",
|
||||||
|
"httpPort": 3000,
|
||||||
"channels": {
|
"channels": {
|
||||||
"ocAlert": "000000000000000000"
|
"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');
|
const publicDir = path.resolve(__dirname, 'public');
|
||||||
fs.mkdirSync(publicDir, { recursive: true });
|
fs.mkdirSync(publicDir, { recursive: true });
|
||||||
|
const port = config.httpPort || 3000;
|
||||||
// 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 app = express();
|
const app = express();
|
||||||
app.use(express.static(publicDir));
|
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, () => {
|
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