@elara-services/tickets 2.0.2 → 2.1.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 +1 -0
- package/index.d.ts +2 -1
- package/index.js +29 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ const { Client } = require("discord.js"),
|
|
|
51
51
|
avatar: "", // 'webhookAvatar' support will be removed in the next major version
|
|
52
52
|
},
|
|
53
53
|
support: {
|
|
54
|
+
canOnlyCloseTickets: true, // If 'true' only roles and users listed below can close tickets. (OR people with 'Manage Server' permission)
|
|
54
55
|
roles: [ // 'supportRoleIds' support will be removed in the next major version
|
|
55
56
|
"123456789"
|
|
56
57
|
],
|
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare module "@elara-services/tickets" {
|
|
|
12
12
|
ticketOpen?: Pick<MessageOptions, "content" | "embeds">
|
|
13
13
|
appeals?: {
|
|
14
14
|
enabled: boolean;
|
|
15
|
-
|
|
15
|
+
mainserver: {
|
|
16
16
|
id: string;
|
|
17
17
|
checkIfBanned: boolean;
|
|
18
18
|
};
|
|
@@ -42,6 +42,7 @@ declare module "@elara-services/tickets" {
|
|
|
42
42
|
support?: {
|
|
43
43
|
roles?: string[];
|
|
44
44
|
users?: string[];
|
|
45
|
+
canOnlyCloseTickets?: boolean;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
/** @deprecated Use 'webhook.id' */
|
package/index.js
CHANGED
|
@@ -10,7 +10,9 @@ const { Collection, WebhookClient, MessageEmbed } = require("discord.js"),
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
module.exports = class Tickets {
|
|
13
|
-
constructor(options) {
|
|
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,12 +59,25 @@ 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
|
};
|
|
64
66
|
|
|
65
|
-
case `${this.prefix}:close`:
|
|
67
|
+
case `${this.prefix}:close`: {
|
|
68
|
+
if (this.options.support?.canOnlyCloseTickets && !member.permissions.has("MANAGE_GUILD")) {
|
|
69
|
+
let [ support, staffOnly ] = [
|
|
70
|
+
this.getSupportIds(),
|
|
71
|
+
() => send({
|
|
72
|
+
ephemeral: true,
|
|
73
|
+
embeds: [ { author: { name: `Only support staff can close tickets`, iconURL: "https://cdn.discordapp.com/emojis/781955502035697745.gif" }, color: 0xFF0000 } ]
|
|
74
|
+
})
|
|
75
|
+
];
|
|
76
|
+
if (!support.users?.includes?.(member.id)) return staffOnly();
|
|
77
|
+
if (support.roles?.length && !support.roles.some(c => member.roles.cache.has(c))) return staffOnly()
|
|
78
|
+
}
|
|
79
|
+
return send({ ephemeral: true, content: `🤔 Are you sure you want to close this ticket?`, components: [{ type: 1, components: [{ type: 2, custom_id: `${this.prefix}:close:confirm:${this.code(channel.topic?.split?.("ID: ")?.[1])}`, label: "Yes close the ticket", style: 4, emoji: { id: "807031399563264030" } }] }] })
|
|
80
|
+
}
|
|
66
81
|
|
|
67
82
|
case `${this.prefix}:modal_submit`: {
|
|
68
83
|
let [embed, fields, split] = [new MessageEmbed().setColor("ORANGE"), [], false];
|
|
@@ -100,7 +115,7 @@ module.exports = class Tickets {
|
|
|
100
115
|
if (!user) return send({ content: `❌ I was unable to fetch the user that opened the ticket.`, ephemeral: true })
|
|
101
116
|
let messages = await this.fetchMessages(channel, 5000);
|
|
102
117
|
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);
|
|
118
|
+
let closed = await channel.delete(`${member.user.tag} (${member.id}) closed the ticket.`).catch(e => this._debug(e));
|
|
104
119
|
if (!closed) return send({ ephemeral: true, content: `${emojis.x} I was unable to delete the channel & close the ticket.` })
|
|
105
120
|
return this.closeTicket({ channel, guild, user, member, messages });
|
|
106
121
|
}
|
|
@@ -164,7 +179,7 @@ module.exports = class Tickets {
|
|
|
164
179
|
{ type: "role", id: guild.id, deny: ["VIEW_CHANNEL"] },
|
|
165
180
|
...permissions
|
|
166
181
|
]
|
|
167
|
-
}).catch(this._debug);
|
|
182
|
+
}).catch(e => this._debug(e));
|
|
168
183
|
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
184
|
let msg = await channel.send({
|
|
170
185
|
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 +191,9 @@ module.exports = class Tickets {
|
|
|
176
191
|
footer: { text: `To close this ticket press the button below.` }
|
|
177
192
|
}],
|
|
178
193
|
components: [{ type: 1, components: [{ type: 2, custom_id: `${this.prefix}:close`, label: "Close Ticket", style: 4, emoji: { name: "🔒" } }] }]
|
|
179
|
-
}).catch(this._debug);
|
|
194
|
+
}).catch(e => this._debug(e));
|
|
180
195
|
if (!msg) return null;
|
|
181
|
-
if (embeds?.length <= 10) for await (const embed of embeds) await channel.send({ embeds: [ embed ] }).catch(this._debug);
|
|
196
|
+
if (embeds?.length <= 10) for await (const embed of embeds) await channel.send({ embeds: [ embed ] }).catch(e => this._debug(e));
|
|
182
197
|
if (this.webhookOptions.id && this.webhookOptions.token) this.webhook()
|
|
183
198
|
.embed({
|
|
184
199
|
author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
|
|
@@ -187,7 +202,7 @@ module.exports = class Tickets {
|
|
|
187
202
|
color: 0xFF000,
|
|
188
203
|
timestamp: new Date(),
|
|
189
204
|
footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` },
|
|
190
|
-
}).send().catch(this._debug);
|
|
205
|
+
}).send().catch(e => this._debug(e));
|
|
191
206
|
return send({
|
|
192
207
|
embeds: [
|
|
193
208
|
{
|
|
@@ -365,7 +380,7 @@ module.exports = class Tickets {
|
|
|
365
380
|
.embeds(embeds)
|
|
366
381
|
.button({ type: 1, components })
|
|
367
382
|
.edit(m.id)
|
|
368
|
-
.catch(this._debug);
|
|
383
|
+
.catch(e => this._debug(e));
|
|
369
384
|
if (user) user.send({
|
|
370
385
|
embeds: [{
|
|
371
386
|
author: { name: guild.name, icon_url: guild.iconURL({ dynamic: true }) },
|
|
@@ -375,8 +390,8 @@ module.exports = class Tickets {
|
|
|
375
390
|
footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` }
|
|
376
391
|
}],
|
|
377
392
|
components: [{ type: 1, components }]
|
|
378
|
-
}).catch(this._debug);
|
|
379
|
-
}).catch(this._debug);
|
|
393
|
+
}).catch(e => this._debug(e));
|
|
394
|
+
}).catch(e => this._debug(e));
|
|
380
395
|
};
|
|
381
396
|
/**
|
|
382
397
|
* @typedef {Object} getSupportResponse
|