better seperate dev/prod env in deploy-commands, unhardcode stuff

This commit is contained in:
Jill 2023-11-11 00:24:00 +03:00
parent 255de61a2e
commit 57b96ce082
Signed by: oat
GPG Key ID: 33489AA58A955108
1 changed files with 41 additions and 31 deletions

View File

@ -1,16 +1,17 @@
const fs = require("node:fs");
const { REST, Routes } = require("discord.js");
const { token } = require('./config.json');
const { exec } = require('child_process');
const rest = new REST({ version: "9" }).setToken(token);
const appID = '898850107892596776';
console.log('building...');
exec('pnpm tsc', (err, stdout, stderr) => {
if (err) throw err;
const isDev = process.argv.includes('--dev');
console.log(stdout);
rest
.get(Routes.currentApplication())
.then(application => {
console.log(`Operating on application ${application.name}`);
if (isDev) console.log('Dev mode on - this may produce unwanted results in prod');
const appID = application.id;
const commands = [];
const commandFiles = fs.readdirSync("./dist/commands").filter((file) => file.endsWith(".js") && !file.startsWith('.'));
@ -20,6 +21,7 @@ exec('pnpm tsc', (err, stdout, stderr) => {
commands.push(command);
}
if (!isDev) {
const knownServers = require('./dist/lib/knownServers').knownServers;
const servers = [...new Set(Object.values(knownServers).reduce((a, b) => a.concat(b), []))];
@ -38,4 +40,12 @@ exec('pnpm tsc', (err, stdout, stderr) => {
.put(Routes.applicationCommands(appID), { body: globalCommands.map(cmd => cmd.data.toJSON()) })
.then(() => console.log(`${globalCommands.length} commands added globally, might take a bit to refresh`))
.catch(console.error);
});
} else {
const guildID = '741963936689160282'; // TODO
rest
.put(Routes.applicationGuildCommands(appID, guildID), { body: commands.map(cmd => cmd.data.toJSON()) })
.then(() => console.log(`${commands.length} commands added to ${guildID}`))
.catch(console.error);
}
});