catto.js 0.6.6 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bot.js +84 -4
- package/package.json +1 -1
package/Bot.js
CHANGED
|
@@ -38,6 +38,8 @@ module.exports = class extends EventEmitter {
|
|
|
38
38
|
this.buttons = new Map();
|
|
39
39
|
this.commands = new Map();
|
|
40
40
|
this.slashCommands = new Map();
|
|
41
|
+
this.userContexts = new Map();
|
|
42
|
+
this.messageContexts = new Map();
|
|
41
43
|
if (this.options.debug) {
|
|
42
44
|
this.client.on("debug", console.log);
|
|
43
45
|
}
|
|
@@ -134,12 +136,33 @@ module.exports = class extends EventEmitter {
|
|
|
134
136
|
break;
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
|
-
cmds.push(cmdo)
|
|
139
|
+
cmds.push(Object.assign(cmdo.toJSON(), {
|
|
140
|
+
"integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
|
|
141
|
+
"contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
for (var cmd of this.userContexts.values()) {
|
|
145
|
+
var cmdo = new Discord.ContextMenuCommandBuilder();
|
|
146
|
+
cmdo.setType(2).setName(cmd.name).setDMPermission(cmd.dm);
|
|
147
|
+
cmds.push(Object.assign(cmdo.toJSON(), {
|
|
148
|
+
"integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
|
|
149
|
+
"contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
for (var cmd of this.messageContexts.values()) {
|
|
153
|
+
var cmdo = new Discord.ContextMenuCommandBuilder();
|
|
154
|
+
cmdo.setType(3).setName(cmd.name).setDMPermission(cmd.dm);
|
|
155
|
+
cmds.push(Object.assign(cmdo.toJSON(), {
|
|
156
|
+
"integration_types": [0, 1].slice(0, (cmd.user ? 2 : 1)),
|
|
157
|
+
"contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
|
|
158
|
+
}));
|
|
138
159
|
}
|
|
139
160
|
if (this.options.slashListener) {
|
|
140
|
-
this.client.application.commands
|
|
161
|
+
this.client.rest.put(`/applications/${this.client.application.id}/commands`, {
|
|
162
|
+
"body": cmds
|
|
163
|
+
});
|
|
141
164
|
}
|
|
142
|
-
this.emit("running", { Discord
|
|
165
|
+
this.emit("running", { Discord });
|
|
143
166
|
});
|
|
144
167
|
this.client.on("interactionCreate", this.handleInteractionCreate.bind(this));
|
|
145
168
|
this.client.on("messageCreate", message => {
|
|
@@ -155,7 +178,6 @@ module.exports = class extends EventEmitter {
|
|
|
155
178
|
command.execute({
|
|
156
179
|
Discord,
|
|
157
180
|
User,
|
|
158
|
-
MessageBuilder,
|
|
159
181
|
message,
|
|
160
182
|
cmd,
|
|
161
183
|
args,
|
|
@@ -203,6 +225,28 @@ module.exports = class extends EventEmitter {
|
|
|
203
225
|
}));
|
|
204
226
|
return this;
|
|
205
227
|
}
|
|
228
|
+
userContext(basic, executor) {
|
|
229
|
+
if (typeof basic === "string") {
|
|
230
|
+
basic = {
|
|
231
|
+
"name": basic
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
this.userContexts.set(basic.name, Object.assign(basic, {
|
|
235
|
+
"execute": executor
|
|
236
|
+
}));
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
messageContext(basic, executor) {
|
|
240
|
+
if (typeof basic === "string") {
|
|
241
|
+
basic = {
|
|
242
|
+
"name": basic
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
this.messageContexts.set(basic.name, Object.assign(basic, {
|
|
246
|
+
"execute": executor
|
|
247
|
+
}));
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
206
250
|
command(basic, executor) {
|
|
207
251
|
if (typeof basic === "string") {
|
|
208
252
|
basic = {
|
|
@@ -270,6 +314,42 @@ module.exports = class extends EventEmitter {
|
|
|
270
314
|
} else {
|
|
271
315
|
interaction.reply({}).catch(() => {});
|
|
272
316
|
}
|
|
317
|
+
} else if (this.options.slashListener && interaction.isUserContextMenuCommand()) {
|
|
318
|
+
var command = this.userContexts.get(interaction.commandName);
|
|
319
|
+
if (command) {
|
|
320
|
+
try {
|
|
321
|
+
command.execute({
|
|
322
|
+
Discord,
|
|
323
|
+
User,
|
|
324
|
+
MessageBuilder,
|
|
325
|
+
interaction,
|
|
326
|
+
"cmd": command.name,
|
|
327
|
+
"bot": this
|
|
328
|
+
});
|
|
329
|
+
} catch(e) {
|
|
330
|
+
console.log(e);
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
interaction.reply({}).catch(() => {});
|
|
334
|
+
}
|
|
335
|
+
} else if (this.options.slashListener && interaction.isMessageContextMenuCommand()) {
|
|
336
|
+
var command = this.messageContexts.get(interaction.commandName);
|
|
337
|
+
if (command) {
|
|
338
|
+
try {
|
|
339
|
+
command.execute({
|
|
340
|
+
Discord,
|
|
341
|
+
User,
|
|
342
|
+
MessageBuilder,
|
|
343
|
+
interaction,
|
|
344
|
+
"cmd": command.name,
|
|
345
|
+
"bot": this
|
|
346
|
+
});
|
|
347
|
+
} catch(e) {
|
|
348
|
+
console.log(e);
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
interaction.reply({}).catch(() => {});
|
|
352
|
+
}
|
|
273
353
|
} else if (this.options.buttonListener && interaction.isButton()) {
|
|
274
354
|
var button = this.buttons.get(interaction.customId);
|
|
275
355
|
if (button) {
|