@elara-services/tickets 2.0.1 → 2.0.4

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/index.js +15 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11,6 +11,8 @@ const { Collection, WebhookClient, MessageEmbed } = require("discord.js"),
11
11
 
12
12
  module.exports = class Tickets {
13
13
  constructor(options) {
14
+ if (typeof options !== "object") throw new Error(`You didn't provide any data in the constructor, fill it out!`);
15
+ if (!("client" in options) || !("prefix" in options) || !("encryptToken" in options)) throw new Error(`You forgot to fill out either 'client', 'prefix' or 'encryptToken'`)
14
16
  this.options = options;
15
17
  };
16
18
  get prefix() { return `system:ticket:${this.options.prefix}`; };
@@ -45,9 +47,9 @@ module.exports = class Tickets {
45
47
  * @param {boolean} defer
46
48
  */
47
49
  const send = async (options = {}, defer = false) => {
48
- if (defer) return int.deferReply(options).catch(this._debug);
49
- if (int.replied || int.deferred) return int.editReply(options).catch(this._debug);
50
- return int.reply(options).catch(this._debug);
50
+ if (defer) return int.deferReply(options).catch(e => this._debug(e));
51
+ if (int.replied || int.deferred) return int.editReply(options).catch(e => this._debug(e));
52
+ return int.reply(options).catch(e => this._debug(e));
51
53
  };
52
54
  switch (customId) {
53
55
  case this.prefix: {
@@ -57,7 +59,7 @@ module.exports = class Tickets {
57
59
  components: this.options.modal.questions?.length >= 1 ?
58
60
  this.options.modal.questions.slice(0, 5).map(c => ({ type: 1, components: [{ min_length: c.min_length || 10, max_length: c.max_length || 4000, type: 4, style: c.style || 2, label: c.label, value: c.value, placeholder: c.placeholder, required: c.required, custom_id: c.label || `random_${Math.floor(Math.random() * 10000)}` }] })) :
59
61
  []
60
- })).catch(this._debug);
62
+ })).catch(e => this._debug(e));
61
63
  }
62
64
  return this.handleCreate({ guild, member, category, send })
63
65
  };
@@ -100,7 +102,7 @@ module.exports = class Tickets {
100
102
  if (!user) return send({ content: `❌ I was unable to fetch the user that opened the ticket.`, ephemeral: true })
101
103
  let messages = await this.fetchMessages(channel, 5000);
102
104
  if (!messages || !messages.length) return send({ ephemeral: true, content: `❌ I was unable to close the ticket, I couldn't fetch the messages in this channel.` })
103
- let closed = await channel.delete(`${member.user.tag} (${member.id}) closed the ticket.`).catch(this._debug);
105
+ let closed = await channel.delete(`${member.user.tag} (${member.id}) closed the ticket.`).catch(e => this._debug(e));
104
106
  if (!closed) return send({ ephemeral: true, content: `${emojis.x} I was unable to delete the channel & close the ticket.` })
105
107
  return this.closeTicket({ channel, guild, user, member, messages });
106
108
  }
@@ -164,7 +166,7 @@ module.exports = class Tickets {
164
166
  { type: "role", id: guild.id, deny: ["VIEW_CHANNEL"] },
165
167
  ...permissions
166
168
  ]
167
- }).catch(this._debug);
169
+ }).catch(e => this._debug(e));
168
170
  if (!channel) return send({ content: `${emojis.x} I was unable to create the ticket channel, if this keeps happening contact one of the staff members via their DMs!` });
169
171
  let msg = await channel.send({
170
172
  content: this.options.ticketOpen?.content?.replace?.(/%user%/gi, member.user.toString())?.replace?.(/%server%/gi, guild.name) || `${member.user.toString()} 👋 Hello, please explain what you need help with.`,
@@ -176,9 +178,9 @@ module.exports = class Tickets {
176
178
  footer: { text: `To close this ticket press the button below.` }
177
179
  }],
178
180
  components: [{ type: 1, components: [{ type: 2, custom_id: `${this.prefix}:close`, label: "Close Ticket", style: 4, emoji: { name: "🔒" } }] }]
179
- }).catch(this._debug);
181
+ }).catch(e => this._debug(e));
180
182
  if (!msg) return null;
181
- if (embeds?.length <= 10) for await (const embed of embeds) await channel.send({ embeds: [ embed ] }).catch(this._debug);
183
+ if (embeds?.length <= 10) for await (const embed of embeds) await channel.send({ embeds: [ embed ] }).catch(e => this._debug(e));
182
184
  if (this.webhookOptions.id && this.webhookOptions.token) this.webhook()
183
185
  .embed({
184
186
  author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
@@ -187,7 +189,7 @@ module.exports = class Tickets {
187
189
  color: 0xFF000,
188
190
  timestamp: new Date(),
189
191
  footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` },
190
- }).send().catch(this._debug);
192
+ }).send().catch(e => this._debug(e));
191
193
  return send({
192
194
  embeds: [
193
195
  {
@@ -365,7 +367,7 @@ module.exports = class Tickets {
365
367
  .embeds(embeds)
366
368
  .button({ type: 1, components })
367
369
  .edit(m.id)
368
- .catch(this._debug);
370
+ .catch(e => this._debug(e));
369
371
  if (user) user.send({
370
372
  embeds: [{
371
373
  author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
@@ -375,8 +377,8 @@ module.exports = class Tickets {
375
377
  footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` }
376
378
  }],
377
379
  components: [{ type: 1, components }]
378
- }).catch(this._debug);
379
- }).catch(this._debug);
380
+ }).catch(e => this._debug(e));
381
+ }).catch(e => this._debug(e));
380
382
  };
381
383
  /**
382
384
  * @typedef {Object} getSupportResponse
@@ -396,7 +398,7 @@ module.exports = class Tickets {
396
398
 
397
399
  /** @private */
398
400
  _debug(...args) {
399
- if (!this.options.debug) return null;
401
+ if (!this.options?.debug) return null;
400
402
  console.log(...args);
401
403
  return null;
402
404
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/tickets",
3
- "version": "2.0.1",
3
+ "version": "2.0.4",
4
4
  "description": "Helper for tickets",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",