@elara-services/tickets 1.0.0 → 1.5.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/README.md CHANGED
@@ -25,6 +25,16 @@ const { Client } = require("discord.js"),
25
25
  ticketOpen: {
26
26
  content: "", // The content of the ticket message once it gets created, use "%user%" or "%server%" for the user mention or server name
27
27
  embeds: [], // View https://discord.com/developers/docs/resources/channel#embed-object
28
+ },
29
+ appeals: { // OPTIONAL
30
+ enabled: true, // If the appeals server checks should be enabled.
31
+ mainserver: {
32
+ id: "", // The main server's id
33
+ checkIfBanned: true // Check if the user is banned in the main server, if not they can't open a ticket.
34
+ },
35
+ embeds: {
36
+ not_banned: {} // The embeds, content and components for the not banned message.
37
+ }
28
38
  }
29
39
  })
30
40
 
package/index.d.ts CHANGED
@@ -3,7 +3,7 @@ declare module "@elara-services/tickets" {
3
3
  import { Client, MessageOptions, GuildMember, Guild, User, TextBasedChannel, Message, Interaction } from "discord.js";
4
4
  import Webhook from "discord-hook";
5
5
 
6
- interface TicketOptions {
6
+ export interface TicketOptions {
7
7
  client: Client;
8
8
  prefix: string;
9
9
  encryptToken: string;
@@ -14,6 +14,16 @@ declare module "@elara-services/tickets" {
14
14
  supportRoleIds?: string[];
15
15
  supportUserIds?: string[];
16
16
  ticketOpen?: Pick<MessageOptions, "content" | "embeds">
17
+ appeals?: {
18
+ enabled: boolean;
19
+ mainServer: {
20
+ id: string;
21
+ checkIfBanned: boolean;
22
+ };
23
+ embeds?: {
24
+ not_banned: Pick<MessageOptions, "content" | "embeds" | "components">
25
+ }
26
+ }
17
27
  }
18
28
 
19
29
  class Tickets {
package/index.js CHANGED
@@ -8,7 +8,7 @@ module.exports = class Tickets {
8
8
  this.options = options;
9
9
  };
10
10
  get prefix() { return `system:ticket:${this.options.prefix}`; };
11
- webhook() {
11
+ webhook() {
12
12
  return new Webhook(`https://discord.com/api/webhooks/${this.options.webhookId}/${this.options.webhookToken}`, {
13
13
  username: this.options.webhookUsername || "Tickets",
14
14
  avatar_url: this.options.webhookAvatar || "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1",
@@ -124,12 +124,34 @@ module.exports = class Tickets {
124
124
  */
125
125
  const send = async (options = {}, defer = false) => {
126
126
  if (defer) return int.deferReply(options).catch(() => null);
127
- if (int.replied || int.deferred) return int.editReply(options).catch(() => {});
127
+ if (int.replied || int.deferred) return int.editReply(options).catch(() => null);
128
128
  return int.reply(options).catch(() => null);
129
129
  };
130
130
  switch (customId) {
131
131
  case this.prefix: {
132
132
  await send({ ephemeral: true }, true);
133
+ if (this.options.appeals?.enabled) {
134
+ let appeals = this.options.appeals;
135
+ if (appeals.mainserver?.id && appeals.mainserver.checkIfBanned) {
136
+ let server = this.options.client.guilds.resolve(appeals.mainserver.id);
137
+ if (server?.available) {
138
+ let isBanned = await server.bans.fetch({ user: member.id, force: true }).catch(() => null);
139
+ if (!isBanned) return send(
140
+ typeof appeals.embeds?.not_banned === "object" ?
141
+ appeals.embeds.not_banned :
142
+ { embeds: [
143
+ {
144
+ author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
145
+ title: "INFO",
146
+ description: `❌ You can't open this ticket due to you not being banned in the main server!`,
147
+ color: 0xFF0000,
148
+ timestamp: new Date()
149
+ }
150
+ ]}
151
+ )
152
+ }
153
+ }
154
+ }
133
155
  let [ permissions, allow ] = [
134
156
  [],
135
157
  [ "ADD_REACTIONS", "ATTACH_FILES", "CREATE_INSTANT_INVITE", "EMBED_LINKS", "READ_MESSAGE_HISTORY", "VIEW_CHANNEL", "USE_EXTERNAL_EMOJIS", "SEND_MESSAGES" ]
@@ -161,7 +183,7 @@ module.exports = class Tickets {
161
183
  components: [{ type: 1, components: [{ type: 2, custom_id: `${this.prefix}:close`, label: "Close Ticket", style: 4, emoji: { name: "🔒" } }] }]
162
184
  }).catch(() => null);
163
185
  if (!msg) return null
164
- this.webhook()
186
+ if (this.options.webhookId && this.options.webhookToken) this.webhook()
165
187
  .embed({
166
188
  author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
167
189
  title: "Ticket: Opened",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/tickets",
3
- "version": "1.0.0",
3
+ "version": "1.5.0",
4
4
  "description": "Helper for tickets",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "aes256": "1.1.0",
15
- "discord-hook": "github:elara-bots/discord-hook#v2",
15
+ "discord-hook": "2.0.0",
16
16
  "shortid": "2.2.16"
17
17
  }
18
18
  }