@elara-services/tickets 4.3.6 → 4.4.0

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/lib/base.js CHANGED
@@ -3,10 +3,12 @@ const {
3
3
  Interactions: { button },
4
4
  ButtonStyle,
5
5
  } = require("@elara-services/packages");
6
- const { is, status, isV13, embedComment, log, emitPackageMessage } = require("@elara-services/utils");
6
+ const { is, status, isV13, embedComment, log, emitPackageMessage, hasBit } = require("@elara-services/utils");
7
7
  const { WebhookClient } = require("discord.js");
8
8
  const { name, version, funding } = require("../package.json");
9
9
  const { inspect } = require("util");
10
+ const { REST } = require("@discordjs/rest");
11
+ const { Routes } = require("discord-api-types/v10");
10
12
  const required = ["client", "prefix", "encryptToken"];
11
13
  const moment = require("moment");
12
14
 
@@ -24,6 +26,7 @@ module.exports = class Tickets {
24
26
  }
25
27
  }
26
28
  this.options = options;
29
+ this.rest = new REST(options.client.token);
27
30
  if (options.suppressPatreon !== true) {
28
31
  emitPackageMessage(`${name} - thanks`, () => {
29
32
  log(`[${name}, v${version}]: Thanks for using the package!`, `Please support the packages via ${funding.map((c) => c.url).join(" OR ")}`);
@@ -298,19 +301,43 @@ module.exports = class Tickets {
298
301
 
299
302
  /**
300
303
  * @param {string} channelId
301
- * @param {import("discord.js").MessageOptions} options
304
+ * @param {import("discord.js").MessageCreateOptions} options
302
305
  */
303
306
  async starterMessage(channelId, options) {
304
307
  let channel = this.options.client.channels.resolve(channelId);
305
308
  if (!channel) {
306
309
  return Promise.reject(this.str("NO_CHANNEL_FOUND")(channelId));
307
310
  }
311
+ if (!options) {
312
+ throw new Error(`No options provided`);
313
+ }
314
+
315
+ if (hasBit(options.flags, 1 << 15)) {
316
+ return await this.rest
317
+ .post(Routes.channelMessages(channelId), {
318
+ body: {
319
+ flags: options.flags,
320
+ components: options.components || [{ type: 1, components: [this.button()] }],
321
+ allowed_mentions: options.allowedMentions
322
+ ? {
323
+ parse: options.allowedMentions.parse,
324
+ users: options.allowedMentions.users,
325
+ roles: options.allowedMentions.roles,
326
+ replied_user: options.allowedMentions.repliedUser ?? undefined,
327
+ }
328
+ : undefined,
329
+ },
330
+ })
331
+ .catch(() => null);
332
+ }
333
+
308
334
  return channel
309
335
  .send({
310
- content: options?.content,
311
- files: options?.attachments,
312
- embeds: options?.embeds,
313
- components: options?.components || [{ type: 1, components: [this.button()] }],
336
+ flags: options.flags,
337
+ content: options.content,
338
+ files: options.attachments,
339
+ embeds: options.embeds,
340
+ components: options.components || [{ type: 1, components: [this.button()] }],
314
341
  })
315
342
  .then(() => console.log(`✅`));
316
343
  }
package/lib/html.js CHANGED
@@ -1,18 +1,22 @@
1
+ const { make } = require("@elara-services/utils");
2
+
1
3
  exports.discordView = function (messages) {
2
4
  return `<!DOCTYPE html>
3
5
  <head>
4
6
  <title>Discord Viewer</title>
5
- <link href="https://cdn.discordapp.com/emojis/880708306761564220.png" rel="icon" />
7
+ <link href="${make.emojiURL("880708306761564220")}" rel="icon" />
6
8
  <script>
7
9
  window.onload = _ => {
8
10
  let doc = document.getElementById("messages");
9
- if (doc.innerHTML.includes('new_timestamp="')) {
10
- let matches = doc.innerHTML.match(new RegExp(\`new_timestamp=".*?"\`, "gi"))
11
+ let text = doc.innerHTML;
12
+ if (text.includes('new_timestamp="')) {
13
+ let matches = text.match(new RegExp(\`new_timestamp=".*?"\`, "gi"))
11
14
  if (matches) {
12
15
  for (const match of matches) {
13
- document.getElementById("messages").innerHTML = doc.innerHTML.replace(match, \`timestamp="\${new Date(match.split("new_timestamp=\\"")[1].replace('"', "")).toLocaleString()}"\`)
16
+ text = text.replace(match, \`timestamp="\${new Date(match.split("new_timestamp=\\"")[1].replace('"', "")).toLocaleString()}"\`)
14
17
  }
15
18
  }
19
+ document.getElementById("messages").innerHTML = text;
16
20
  }
17
21
  setTimeout(_ => hidePreloader(), 1000)
18
22
  }
@@ -45,7 +49,7 @@ exports.discordView = function (messages) {
45
49
  background-color: transparent;
46
50
  left: 50%;
47
51
  top: 50%;
48
- background-image: url(https://cdn.discordapp.com/emojis/634127148696862753.gif?v=1);
52
+ background-image: url(${make.emojiURL("634127148696862753", "gif")});
49
53
  background-repeat: no-repeat;
50
54
  background-position: center;
51
55
  margin: -100px 0 0 -100px;
@@ -0,0 +1,41 @@
1
+ const ticketEmojiID = "1374908572982448208";
2
+
3
+ exports.messages = {
4
+ ticketEmojiID,
5
+ ticket: {
6
+ open: (channelId, messageURL) => ({
7
+ flags: 1 << 15,
8
+ components: [
9
+ {
10
+ type: 17,
11
+ components: [
12
+ {
13
+ type: 9,
14
+ accessory: {
15
+ type: 2,
16
+ style: 5,
17
+ label: "Jump to",
18
+ emoji: {
19
+ id: "1077031650459926619",
20
+ },
21
+ url: messageURL,
22
+ },
23
+ components: [
24
+ {
25
+ type: 10,
26
+ content: `## <:tickets:${ticketEmojiID}> Ticket Created`,
27
+ },
28
+ {
29
+ type: 10,
30
+ content: `-# <#${channelId}>`,
31
+ },
32
+ ],
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ }),
38
+
39
+ close: () => ({}),
40
+ },
41
+ };
package/lib/util.js CHANGED
@@ -7,6 +7,15 @@ const {
7
7
  defLang = require("../languages/en-US"),
8
8
  pack = require("../package.json");
9
9
  const { discordView } = require("./html");
10
+ const { make } = require("@elara-services/utils");
11
+
12
+ exports.emojis = {
13
+ tickets: "1374908572982448208",
14
+ info: "847397714677334066",
15
+ success: "476629550797684736",
16
+ xmark: "781955502035697745",
17
+ warning: "807031399563264030",
18
+ };
10
19
 
11
20
  exports.getString = (name, lang = "en-US") => {
12
21
  if (!lang) {
@@ -116,7 +125,7 @@ exports.displayMessages = (channel, messages = [], ticketID, type, str) => {
116
125
  }
117
126
  return [
118
127
  `<discord-messages>`,
119
- `<discord-message author="${type} ${str("TICKET")}: ${ticketID}" bot="true" verified avatar="https://cdn.discordapp.com/emojis/847397714677334066.png?v=1" role-color="#1da1f2">${str("TOTAL_MESSAGES")}: ${users
128
+ `<discord-message author="${type} ${str("TICKET")}: ${ticketID}" bot="true" verified avatar="${make.emojiURL(exports.emojis.info)}" role-color="#1da1f2">${str("TOTAL_MESSAGES")}: ${users
120
129
  .map((c) => c.count)
121
130
  .reduce((a, b) => a + b, 0)
122
131
  .toLocaleString()}<br>${users.map((c) => `<discord-mention type="role" color="${channel.guild?.members?.resolve?.(c.user.id)?.displayColor ? channel.guild?.members?.resolve?.(c.user.id)?.displayHexColor : `#ffffff`}">${c.user.tag}</discord-mention> (${c.user.id})`).join("<br>")}</discord-message></discord-messages><discord-messages>`,
@@ -331,13 +340,13 @@ exports.embed = (content, { color, title, guild, footer, author, str, descriptio
331
340
  footer,
332
341
  author: author || {
333
342
  name: guild?.name ?? str("TICKETS"),
334
- icon_url: guild?.iconURL?.({ dynamic: true }) ?? "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1",
343
+ icon_url: guild?.iconURL?.({ dynamic: true }) ?? make.emojiURL(exports.emojis.tickets),
335
344
  },
336
345
  });
337
346
 
338
347
  exports.webhook = (options) => {
339
348
  const { id, token, username, avatar, threadId } = options;
340
- return new Webhook(`https://discord.com/api/webhooks/${id}/${token}`, {
349
+ return new Webhook(`https://discord.com/api/v10/webhooks/${id}/${token}`, {
341
350
  username,
342
351
  avatar_url: avatar,
343
352
  threadId,
@@ -365,7 +374,7 @@ exports.getWebhookInfo = async (options, username = "Tickets") => {
365
374
  token: options.webhook?.token,
366
375
  threadId: options.webhook?.threadId,
367
376
  username: options.webhook?.username || username,
368
- avatar: options.webhook?.avatar || "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1",
377
+ avatar: options.webhook?.avatar || make.emojiURL(exports.emojis.tickets),
369
378
  };
370
379
  };
371
380
 
package/lib/v13.js CHANGED
@@ -4,8 +4,8 @@ const {
4
4
  MessageComponentInteraction,
5
5
  } = require("discord.js"),
6
6
  base = require("./base"),
7
- { de, code, fetchMessages, hasTicket, embed, webhook, getAppealServer, perms, defs } = require("./util"),
8
- { generate, parser, discord, is } = require("@elara-services/utils"),
7
+ { de, code, fetchMessages, hasTicket, embed, webhook, getAppealServer, perms, defs, emojis } = require("./util"),
8
+ { generate, parser, discord, is, make } = require("@elara-services/utils"),
9
9
  {
10
10
  Interactions: { button },
11
11
  } = require("@elara-services/packages");
@@ -105,7 +105,7 @@ module.exports = class Tickets extends base {
105
105
  {
106
106
  author: {
107
107
  name: this.str("ONLY_SUPPORT"),
108
- iconURL: "https://cdn.discordapp.com/emojis/781955502035697745.gif",
108
+ iconURL: make.emojiURL(emojis.xmark),
109
109
  },
110
110
  color: 0xff0000,
111
111
  },
@@ -159,7 +159,7 @@ module.exports = class Tickets extends base {
159
159
  button({
160
160
  title: this.str("TICKET_CLOSE_CONFIRM_BUTTON"),
161
161
  style: 3,
162
- emoji: { id: "807031399563264030" },
162
+ emoji: { id: emojis.warning },
163
163
  id: `${this.prefix}:close:confirm:${code(channel.topic?.split?.("ID: ")?.[1], "d", this.options.encryptToken)}${this.options?.ticket?.closeReason ? `:modal_submit` : ""}`,
164
164
  }),
165
165
  ],
@@ -339,7 +339,7 @@ module.exports = class Tickets extends base {
339
339
  style: 3,
340
340
  id: "_ _",
341
341
  disabled: true,
342
- emoji: { id: `476629550797684736` },
342
+ emoji: { id: emojis.success },
343
343
  }),
344
344
  ],
345
345
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/tickets",
3
- "version": "4.3.6",
3
+ "version": "4.4.0",
4
4
  "description": "Helper for tickets",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,9 +27,11 @@
27
27
  "pc": "prettier --check **/**/*.js"
28
28
  },
29
29
  "dependencies": {
30
- "@elara-services/packages": "^6.0.9",
31
- "@elara-services/utils": "^1.4.0",
32
- "@elara-services/webhooks": "^2.1.18"
30
+ "@discordjs/rest": "^2.5.0",
31
+ "@elara-services/packages": "^7.0.6",
32
+ "@elara-services/utils": "^3.0.7",
33
+ "@elara-services/webhooks": "^4.1.0",
34
+ "discord-api-types": "^0.38.8"
33
35
  },
34
36
  "devDependencies": {
35
37
  "eslint": "8.20.0",