-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathregcmd.js
168 lines (152 loc) · 4.51 KB
/
regcmd.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const { REST, Routes } = require('discord.js');
const config = require('./configs/config.json');
const fetch = require('node-fetch');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
async function fetchBots() {
try {
const response = await fetch("https://" + config.secruity.IP + "/Api/Bot/ASF", {
method: "get",
headers: {
"Content-Type": "application/json",
Authentication: config.secruity.IPC_PASSWORD,
},
});
const body = await response.json();
if (body.Success) {
return Object.keys(body.Result);
}
throw new Error("Failed to fetch bot names");
} catch (error) {
console.error("Fetch error:", error);
return [];
}
}
const staticCommands = [
{
"name": "botversion",
"description": "Discord Bot-version"
},
{
"name": "exit",
"description": "Ends ASF Process"
},
{
"name": "restart",
"description": "Restart ASF"
},
{
"name": "update",
"description": "Update ASF"
}
];
async function registerCommands() {
const botNames = await fetchBots();
const basic = ["resume", "start", "stop"].map((command) => ({
"name": command,
"description": `${command.charAt(0).toUpperCase() + command.slice(1)} ASF Bot`,
"options": [
{
"name": "botname",
"description": `The bot to ${command}`,
"type": 3,
"required": false,
"choices": botNames.map(bot => ({
name: bot,
value: bot
}))
}
]
}));
const pause = {
"name" : "pause",
"description": "Pause bots farming",
"options": [
{
"name": "botname",
"description": "The bot to pause",
"type": 3,
"required": false,
"choices": botNames.map(bot => ({
name: bot,
value: bot
}))
},
{
"name": "time",
"description": "How long to pause the bot(s) for in seconds",
"type": 4,
"required": false
}
]
}
const addLicense = {
"name": "addlicense",
"description": "Add licences to you account",
"options": [
{
"name": "license_ids",
"description": "The ids to add",
"type": 3,
"required": true
},
{
"name": "botname",
"description": "The bot to addlicense",
"type": 3,
"required": false,
"choices": botNames.map(bot => ({
name: bot,
value: bot
}))
}
]
};
const redeemPoints = {
"name": "redeempoints",
"description": "Redeem items from the pointshop",
"options": [
{
"name": "item_ids",
"description": "The ids to redeem",
"type": 3,
"required": true
},
{
"name": "botname",
"description": "The bot to redeem",
"type": 3,
"required": false,
"choices": botNames.map(bot => ({
name: bot,
value: bot
}))
}
]
};
const commands = [...staticCommands, ...basic, pause, addLicense, redeemPoints];
const rest = new REST({ version: '10' }).setToken(config.bot.token);
try {
console.log('Started refreshing application (/) commands. (This might take a bit)');
await rest.put(
Routes.applicationGuildCommands(
config.bot.ID,
config.secruity.SERVER_ID
),
{ body: [] }
);
console.log('Successfully deleted all commands.');
await rest.put(
Routes.applicationGuildCommands(
config.bot.ID,
config.secruity.SERVER_ID
),
{ body: commands }
);
console.log('Successfully reloaded application (/) commands.');
process.exit(0);
} catch (error) {
console.error(`Error during command registration: ${error}`);
process.exit(1);
}
}
registerCommands();