forked from Sar00k/Femboi_OwO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.js
69 lines (69 loc) · 3.14 KB
/
deploy-commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const fs = require('fs'), { REST } = require('@discordjs/rest'), { Routes } = require('discord-api-types/v9'), { guildId, clientId, Token, language } = require('./config.json'), lang = require('./languages/' + language + '.json');
const wait = require('node:timers/promises').setTimeout;
const e = lang.deploy.error.split('-'), a = lang.deploy.answer.split('-'), q = lang.deploy.question.split('-')
const commands = [], commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
require('dotenv').config();
var token = process.env.token, cId =process.env.cId, gId =process.env.gId;
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON())
}
console.clear();
try { if (Token !== "token") var t = Token; else var t = token} catch {console.log(e[0])}
try { if (clientId !== "clientID") var c = clientId; else var c = cId} catch {console.log(e[1])}
const rest = new REST({ version: '9' }).setToken(t);
//ask user for number input from console (github copilot)
const ask = (question, callback) => {
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(q[0] + "\n1." + q[1] + "\n2." + q[2] + "\n3." + q[3] + "\n4." + q[4] + "\n5." + q[5] + "\n", (answer) => {
rl.close();
callback(answer);
});
};
//ask user for a number between 1 and 5 and execute the corresponding function
ask(lang.deploy.question, (answer) => {
if (answer == 1) {
try { if (guildId !== "guildID") var g = guildId; else var g = gId} catch {console.log(e[2])}
rest.put(Routes.applicationGuildCommands(c, g), { body: commands })
.then(() => console.log(a[0]+" => "+g))
.catch(console.error);
console.log(commands)
} else if (answer == 2) {
rest.put(Routes.applicationCommands(c), { body: commands })
.then(() => console.log(a[1]))
.catch(console.error);
console.log(commands)
} else if (answer == 3) {
try { if (guildId !== "guildID") var g = guildId; else var g = gId} catch {console.log(e[2])}
rest.get(Routes.applicationGuildCommands(c, g))
.then(data => {
const promises = [];
for (const command of data) {
const deleteUrl = `${Routes.applicationGuildCommands(c, g)}/${command.id}`;
promises.push(rest.delete(deleteUrl));
}
Promise.all(promises).then(() => console.log(a[2]+" => "+g)).catch(console.error);
})
.catch(console.error);
} else if (answer == 4) {
rest.get(Routes.applicationCommands(c))
.then(data => {
const promises = [];
for (const command of data) {
const deleteUrl = `${Routes.applicationCommands(c)}/${command.id}`;
promises.push(rest.delete(deleteUrl));
}
Promise.all(promises).then(() => console.log(a[3])).catch(console.error);
})
.catch(console.error);
} else if (answer == 5) {
console.log(a[4]);
} else {
console.log(e[3]);
}
return wait(3000)
});