2022-06-08 02:57:15 +02:00
|
|
|
const fs = require("node:fs");
|
2023-06-11 17:23:57 +02:00
|
|
|
const { REST, Routes } = require("discord.js");
|
2022-06-08 02:57:15 +02:00
|
|
|
const { token } = require('./config.json');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
const rest = new REST({ version: "9" }).setToken(token);
|
2023-09-25 18:24:18 +02:00
|
|
|
const appID = '898850107892596776';
|
2022-06-08 02:57:15 +02:00
|
|
|
|
|
|
|
console.log('building...');
|
|
|
|
exec('pnpm tsc', (err, stdout, stderr) => {
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
console.log(stdout);
|
|
|
|
|
|
|
|
const commands = [];
|
2023-10-29 10:45:38 +01:00
|
|
|
const commandFiles = fs.readdirSync("./dist/commands").filter((file) => file.endsWith(".js") && !file.startsWith('.'));
|
2022-06-08 02:57:15 +02:00
|
|
|
|
|
|
|
for (const file of commandFiles) {
|
2023-10-29 10:45:38 +01:00
|
|
|
const command = require(`./dist/commands/${file}`);
|
2023-09-25 18:24:18 +02:00
|
|
|
commands.push(command);
|
2022-06-08 02:57:15 +02:00
|
|
|
}
|
|
|
|
|
2023-10-29 10:45:38 +01:00
|
|
|
const knownServers = require('./dist/lib/knownServers').knownServers;
|
2023-09-25 18:24:18 +02:00
|
|
|
const servers = [...new Set(Object.values(knownServers).reduce((a, b) => a.concat(b), []))];
|
|
|
|
|
|
|
|
for (const id of servers) {
|
|
|
|
const serverCommands = commands.filter(command => command.serverWhitelist && command.serverWhitelist.includes(id));
|
|
|
|
|
|
|
|
rest
|
|
|
|
.put(Routes.applicationGuildCommands(appID, id), { body: serverCommands.map(cmd => cmd.data.toJSON()) })
|
|
|
|
.then(() => console.log(`${serverCommands.length} commands added to ${id}`))
|
|
|
|
.catch(console.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
const globalCommands = commands.filter(command => !command.serverWhitelist);
|
|
|
|
|
2022-06-08 02:57:15 +02:00
|
|
|
rest
|
2023-09-25 18:24:18 +02:00
|
|
|
.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`))
|
2022-06-08 02:57:15 +02:00
|
|
|
.catch(console.error);
|
|
|
|
});
|