@elara-services/tickets 2.1.0 → 2.1.1
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.js +23 -59
- package/package.json +5 -2
- package/post.js +12 -0
package/index.js
CHANGED
|
@@ -16,7 +16,6 @@ module.exports = class Tickets {
|
|
|
16
16
|
this.options = options;
|
|
17
17
|
};
|
|
18
18
|
get prefix() { return `system:ticket:${this.options.prefix}`; };
|
|
19
|
-
|
|
20
19
|
/** @private */
|
|
21
20
|
get webhookOptions() {
|
|
22
21
|
return {
|
|
@@ -38,7 +37,6 @@ module.exports = class Tickets {
|
|
|
38
37
|
if (int?.isButton?.() || int?.isModalSubmit()) {
|
|
39
38
|
let { guild, channel, member, customId } = int,
|
|
40
39
|
category = guild?.channels?.resolve?.(this.options.ticketCategory || channel?.parentId);
|
|
41
|
-
|
|
42
40
|
if (!guild || !guild.available || !channel || !member || !category) return;
|
|
43
41
|
|
|
44
42
|
/**
|
|
@@ -56,9 +54,7 @@ module.exports = class Tickets {
|
|
|
56
54
|
if (this.options.modal?.enabled) {
|
|
57
55
|
return int.showModal(this.modal({
|
|
58
56
|
title: this.options.modal.title,
|
|
59
|
-
components: this.options.modal.questions?.length >= 1 ?
|
|
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)}` }] })) :
|
|
61
|
-
[]
|
|
57
|
+
components: this.options.modal.questions?.length >= 1 ? 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)}` }] })) : []
|
|
62
58
|
})).catch(e => this._debug(e));
|
|
63
59
|
}
|
|
64
60
|
return this.handleCreate({ guild, member, category, send })
|
|
@@ -68,10 +64,7 @@ module.exports = class Tickets {
|
|
|
68
64
|
if (this.options.support?.canOnlyCloseTickets && !member.permissions.has("MANAGE_GUILD")) {
|
|
69
65
|
let [ support, staffOnly ] = [
|
|
70
66
|
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
|
-
})
|
|
67
|
+
() => send({ ephemeral: true, embeds: [ { author: { name: `Only support staff can close tickets`, iconURL: "https://cdn.discordapp.com/emojis/781955502035697745.gif" }, color: 0xFF0000 } ] })
|
|
75
68
|
];
|
|
76
69
|
if (!support.users?.includes?.(member.id)) return staffOnly();
|
|
77
70
|
if (support.roles?.length && !support.roles.some(c => member.roles.cache.has(c))) return staffOnly()
|
|
@@ -80,7 +73,9 @@ module.exports = class Tickets {
|
|
|
80
73
|
}
|
|
81
74
|
|
|
82
75
|
case `${this.prefix}:modal_submit`: {
|
|
83
|
-
let [embed, fields, split] = [
|
|
76
|
+
let [embed, fields, split] = [
|
|
77
|
+
new MessageEmbed().setColor("ORANGE").setTimestamp().setTitle(`For Responses`).setFooter({ text: `ID: ${member.id}` }).setAuthor({ name: member.user.username, iconURL: member.user.displayAvatarURL({ dynamic: true }) }),
|
|
78
|
+
[], false];
|
|
84
79
|
for (const c of int.fields.components) {
|
|
85
80
|
for (const cc of c.components) {
|
|
86
81
|
if (cc.value && cc.customId) {
|
|
@@ -92,31 +87,22 @@ module.exports = class Tickets {
|
|
|
92
87
|
}
|
|
93
88
|
if (embed.length >= 6000 || split) {
|
|
94
89
|
return this.handleCreate({ guild, member, category, send, embeds: fields.map((v, i) => ({
|
|
95
|
-
title: `Form Response: ${v.name}`,
|
|
96
|
-
color: embed.color,
|
|
97
|
-
description: v.value,
|
|
90
|
+
title: `Form Response: ${v.name}`, color: embed.color, description: v.value,
|
|
98
91
|
author: i === 0 ? { name: member.user.username, iconURL: member.user.displayAvatarURL({ dynamic: true }) } : undefined,
|
|
99
92
|
timestamp: fields.length - 1 === i ? new Date() : undefined,
|
|
100
93
|
footer: fields.length - 1 === i ? { text: `ID: ${member.id}` } : undefined
|
|
101
94
|
})) })
|
|
102
95
|
};
|
|
103
|
-
|
|
104
|
-
return this.handleCreate({ guild, member, category, send, embeds: [
|
|
105
|
-
embed
|
|
106
|
-
.setTitle(`Form Responses`)
|
|
107
|
-
.setTimestamp()
|
|
108
|
-
.setAuthor({ name: member.user.username, iconURL: member.user.displayAvatarURL({ dynamic: true }) })
|
|
109
|
-
.setFooter({ text: `ID: ${member.id}` })
|
|
110
|
-
]})
|
|
96
|
+
return this.handleCreate({ guild, member, category, send, embeds: [ embed ]})
|
|
111
97
|
}
|
|
112
98
|
};
|
|
113
99
|
if (customId.startsWith(`${this.prefix}:close:confirm`)) {
|
|
114
100
|
let user = this.options.client.users.resolve(customId.split("close:confirm:")[1]) ?? await this.options.client.users.fetch(customId.split("close:confirm:")[1]).catch(() => null);
|
|
115
101
|
if (!user) return send({ content: `❌ I was unable to fetch the user that opened the ticket.`, ephemeral: true })
|
|
116
102
|
let messages = await this.fetchMessages(channel, 5000);
|
|
117
|
-
if (!messages
|
|
103
|
+
if (!messages?.length) return send({ ephemeral: true, content: `❌ I was unable to close the ticket, I couldn't fetch the messages in this channel.` })
|
|
118
104
|
let closed = await channel.delete(`${member.user.tag} (${member.id}) closed the ticket.`).catch(e => this._debug(e));
|
|
119
|
-
if (!closed) return send({ ephemeral: true, content:
|
|
105
|
+
if (!closed) return send({ ephemeral: true, content: `❌ I was unable to delete the channel & close the ticket.` })
|
|
120
106
|
return this.closeTicket({ channel, guild, user, member, messages });
|
|
121
107
|
}
|
|
122
108
|
};
|
|
@@ -124,10 +110,15 @@ module.exports = class Tickets {
|
|
|
124
110
|
|
|
125
111
|
/** @private */
|
|
126
112
|
async handleCreate({ guild, member, category, send, embeds = [] } = {}) {
|
|
127
|
-
|
|
113
|
+
await send({ ephemeral: true }, true);
|
|
114
|
+
let [ supportIds, permissions, allow, { appeals } ] = [
|
|
115
|
+
this.getSupportIds(), [],
|
|
116
|
+
["ADD_REACTIONS", "ATTACH_FILES", "CREATE_INSTANT_INVITE", "EMBED_LINKS", "READ_MESSAGE_HISTORY", "VIEW_CHANNEL", "USE_EXTERNAL_EMOJIS", "SEND_MESSAGES"],
|
|
117
|
+
this.options ?? {}
|
|
118
|
+
];
|
|
128
119
|
if (supportIds.roles.length) for (const sup of supportIds.roles) {
|
|
129
120
|
let role = guild.roles.resolve(sup);
|
|
130
|
-
if (role)
|
|
121
|
+
if (role) permissions.push({ type: "role", id: sup, allow });
|
|
131
122
|
};
|
|
132
123
|
|
|
133
124
|
if (supportIds.users.length) for (const uId of supportIds.users) {
|
|
@@ -135,11 +126,9 @@ module.exports = class Tickets {
|
|
|
135
126
|
if (e?.stack?.includes?.("Unknown Member")) this.options.support.users = this.options.support.users.filter(c => c !== uId);
|
|
136
127
|
return this._debug(e);
|
|
137
128
|
});
|
|
138
|
-
if (member)
|
|
129
|
+
if (member) permissions.push({ type: "member", id: uId, allow });
|
|
139
130
|
}
|
|
140
|
-
|
|
141
|
-
if (this.options.appeals?.enabled) {
|
|
142
|
-
let appeals = this.options.appeals;
|
|
131
|
+
if (appeals?.enabled) {
|
|
143
132
|
if (appeals.mainserver?.id && appeals.mainserver.checkIfBanned) {
|
|
144
133
|
let server = this.options.client.guilds.resolve(appeals.mainserver.id);
|
|
145
134
|
if (server?.available) {
|
|
@@ -162,12 +151,6 @@ module.exports = class Tickets {
|
|
|
162
151
|
}
|
|
163
152
|
}
|
|
164
153
|
}
|
|
165
|
-
let [permissions, allow] = [
|
|
166
|
-
[],
|
|
167
|
-
["ADD_REACTIONS", "ATTACH_FILES", "CREATE_INSTANT_INVITE", "EMBED_LINKS", "READ_MESSAGE_HISTORY", "VIEW_CHANNEL", "USE_EXTERNAL_EMOJIS", "SEND_MESSAGES"]
|
|
168
|
-
];
|
|
169
|
-
if (support.length) for (const sup of support) permissions.push({ type: "role", id: sup, allow });
|
|
170
|
-
if (supportUsers.length) for (const user of supportUsers) permissions.push({ type: "member", id: user, allow });
|
|
171
154
|
|
|
172
155
|
/** @type {import("discord.js").TextChannel} */
|
|
173
156
|
let channel = await guild.channels.create(`${this.options.prefix}-${generate().slice(0, 5).replace(/-|_/g, "")}`, {
|
|
@@ -180,7 +163,7 @@ module.exports = class Tickets {
|
|
|
180
163
|
...permissions
|
|
181
164
|
]
|
|
182
165
|
}).catch(e => this._debug(e));
|
|
183
|
-
if (!channel) return send({ content:
|
|
166
|
+
if (!channel) return send({ content: `❌ I was unable to create the ticket channel, if this keeps happening contact one of the staff members via their DMs!` });
|
|
184
167
|
let msg = await channel.send({
|
|
185
168
|
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.`,
|
|
186
169
|
embeds: this.options.ticketOpen?.embeds || [{
|
|
@@ -204,24 +187,13 @@ module.exports = class Tickets {
|
|
|
204
187
|
footer: { text: `Ticket ID: ${channel.name.split("-")[1]}` },
|
|
205
188
|
}).send().catch(e => this._debug(e));
|
|
206
189
|
return send({
|
|
207
|
-
embeds: [
|
|
208
|
-
{
|
|
209
|
-
author: { name: `Ticket Created!`, icon_url: `https://cdn.discordapp.com/emojis/476629550797684736.gif` },
|
|
210
|
-
description: channel.toString(),
|
|
211
|
-
color: 0xFF000
|
|
212
|
-
}
|
|
213
|
-
],
|
|
190
|
+
embeds: [ { author: { name: `Ticket Created!`, icon_url: `https://cdn.discordapp.com/emojis/476629550797684736.gif` }, description: channel.toString(), color: 0xFF000 } ],
|
|
214
191
|
components: [ { type: 1, components: [ button({ title: "Go to ticket", url: msg.url }) ] } ]
|
|
215
192
|
})
|
|
216
193
|
}
|
|
217
194
|
|
|
218
195
|
button(options = { style: 3, label: "Create Ticket", emoji: { name: "📩" } }) {
|
|
219
|
-
return button({
|
|
220
|
-
id: options?.id || this.prefix,
|
|
221
|
-
style: options.style || 3,
|
|
222
|
-
title: options.label,
|
|
223
|
-
emoji: options.emoji
|
|
224
|
-
});
|
|
196
|
+
return button({ id: options?.id || this.prefix, style: options.style || 3, title: options.label, emoji: options.emoji });
|
|
225
197
|
};
|
|
226
198
|
|
|
227
199
|
/**
|
|
@@ -233,13 +205,7 @@ module.exports = class Tickets {
|
|
|
233
205
|
return modal({
|
|
234
206
|
id: `${this.prefix}:modal_submit`,
|
|
235
207
|
title: options?.title || "Create Ticket",
|
|
236
|
-
components: options?.components?.length >= 1 ? options.components : [
|
|
237
|
-
{
|
|
238
|
-
type: 1, components: [
|
|
239
|
-
{ type: 4, min_length: 10, max_length: 4000, custom_id: "message", label: "Content", style: 2, placeholder: "What's the ticket about?", required: true }
|
|
240
|
-
]
|
|
241
|
-
}
|
|
242
|
-
]
|
|
208
|
+
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 } ] } ]
|
|
243
209
|
})
|
|
244
210
|
}
|
|
245
211
|
|
|
@@ -411,9 +377,7 @@ module.exports = class Tickets {
|
|
|
411
377
|
|
|
412
378
|
/** @private */
|
|
413
379
|
_debug(...args) {
|
|
414
|
-
if (
|
|
415
|
-
console.log(...args);
|
|
380
|
+
if (this.options?.debug) console.log(...args);
|
|
416
381
|
return null;
|
|
417
382
|
}
|
|
418
|
-
|
|
419
383
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elara-services/tickets",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Helper for tickets",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"typings": "index.d.ts",
|
|
8
8
|
"author": "SUPERCHIEFYT (Elara-Discord-Bots, Elara-Services)",
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node post.js"
|
|
12
|
+
},
|
|
10
13
|
"optionalDependencies": {
|
|
11
|
-
"discord.js": "13.8.
|
|
14
|
+
"discord.js": "13.8.1"
|
|
12
15
|
},
|
|
13
16
|
"dependencies": {
|
|
14
17
|
"@elara-services/packages": "5.0.0",
|
package/post.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const package = require("./package.json");
|
|
2
|
+
console.log([
|
|
3
|
+
`Package: ${package.name}`,
|
|
4
|
+
`────────────────────────`,
|
|
5
|
+
`Thanks for installing the package!`,
|
|
6
|
+
`Version you installed: ${package.version}`,
|
|
7
|
+
`─────────────────────────────────────────`,
|
|
8
|
+
`To get started look at the 'Getting Started' section on the npm page here: https://www.npmjs.com/package/@elara-services/tickets`,
|
|
9
|
+
`Here is some helpful links:`,
|
|
10
|
+
`Source Code: https://github.com/elara-bots/tickets`,
|
|
11
|
+
`Support: https://discord.gg/qafHJ63`
|
|
12
|
+
].join("\n"))
|