catto.js 0.3.4 → 0.3.6

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 CHANGED
@@ -213,38 +213,7 @@ module.exports = class extends EventEmitter {
213
213
  "type": 1
214
214
  });
215
215
  } else {
216
- var interaction = new Discord.BaseInteraction(this.client, req.body);
217
- if (interaction.isCommand()) {
218
- interaction = new Discord.CommandInteraction(this.client, req.body);
219
- if (interaction.isChatInputCommand()) {
220
- interaction = new Discord.ChatInputCommandInteraction(this.client, req.body);
221
- }
222
- } else if (interaction.isButton()) {
223
- interaction = new Discord.ButtonInteraction(this.client, req.body);
224
- }
225
- interaction.reply = async options => {
226
- if (this.deferred || this.replied) {
227
- throw new Error("Already deferred or replied.");
228
- }
229
- if (options.ephemeral !== null && options.ephemeral !== undefined) {
230
- this.ephemeral = options.ephemeral;
231
- } else {
232
- this.ephemeral = !1;
233
- }
234
- var messagePayload = null;
235
- if (options instanceof Discord.MessagePayload) {
236
- messagePayload = options;
237
- } else {
238
- messagePayload = Discord.MessagePayload.create(this, options);
239
- }
240
- var { body: data, files } = await messagePayload.resolveBody().resolveFiles();
241
- res.json({
242
- "type": 4,
243
- data
244
- });
245
- this.replied = !0;
246
- }
247
- this.handleInteractionCreate(interaction);
216
+ this.client.actions.InteractionCreate.handle(req.body);
248
217
  }
249
218
  } else {
250
219
  res.status(401).end("Invalid request signature.");
@@ -283,11 +252,13 @@ module.exports = class extends EventEmitter {
283
252
  var button = this.buttons.get(interaction.customId);
284
253
  if (button) {
285
254
  try {
286
- button({
255
+ button.execute({
287
256
  Discord,
288
257
  User,
289
258
  MessageBuilder,
290
259
  interaction,
260
+ button,
261
+ "args": button.args,
291
262
  "bot": this
292
263
  });
293
264
  } catch(e) {
package/MessageBuilder.js CHANGED
@@ -99,7 +99,9 @@ class MessageBuilder {
99
99
  if (this.bot.buttons.get(basic.id)) {
100
100
  throw new Error("ID must be unique.");
101
101
  }
102
- this.bot.buttons.set(basic.id, execute);
102
+ this.bot.buttons.set(basic.id, Object.assign(basic, {
103
+ execute
104
+ }));
103
105
  }
104
106
  return this;
105
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -39,9 +39,9 @@
39
39
  "jest": "^29.4.1"
40
40
  },
41
41
  "dependencies": {
42
- "body-parser": "^1.20.1",
43
- "discord.js": "^14.7.1",
44
- "ejs": "^3.1.8",
42
+ "body-parser": "^1.20.2",
43
+ "discord.js": "^14.8.0",
44
+ "ejs": "^3.1.9",
45
45
  "express": "^4.18.2",
46
46
  "express-session": "^1.17.3",
47
47
  "express-ws": "^5.0.2",
package/utils.js CHANGED
@@ -4,3 +4,15 @@ Array.prototype.remove = function(index) {
4
4
  Array.prototype.has = function(data) {
5
5
  return this.includes(data);
6
6
  };
7
+ var utils = {};
8
+ utils.waitFor = (obj, prop) => {
9
+ return new Promise(r => {
10
+ var i = setInterval(() => {
11
+ if (obj[prop]) {
12
+ clearInterval(i);
13
+ r();
14
+ }
15
+ }, 1);
16
+ });
17
+ };
18
+ module.exports = utils;