catto.js 0.6.7 → 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.
Files changed (2) hide show
  1. package/Bot.js +77 -2
  2. 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
  }
@@ -139,12 +141,28 @@ module.exports = class extends EventEmitter {
139
141
  "contexts": [0, 1, 2].slice(0, (cmd.user ? 3 : 2)),
140
142
  }));
141
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
+ }));
159
+ }
142
160
  if (this.options.slashListener) {
143
161
  this.client.rest.put(`/applications/${this.client.application.id}/commands`, {
144
162
  "body": cmds
145
163
  });
146
164
  }
147
- this.emit("running", { Discord, MessageBuilder });
165
+ this.emit("running", { Discord });
148
166
  });
149
167
  this.client.on("interactionCreate", this.handleInteractionCreate.bind(this));
150
168
  this.client.on("messageCreate", message => {
@@ -160,7 +178,6 @@ module.exports = class extends EventEmitter {
160
178
  command.execute({
161
179
  Discord,
162
180
  User,
163
- MessageBuilder,
164
181
  message,
165
182
  cmd,
166
183
  args,
@@ -208,6 +225,28 @@ module.exports = class extends EventEmitter {
208
225
  }));
209
226
  return this;
210
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
+ }
211
250
  command(basic, executor) {
212
251
  if (typeof basic === "string") {
213
252
  basic = {
@@ -275,6 +314,42 @@ module.exports = class extends EventEmitter {
275
314
  } else {
276
315
  interaction.reply({}).catch(() => {});
277
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
+ }
278
353
  } else if (this.options.buttonListener && interaction.isButton()) {
279
354
  var button = this.buttons.get(interaction.customId);
280
355
  if (button) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {