@elara-services/tickets 3.1.3 → 3.1.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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare module "@elara-services/tickets" {
2
2
 
3
3
  import { Client, MessageOptions, GuildMember, Guild, User, TextBasedChannel, Message, Interaction, ModalOptions } from "discord.js";
4
- import Webhook from "discord-hook";
4
+ import type { DiscordWebhook } from "@elara-services/webhooks";
5
5
 
6
6
  export interface TicketOptions {
7
7
  client: Client;
@@ -67,7 +67,7 @@ declare module "@elara-services/tickets" {
67
67
  public constructor(options: TicketOptions);
68
68
  public options: TicketOptions;
69
69
  public prefix: string;
70
- public webhook(): typeof Webhook.prototype;
70
+ public webhook(): typeof DiscordWebhook.prototype;
71
71
  public button(options: { style: 1 | 2 | 3 | 4 | 5 | number, id?: string, label?: string, emoji?: { name?: string, id?: string } }): { type: number, custom_id: string, style: number, label?: string, emoji?: { name?: string, id?: string } }
72
72
 
73
73
  public fetchMessages(channel: TextBasedChannel, limit?: number, before?: string, after?: string, around?: string): Promise<Array<Message>>
@@ -0,0 +1,36 @@
1
+ module.exports = {
2
+ NO_CONSTRUCTOR_OPTIONS: (name = "") => name ? `You didn't provide any data in the constructor, fill it out!` : `You forgot to fill out either ${name}`,
3
+
4
+ CREATE_TICKET: "Create Ticket",
5
+ MODAL_CONTENT: "Content",
6
+ MODAL_CONTENT_PLACEHOLDER: "What's the ticket about?",
7
+ OPEN_TICKET_TITLE: "Ticket: Opened",
8
+ OPEN_TICKET_CREATE: "Ticket Created!",
9
+ OPEN_TICKET_AUDIT_REASON: "Ticket created by:",
10
+ OPEN_TICKET_MESSAGE_CONTENT: "👋 Hello, please explain what you need help with.",
11
+ OPEN_TICKET_MESSAGE_FOOTER: "To close the ticket, press the button below",
12
+ OPEN_TICKET_MESSAGE: "Support will be with you shortly.",
13
+ CLOSE_TICKET_TITLE: `Ticket: Closed`,
14
+ CLOSE_TICKET: "Close Ticket",
15
+ CLOSE_TICKET_FIELD_REASON: "Close Reason",
16
+ NO_CHANNEL_CREATE: `❌ I was unable to create the ticket channel, if this keeps happening contact one of the staff members via their DMs!`,
17
+ NO_CHANNEL_DELETE: "",
18
+ GO_TO_TICKET: "Go to ticket",
19
+ TICKET_ID: "Ticket ID:",
20
+ TRANSCRIPT: "Transcript",
21
+ VIEW_HERE: "View here",
22
+ NO_REASON: "No Reason Provided",
23
+ TICKET_LIMIT_ONE_PER_USER: (name = "") => `❌ You can only create one (${name}) ticket at a time.`,
24
+ TICKET_BLOCKED: `❌ You can't create tickets, if you believe this is a mistake contact one of the staff members.`,
25
+ ONLY_SUPPORT: "Only support staff can close tickets",
26
+ TICKET_CLOSE_CONFIRM: `🤔 Are you sure you want to close the ticket?`,
27
+ TICKET_CLOSE_CONFIRM_BUTTON: `Yes, close the ticket!`,
28
+ TICKET_CLOSE_PLACEHOLDER: "What's the reason for closing the ticket?",
29
+ FORM_RESPONSES: "Form Responses",
30
+ FORM_RESPONSE: "Form Response",
31
+ ID: (id) => `ID: ${id}`,
32
+ REASON: "Reason",
33
+ BAN_REASON: "Ban Reason",
34
+ NOT_BANNED_MAIN_SERVER: `❌ You can't open this ticket due to you not being banned in the main server!`,
35
+ UNBAN: "Unban"
36
+ }
package/lib/base.js CHANGED
@@ -1,11 +1,11 @@
1
- const { getWebhookInfo, displayMessages, de, webhook } = require("./util"),
1
+ const { getWebhookInfo, displayMessages, de, webhook, getString } = require("./util"),
2
2
  { Interactions: { button, modal } } = require("@elara-services/packages"),
3
3
  { WebhookClient } = require("discord.js");
4
4
 
5
5
  module.exports = class Tickets {
6
6
  constructor(options) {
7
- if (typeof options !== "object") throw new Error(`You didn't provide any data in the constructor, fill it out!`);
8
- if (!("client" in options) || !("prefix" in options) || !("encryptToken" in options)) throw new Error(`You forgot to fill out either 'client', 'prefix' or 'encryptToken'`)
7
+ if (typeof options !== "object") throw new Error(this.str("NO_CONSTRUCTOR_OPTIONS")());
8
+ if (!("client" in options) || !("prefix" in options) || !("encryptToken" in options)) throw new Error(this.str("NO_CONSTRUCTOR_OPTIONS")("'client', 'prefix' or 'encryptToken'"));
9
9
  this.options = options;
10
10
  }
11
11
  get prefix() { return `system:ticket:${this.options.prefix}`; };
@@ -16,14 +16,15 @@ module.exports = class Tickets {
16
16
  users: this.options.support?.users || []
17
17
  }
18
18
  }
19
-
19
+ str(name) { return getString(name, this.options?.lang || "en-US"); }
20
+
20
21
  /** @private */
21
22
  _debug(...args) {
22
23
  if (this.options?.debug) console.log(...args);
23
24
  return null;
24
25
  }
25
26
 
26
- button(options = { style: 3, label: "Create Ticket", emoji: { name: "📩" } }) {
27
+ button(options = { style: 3, label: this.str("CREATE_TICKET"), emoji: { name: "📩" } }) {
27
28
  return button({ id: options?.id || this.prefix, style: options.style || 3, title: options.label, emoji: options.emoji });
28
29
  };
29
30
 
@@ -33,7 +34,7 @@ module.exports = class Tickets {
33
34
  * @param {import("@elara-services/packages").Modal['components']} [options.components]
34
35
  */
35
36
  modal(options = { title: "", components: [] }) {
36
- return modal({ id: `${this.prefix}:modal_submit`, title: options?.title || "Create Ticket", components: options?.components?.length >= 1 ? options.components : [{ type: 1, components: [{ type: 4, min_length: 10, max_length: 4000, custom_id: "message", label: "Content", style: 2, placeholder: "What's the ticket about?", required: true }] }] })
37
+ return modal({ id: `${this.prefix}:modal_submit`, title: options?.title || this.str("CREATE_TICKET"), components: options?.components?.length >= 1 ? options.components : [{ type: 1, components: [{ type: 4, min_length: 10, max_length: 4000, custom_id: "message", label: this.str("MODAL_CONTENT"), style: 2, placeholder: this.str("MODAL_CONTENT_PLACEHOLDER"), required: true }] }] })
37
38
  };
38
39
 
39
40
  async closeTicket({ member, messages, channel, guild, user, reason } = {}) {
@@ -42,12 +43,12 @@ module.exports = class Tickets {
42
43
  let embeds = [
43
44
  {
44
45
  author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
45
- title: "Ticket: Closed",
46
+ title: this.str("CLOSE_TICKET_TITLE"),
46
47
  description: `${de.user}User: ${user.toString()} \`@${user.tag}\` (${user.id})\n${de.user}Closed By: ${member.toString()} (${member.id})\n${de.channel}Channel: \`#${channel.name}\` (${channel.id})`,
47
48
  color: 0xFF0000,
48
- fields: reason ? [ { name: "Close Reason", value: reason?.slice?.(0, 1024) ?? "No Reason Provided" } ] : undefined,
49
+ fields: reason ? [ { name: this.str("CLOSE_TICKET_FIELD_REASON"), value: reason?.slice?.(0, 1024) ?? this.str("NO_REASON") } ] : undefined,
49
50
  timestamp: new Date(),
50
- footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` },
51
+ footer: { text: `${this.str("TICKET_ID")} ${channel.name.split("-")[1]}` },
51
52
  }
52
53
  ];
53
54
  new WebhookClient({ id, token })
@@ -67,11 +68,11 @@ module.exports = class Tickets {
67
68
  if (user) user.send({
68
69
  embeds: [{
69
70
  author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
70
- title: `Ticket: Closed`,
71
+ title: this.str("CLOSE_TICKET_TITLE"),
71
72
  color: 0xFF0000,
72
- fields: reason ? [ { name: "Close Reason", value: reason?.slice?.(0, 1024) ?? "No Reason Provided" } ] : undefined,
73
+ fields: reason ? [ { name: this.str("CLOSE_TICKET_FIELD_REASON"), value: reason?.slice?.(0, 1024) ?? this.str("NO_REASON") } ] : undefined,
73
74
  timestamp: new Date(),
74
- footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` }
75
+ footer: { text: `${this.str("TICKET_ID")} ${channel.name.split("-")[1]}` }
75
76
  }],
76
77
  components: [{ type: 1, components }]
77
78
  }).catch(e => this._debug(e));
package/lib/util.js CHANGED
@@ -1,6 +1,21 @@
1
1
  const { AES } = require("@elara-services/packages"),
2
2
  { Collection, version } = require("discord.js"),
3
- Webhook = require("discord-hook");
3
+ { DiscordWebhook: Webhook } = require("@elara-services/webhooks"),
4
+ defLang = require("../languages/en-US"),
5
+ pack = require("../package.json");
6
+
7
+ exports.getString = (name, lang = "en-US") => {
8
+ if (!lang) lang = "en-US";
9
+ let str = '[UNKNOWN STRING]';
10
+ if (!pack.languages.includes(lang)) lang = "en-US";
11
+ try {
12
+ let file = require(`../languages/${lang}.js`);
13
+ if (file[name]) str = file[name];
14
+ } catch {
15
+ if (defLang[name]) str = defLang[name];
16
+ };
17
+ return str;
18
+ }
4
19
 
5
20
  exports.code = (message, type = "d", token) => {
6
21
  if (!message || !type) return "";
package/lib/v13.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { MessageEmbed } = require("discord.js"),
2
2
  base = require("./base"),
3
3
  { de, code, fetchMessages, hasTicket, embed, webhook, getAppealServer } = require("./util"),
4
- { generate } = require("shortid"),
4
+ { generate } = require("@elara-services/utils"),
5
5
  { Interactions: { button, modal } } = require("@elara-services/packages");
6
6
 
7
7
  module.exports = class Tickets extends base {
@@ -161,22 +161,22 @@ module.exports = class Tickets extends base {
161
161
  if (!ban) return send(
162
162
  typeof appeals.embeds?.not_banned === "object" ?
163
163
  appeals.embeds.not_banned :
164
- { embeds: [ embed(`❌ You can't open this ticket due to you not being banned in the main server!`, { guild, color: 0xFF0000 }) ] }
164
+ { embeds: [ embed(this.str("NOT_BANNED_MAIN_SERVER"), { guild, color: 0xFF0000 }) ] }
165
165
  );
166
166
  sendBanReason = {
167
- embeds: [ embed(ban?.reason ?? "No Reason Provided", { title: "Ban Reason", guild: server }) ],
167
+ embeds: [ embed(ban?.reason ?? this.str("NO_REASON"), { title: this.str("BAN_REASON"), guild: server }) ],
168
168
  components: [
169
169
  {
170
170
  type: 1, components: [
171
- button({ id: `unban:${member.id}`, style: 4, title: "Unban", emoji: { name: "🔒" } })
171
+ button({ id: `unban:${member.id}`, style: 4, title: this.str("UNBAN"), emoji: { name: "🔒" } })
172
172
  ]
173
173
  }
174
174
  ]
175
175
  }
176
176
  }
177
177
  }
178
- let channel = await guild.channels.create(`${this.options.prefix}-${generate().slice(0, 5).replace(/-|_/g, "")}`, {
179
- type: "GUILD_TEXT", parent: category, reason: `Ticket created by: @${member.user.tag} (${member.id})`,
178
+ let channel = await guild.channels.create(`${this.options.prefix}-${generate(5)}`, {
179
+ type: "GUILD_TEXT", parent: category, reason: `${this.str("OPEN_TICKET_AUDIT_REASON")} @${member.user.tag} (${member.id})`,
180
180
  topic: `ID: ${code(member.id, "e", this.options.encryptToken)}`,
181
181
  permissionOverwrites: [
182
182
  { type: "member", id: this.options.client.user.id, allow: ["ADD_REACTIONS", "ATTACH_FILES", "SEND_MESSAGES", "READ_MESSAGE_HISTORY", "EMBED_LINKS", "USE_EXTERNAL_EMOJIS", "VIEW_CHANNEL", "MENTION_EVERYONE"] },
@@ -185,25 +185,25 @@ module.exports = class Tickets extends base {
185
185
  ...permissions
186
186
  ]
187
187
  }).catch(e => this._debug(e));
188
- if (!channel) return send({ embeds: [embed(`❌ I was unable to create the ticket channel, if this keeps happening contact one of the staff members via their DMs!`)] });
188
+ if (!channel) return send({ embeds: [embed(this.str("NO_CHANNEL_CREATE"))] });
189
189
  let msg = await channel.send({
190
- content: (this.options.ticket?.open || 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.`,
191
- embeds: (this.options.ticket?.open || this.options.ticketOpen)?.embeds || [ embed(undefined, { title: `Support will be with you shortly.`, color: 0xF50DE3, guild, footer: { text: `To close the ticket, press the button below` } }) ],
192
- components: [ { type: 1, components: [ button({ id: `${this.prefix}:close`, title: `Close Ticket`, style: 4, emoji: { name: "🔒" } }) ] }]
190
+ content: (this.options.ticket?.open || this.options.ticketOpen)?.content?.replace?.(/%user%/gi, member.user.toString())?.replace?.(/%server%/gi, guild.name) || `${member.user.toString()} ${this.str("OPEN_TICKET_MESSAGE_CONTENT")}`,
191
+ embeds: (this.options.ticket?.open || this.options.ticketOpen)?.embeds || [ embed(undefined, { title: this.str("OPEN_TICKET_MESSAGE"), color: 0xF50DE3, guild, footer: { text: this.str("OPEN_TICKET_MESSAGE_FOOTER") } }) ],
192
+ components: [ { type: 1, components: [ button({ id: `${this.prefix}:close`, title: this.str("CLOSE_TICKET"), style: 4, emoji: { name: "🔒" } }) ] }]
193
193
  }).catch(e => this._debug(e));
194
194
  if (!msg) return null;
195
195
  if (sendBanReason) await channel.send(sendBanReason).catch(e => this._debug(e));
196
196
  if (embeds?.length <= 10) for await (const embed of embeds) await channel.send({ embeds: [embed] }).catch(e => this._debug(e));
197
197
  if (this.webhookOptions.id && this.webhookOptions.token) webhook(this.webhookOptions)
198
198
  .embed(embed(`${de.user} User: ${member.user.toString()} \`@${member.user.tag}\` (${member.id})\n${de.channel} Channel: \`#${channel.name}\` (${channel.id})`, {
199
- title: `TIcket: Opened`,
199
+ title: this.str("OPEN_TICKET_TITLE"),
200
200
  color: 0xFF000,
201
- footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` },
201
+ footer: { text: `${this.str("TICKET_ID")} ${channel.name.split("-")[1]}` },
202
202
  guild
203
203
  })).send().catch(e => this._debug(e));
204
204
  return send({
205
- embeds: [ embed(channel.toString(), { color: 0xFF000, author: { name: `Ticket Created!`, icon_url: `https://cdn.discordapp.com/emojis/476629550797684736.gif` } }) ],
206
- components: [{ type: 1, components: [button({ title: "Go to ticket", url: msg.url })] }]
205
+ embeds: [ embed(channel.toString(), { color: 0xFF000, author: { name: this.str("OPEN_TICKET_CREATE"), icon_url: `https://cdn.discordapp.com/emojis/476629550797684736.gif` } }) ],
206
+ components: [{ type: 1, components: [button({ title: this.str("GO_TO_TICKET"), url: msg.url })] }]
207
207
  })
208
208
  }
209
209
 
@@ -215,4 +215,4 @@ module.exports = class Tickets extends base {
215
215
  return channel.send({ content: options?.content, files: options?.attachments, embeds: options?.embeds, components: options?.components || [{ type: 1, components: [this.button()] }] })
216
216
  .then(() => console.log(`Sent the starter message in ${channel.name} (${channel.id})`))
217
217
  };
218
- };
218
+ }
package/lib/v14.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { EmbedBuilder: MessageEmbed, InteractionType, PermissionFlagsBits, ChannelType } = require("discord.js"),
2
2
  base = require("./base"),
3
3
  { de, code, fetchMessages, hasTicket, embed, webhook, getAppealServer } = require("./util"),
4
- { generate } = require("shortid"),
4
+ { generate } = require("@elara-services/utils"),
5
5
  { Interactions: { button, modal } } = require("@elara-services/packages");
6
6
 
7
7
  module.exports = class Tickets extends base {
@@ -186,7 +186,7 @@ module.exports = class Tickets extends base {
186
186
  }
187
187
  }
188
188
  let channel = await guild.channels.create({
189
- name: `${this.options.prefix}-${generate().slice(0, 5).replace(/-|_/g, "")}`,
189
+ name: `${this.options.prefix}-${generate(5)}`,
190
190
  type: ChannelType.GuildText,
191
191
  parent: category,
192
192
  reason: `Ticket created by: @${member.user.tag} (${member.id})`,
@@ -249,7 +249,7 @@ module.exports = class Tickets extends base {
249
249
  async starterMessage(channelId, options) {
250
250
  let channel = this.options.client.channels.resolve(channelId);
251
251
  if (!channel) return Promise.reject(`No channel found for: ${channelId}`);
252
- if (!channel.isText()) return Promise.reject(`The channel ID provided isn't a text-based-channel`);
252
+ if (!channel.isTextBased()) return Promise.reject(`The channel ID provided isn't a text-based-channel`);
253
253
  if (!channel.permissionsFor?.(this.options.client.user.id)?.has?.([
254
254
  PermissionFlagsBits.ViewChannel,
255
255
  PermissionFlagsBits.SendMessages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/tickets",
3
- "version": "3.1.3",
3
+ "version": "3.1.6",
4
4
  "description": "Helper for tickets",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@elara-services/packages": "5.0.0",
19
- "discord-hook": "2.0.0",
20
- "shortid": "2.2.16"
19
+ "@elara-services/utils": "^1.2.11",
20
+ "@elara-services/webhooks": "^2.1.7"
21
21
  },
22
22
  "devDependencies": {
23
23
  "eslint": "8.20.0"
@@ -33,5 +33,8 @@
33
33
  "appeals",
34
34
  "banappeal",
35
35
  "discordtickets"
36
+ ],
37
+ "languages": [
38
+ "en-US"
36
39
  ]
37
40
  }