@elara-services/tickets 3.1.0 → 3.1.3
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/.eslintrc.json +20 -20
- package/README.md +86 -82
- package/index.d.ts +88 -82
- package/index.js +11 -11
- package/lib/base.js +79 -79
- package/lib/util.js +142 -142
- package/lib/v13.js +217 -217
- package/lib/v14.js +262 -262
- package/package.json +18 -2
- package/renovate.json +5 -5
package/lib/util.js
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
const { AES } = require("@elara-services/packages"),
|
|
2
|
-
{ Collection, version } = require("discord.js"),
|
|
3
|
-
Webhook = require("discord-hook");
|
|
4
|
-
|
|
5
|
-
exports.code = (message, type = "d", token) => {
|
|
6
|
-
if (!message || !type) return "";
|
|
7
|
-
if (!token) return message;
|
|
8
|
-
try {
|
|
9
|
-
const aes = new AES(token);
|
|
10
|
-
switch (type) {
|
|
11
|
-
case "e": return aes.encrypt(message);
|
|
12
|
-
case "d": return aes.decrypt(message);
|
|
13
|
-
}
|
|
14
|
-
} catch {
|
|
15
|
-
return message;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
exports.de = {
|
|
20
|
-
user: "<:Members:860931214232125450>",
|
|
21
|
-
channel: "<:Channel:841654412509839390>",
|
|
22
|
-
transcript: "<:Log:792290922749624320>"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.fetchMessages = async (channel, limit = 50, before, after, around) => {
|
|
26
|
-
if (limit && limit > 100) {
|
|
27
|
-
let logs = [];
|
|
28
|
-
const get = async (_before, _after) => {
|
|
29
|
-
const messages = [...(await channel.messages.fetch({ limit: 100, before: _before || undefined, after: _after || undefined }).catch(() => new Collection())).values()];
|
|
30
|
-
if (limit <= messages.length) {
|
|
31
|
-
return (_after ? messages.slice(messages.length - limit, messages.length).map((message) => message).concat(logs) : logs.concat(messages.slice(0, limit).map((message) => message)));
|
|
32
|
-
}
|
|
33
|
-
limit -= messages.length;
|
|
34
|
-
logs = (_after ? messages.map((message) => message).concat(logs) : logs.concat(messages.map((message) => message)));
|
|
35
|
-
if (messages.length < 100) return logs;
|
|
36
|
-
return get((_before || !_after) && messages[messages.length - 1].id, _after && messages[0].id);
|
|
37
|
-
};
|
|
38
|
-
return get(before, after);
|
|
39
|
-
}
|
|
40
|
-
return [...(await channel.messages.fetch({ limit, before, after, around }).catch(() => new Collection())).values()];
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
exports.displayMessages = (channel, messages = [], ticketID, type) => {
|
|
44
|
-
let users = [];
|
|
45
|
-
for (const i of messages.values()) {
|
|
46
|
-
let f = users.find(c => c.user.id === i.author.id);
|
|
47
|
-
if (f) f.count++; else users.push({ user: i.author, count: 1 });
|
|
48
|
-
};
|
|
49
|
-
return [`<discord-messages>`, `<discord-message author="${type} Ticket: ${ticketID}" bot="true" verified avatar="https://cdn.discordapp.com/emojis/847397714677334066.png?v=1" role-color="#1da1f2">Total Messages: ${users.map(c => c.count).reduce((a, b) => a + b, 0).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>`,
|
|
50
|
-
...messages.map(message => {
|
|
51
|
-
let str = [
|
|
52
|
-
`<discord-message${message.author.bot ? ` bot="true" ${message.author.flags?.has?.(version?.includes?.("14") ? 1 << 16 : "VERIFIED_BOT") ? `verified="true"` : ""}` : ""} new_timestamp="${message.createdAt.toISOString()}" author="${message.author.username}" avatar=${message.author.displayAvatarURL({ dynamic: true, format: "png" })} role-color="${channel.guild?.members?.resolve?.(message.author.id)?.displayColor ? channel.guild?.members?.resolve?.(message.author.id)?.displayHexColor : `#ffffff`}">`
|
|
53
|
-
];
|
|
54
|
-
if (message.content) {
|
|
55
|
-
let content = message.content;
|
|
56
|
-
if (message.mentions.users.size) for (const user of message.mentions.users.values()) content = content.replace(new RegExp(`<@!?${user.id}>`, "g"), `<discord-mention type="role" color="${message.guild?.members?.resolve?.(user?.id)?.displayHexColor ?? "#ffffff"}">${user.tag}</discord-mention>`);
|
|
57
|
-
if (message.mentions.channels.size) for (const channel of message.mentions.channels.values()) content = content.replace(new RegExp(channel.toString(), "g"), `<discord-mention type="channel">${channel.name}</discord-mention>`);
|
|
58
|
-
if (message.mentions.roles.size) for (const role of message.mentions.roles.values()) content = content.replace(new RegExp(role.toString(), "g"), `<discord-mention type="role" color="${role.hexColor}">${role.name}</discord-mention>`)
|
|
59
|
-
str.push(content)
|
|
60
|
-
};
|
|
61
|
-
if (message.embeds?.length) {
|
|
62
|
-
let arr = [`<discord-embeds slot="embeds">`];
|
|
63
|
-
for (const embed of message.embeds) {
|
|
64
|
-
let emb = [
|
|
65
|
-
`<discord-embed slot="embed" ${embed.thumbnail?.url ? `thumbnail="${embed.thumbnail.url}"` : ""} ${embed.image?.url ? `image="${embed.image.url}"` : ""} ${embed.author ? `${embed.author.name ? `author-name="${embed.author.name}"` : ""} ${embed.author.iconURL ? `author-image="${embed.author.iconURL}"` : ""} ${embed.author.url ? `author-url="${embed.author.url}"` : ""}` : ""} ${embed.title ? `embed-title="${embed.title}"` : ""}${embed.color ? `color="${embed.hexColor}"` : ""}>`
|
|
66
|
-
];
|
|
67
|
-
if (embed.description) emb.push(`<discord-embed-description slot="description">${embed.description}</discord-embed-description>`);
|
|
68
|
-
if (embed.fields?.length) {
|
|
69
|
-
emb.push(`<discord-embed-fields slot="fields">`)
|
|
70
|
-
for (const field of embed.fields) emb.push(`<discord-embed-field field-title="${field.name}" ${field.inline ? `inline` : ""}>${field.value}</discord-embed-field>`)
|
|
71
|
-
}
|
|
72
|
-
arr.push(...emb, `</discord-embed>`)
|
|
73
|
-
}
|
|
74
|
-
str.push(...arr, "</discord-embeds>")
|
|
75
|
-
}
|
|
76
|
-
if (message.interaction?.user) str.push(`<discord-command slot="reply" command="${message.interaction.type === "APPLICATION_COMMAND" ? "/" : ""}${message.interaction.commandName}" profile="${message.interaction.user.id}" role-color="${channel.guild?.members?.resolve?.(message.interaction.user?.id)?.displayHexColor || "#fffff"}" author="${message.interaction.user.tag}" avatar="${message.interaction.user.displayAvatarURL({ dynamic: true })}"></discord-command>`)
|
|
77
|
-
if (message.components?.length) {
|
|
78
|
-
let row = [
|
|
79
|
-
`<discord-attachments slot="components">`
|
|
80
|
-
],
|
|
81
|
-
styles = {
|
|
82
|
-
"PRIMARY": "primary",
|
|
83
|
-
"SECONDARY": "secondary",
|
|
84
|
-
"SUCCESS": "success",
|
|
85
|
-
"DANGER": "destructive",
|
|
86
|
-
"LINK": "secondary"
|
|
87
|
-
}
|
|
88
|
-
for (const components of message.components) {
|
|
89
|
-
row.push(`<discord-action-row>`)
|
|
90
|
-
for (const c of components.components) {
|
|
91
|
-
if (c.type === "BUTTON") row.push(`<discord-button ${c.disabled ? `disabled=true` : ""} type="${styles[c.style]}" ${c.emoji?.name ? `emoji-name="${c.emoji.name}"` : ""} ${c.emoji?.id ? `emoji="https://cdn.discordapp.com/emojis/${c.emoji.id}.${c.emoji.animated ? "gif" : "png"}"` : ""} ${c.url ? `url="${c.url}"` : ""}>${c.label || ""}</discord-button>`)
|
|
92
|
-
}
|
|
93
|
-
row.push(`</discord-action-row>`)
|
|
94
|
-
}
|
|
95
|
-
if (row.length >= 2) str.push(...row, `</discord-attachments>`)
|
|
96
|
-
}
|
|
97
|
-
if (message.attachments.size) str.push(message.attachments.map((c) => `<a href="${c.proxyURL}">${c.name}</a>`).join("<br>"))
|
|
98
|
-
str.push(`${message.content?.length ? `<br><br>` : ""}<code style="background-color: #36393e; color: white;">ID: ${message.id}</code>`)
|
|
99
|
-
return [...str, `</discord-message>`].join(" ");
|
|
100
|
-
}),
|
|
101
|
-
"</discord-messages>"].join(" ");
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* @param {object} options
|
|
105
|
-
* @param {string} [options.userId]
|
|
106
|
-
* @param {string} [options.token]
|
|
107
|
-
* @param {import("discord.js").Guild} [options.guild]
|
|
108
|
-
* @returns {boolean}
|
|
109
|
-
*/
|
|
110
|
-
exports.hasTicket = ({ userId, guild, token, prefix } = {}) => {
|
|
111
|
-
if (!userId || !guild || !token || !prefix || !guild?.channels?.cache?.size) return false;
|
|
112
|
-
let channels = guild.channels.cache.filter(c => [ 0, "GUILD_TEXT" ].includes(c.type) && c.topic && exports.code(c.topic.split("ID: ")[1], "d", token) === userId && c.name?.match?.(new RegExp(prefix, "gi")));
|
|
113
|
-
if (!channels.size) return false;
|
|
114
|
-
return true;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
exports.embed = (content, { color, title, guild, footer, author } = {}) => ({
|
|
118
|
-
title: title || "INFO", description: content,
|
|
119
|
-
color: color || 0xFF0000, timestamp: new Date(),
|
|
120
|
-
footer,
|
|
121
|
-
author: author || { name: guild?.name ?? "Tickets", icon_url: guild?.iconURL?.({ dynamic: true }) ?? "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1" }
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
exports.webhook = (options) => {
|
|
125
|
-
const { id, token, username, avatar } = options;
|
|
126
|
-
return new Webhook(`https://discord.com/api/webhooks/${id}/${token}`, { username, avatar_url: avatar });
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
exports.getWebhookInfo = (options) => {
|
|
130
|
-
return {
|
|
131
|
-
id: options.webhook?.id,
|
|
132
|
-
token: options.webhook?.token,
|
|
133
|
-
username: options.webhook?.username || "Tickets",
|
|
134
|
-
avatar: options.webhook?.avatar || "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1"
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
exports.getAppealServer = ({ appeals, client } = {}) => {
|
|
139
|
-
if (!appeals?.enabled || !appeals?.mainserver?.checkIfBanned) return null;
|
|
140
|
-
let server = client.guilds.resolve(appeals.mainserver?.id);
|
|
141
|
-
if (!server?.available) return null;
|
|
142
|
-
return server;
|
|
1
|
+
const { AES } = require("@elara-services/packages"),
|
|
2
|
+
{ Collection, version } = require("discord.js"),
|
|
3
|
+
Webhook = require("discord-hook");
|
|
4
|
+
|
|
5
|
+
exports.code = (message, type = "d", token) => {
|
|
6
|
+
if (!message || !type) return "";
|
|
7
|
+
if (!token) return message;
|
|
8
|
+
try {
|
|
9
|
+
const aes = new AES(token);
|
|
10
|
+
switch (type) {
|
|
11
|
+
case "e": return aes.encrypt(message);
|
|
12
|
+
case "d": return aes.decrypt(message);
|
|
13
|
+
}
|
|
14
|
+
} catch {
|
|
15
|
+
return message;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.de = {
|
|
20
|
+
user: "<:Members:860931214232125450>",
|
|
21
|
+
channel: "<:Channel:841654412509839390>",
|
|
22
|
+
transcript: "<:Log:792290922749624320>"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.fetchMessages = async (channel, limit = 50, before, after, around) => {
|
|
26
|
+
if (limit && limit > 100) {
|
|
27
|
+
let logs = [];
|
|
28
|
+
const get = async (_before, _after) => {
|
|
29
|
+
const messages = [...(await channel.messages.fetch({ limit: 100, before: _before || undefined, after: _after || undefined }).catch(() => new Collection())).values()];
|
|
30
|
+
if (limit <= messages.length) {
|
|
31
|
+
return (_after ? messages.slice(messages.length - limit, messages.length).map((message) => message).concat(logs) : logs.concat(messages.slice(0, limit).map((message) => message)));
|
|
32
|
+
}
|
|
33
|
+
limit -= messages.length;
|
|
34
|
+
logs = (_after ? messages.map((message) => message).concat(logs) : logs.concat(messages.map((message) => message)));
|
|
35
|
+
if (messages.length < 100) return logs;
|
|
36
|
+
return get((_before || !_after) && messages[messages.length - 1].id, _after && messages[0].id);
|
|
37
|
+
};
|
|
38
|
+
return get(before, after);
|
|
39
|
+
}
|
|
40
|
+
return [...(await channel.messages.fetch({ limit, before, after, around }).catch(() => new Collection())).values()];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.displayMessages = (channel, messages = [], ticketID, type) => {
|
|
44
|
+
let users = [];
|
|
45
|
+
for (const i of messages.values()) {
|
|
46
|
+
let f = users.find(c => c.user.id === i.author.id);
|
|
47
|
+
if (f) f.count++; else users.push({ user: i.author, count: 1 });
|
|
48
|
+
};
|
|
49
|
+
return [`<discord-messages>`, `<discord-message author="${type} Ticket: ${ticketID}" bot="true" verified avatar="https://cdn.discordapp.com/emojis/847397714677334066.png?v=1" role-color="#1da1f2">Total Messages: ${users.map(c => c.count).reduce((a, b) => a + b, 0).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>`,
|
|
50
|
+
...messages.map(message => {
|
|
51
|
+
let str = [
|
|
52
|
+
`<discord-message${message.author.bot ? ` bot="true" ${message.author.flags?.has?.(version?.includes?.("14") ? 1 << 16 : "VERIFIED_BOT") ? `verified="true"` : ""}` : ""} new_timestamp="${message.createdAt.toISOString()}" author="${message.author.username}" avatar=${message.author.displayAvatarURL({ dynamic: true, format: "png" })} role-color="${channel.guild?.members?.resolve?.(message.author.id)?.displayColor ? channel.guild?.members?.resolve?.(message.author.id)?.displayHexColor : `#ffffff`}">`
|
|
53
|
+
];
|
|
54
|
+
if (message.content) {
|
|
55
|
+
let content = message.content;
|
|
56
|
+
if (message.mentions.users.size) for (const user of message.mentions.users.values()) content = content.replace(new RegExp(`<@!?${user.id}>`, "g"), `<discord-mention type="role" color="${message.guild?.members?.resolve?.(user?.id)?.displayHexColor ?? "#ffffff"}">${user.tag}</discord-mention>`);
|
|
57
|
+
if (message.mentions.channels.size) for (const channel of message.mentions.channels.values()) content = content.replace(new RegExp(channel.toString(), "g"), `<discord-mention type="channel">${channel.name}</discord-mention>`);
|
|
58
|
+
if (message.mentions.roles.size) for (const role of message.mentions.roles.values()) content = content.replace(new RegExp(role.toString(), "g"), `<discord-mention type="role" color="${role.hexColor}">${role.name}</discord-mention>`)
|
|
59
|
+
str.push(content)
|
|
60
|
+
};
|
|
61
|
+
if (message.embeds?.length) {
|
|
62
|
+
let arr = [`<discord-embeds slot="embeds">`];
|
|
63
|
+
for (const embed of message.embeds) {
|
|
64
|
+
let emb = [
|
|
65
|
+
`<discord-embed slot="embed" ${embed.thumbnail?.url ? `thumbnail="${embed.thumbnail.url}"` : ""} ${embed.image?.url ? `image="${embed.image.url}"` : ""} ${embed.author ? `${embed.author.name ? `author-name="${embed.author.name}"` : ""} ${embed.author.iconURL ? `author-image="${embed.author.iconURL}"` : ""} ${embed.author.url ? `author-url="${embed.author.url}"` : ""}` : ""} ${embed.title ? `embed-title="${embed.title}"` : ""}${embed.color ? `color="${embed.hexColor}"` : ""}>`
|
|
66
|
+
];
|
|
67
|
+
if (embed.description) emb.push(`<discord-embed-description slot="description">${embed.description}</discord-embed-description>`);
|
|
68
|
+
if (embed.fields?.length) {
|
|
69
|
+
emb.push(`<discord-embed-fields slot="fields">`)
|
|
70
|
+
for (const field of embed.fields) emb.push(`<discord-embed-field field-title="${field.name}" ${field.inline ? `inline` : ""}>${field.value}</discord-embed-field>`)
|
|
71
|
+
}
|
|
72
|
+
arr.push(...emb, `</discord-embed>`)
|
|
73
|
+
}
|
|
74
|
+
str.push(...arr, "</discord-embeds>")
|
|
75
|
+
}
|
|
76
|
+
if (message.interaction?.user) str.push(`<discord-command slot="reply" command="${message.interaction.type === "APPLICATION_COMMAND" ? "/" : ""}${message.interaction.commandName}" profile="${message.interaction.user.id}" role-color="${channel.guild?.members?.resolve?.(message.interaction.user?.id)?.displayHexColor || "#fffff"}" author="${message.interaction.user.tag}" avatar="${message.interaction.user.displayAvatarURL({ dynamic: true })}"></discord-command>`)
|
|
77
|
+
if (message.components?.length) {
|
|
78
|
+
let row = [
|
|
79
|
+
`<discord-attachments slot="components">`
|
|
80
|
+
],
|
|
81
|
+
styles = {
|
|
82
|
+
"PRIMARY": "primary",
|
|
83
|
+
"SECONDARY": "secondary",
|
|
84
|
+
"SUCCESS": "success",
|
|
85
|
+
"DANGER": "destructive",
|
|
86
|
+
"LINK": "secondary"
|
|
87
|
+
}
|
|
88
|
+
for (const components of message.components) {
|
|
89
|
+
row.push(`<discord-action-row>`)
|
|
90
|
+
for (const c of components.components) {
|
|
91
|
+
if (c.type === "BUTTON") row.push(`<discord-button ${c.disabled ? `disabled=true` : ""} type="${styles[c.style]}" ${c.emoji?.name ? `emoji-name="${c.emoji.name}"` : ""} ${c.emoji?.id ? `emoji="https://cdn.discordapp.com/emojis/${c.emoji.id}.${c.emoji.animated ? "gif" : "png"}"` : ""} ${c.url ? `url="${c.url}"` : ""}>${c.label || ""}</discord-button>`)
|
|
92
|
+
}
|
|
93
|
+
row.push(`</discord-action-row>`)
|
|
94
|
+
}
|
|
95
|
+
if (row.length >= 2) str.push(...row, `</discord-attachments>`)
|
|
96
|
+
}
|
|
97
|
+
if (message.attachments.size) str.push(message.attachments.map((c) => `<a href="${c.proxyURL}">${c.name}</a>`).join("<br>"))
|
|
98
|
+
str.push(`${message.content?.length ? `<br><br>` : ""}<code style="background-color: #36393e; color: white;">ID: ${message.id}</code>`)
|
|
99
|
+
return [...str, `</discord-message>`].join(" ");
|
|
100
|
+
}),
|
|
101
|
+
"</discord-messages>"].join(" ");
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* @param {object} options
|
|
105
|
+
* @param {string} [options.userId]
|
|
106
|
+
* @param {string} [options.token]
|
|
107
|
+
* @param {import("discord.js").Guild} [options.guild]
|
|
108
|
+
* @returns {boolean}
|
|
109
|
+
*/
|
|
110
|
+
exports.hasTicket = ({ userId, guild, token, prefix } = {}) => {
|
|
111
|
+
if (!userId || !guild || !token || !prefix || !guild?.channels?.cache?.size) return false;
|
|
112
|
+
let channels = guild.channels.cache.filter(c => [ 0, "GUILD_TEXT" ].includes(c.type) && c.topic && exports.code(c.topic.split("ID: ")[1], "d", token) === userId && c.name?.match?.(new RegExp(prefix, "gi")));
|
|
113
|
+
if (!channels.size) return false;
|
|
114
|
+
return true;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.embed = (content, { color, title, guild, footer, author } = {}) => ({
|
|
118
|
+
title: title || "INFO", description: content,
|
|
119
|
+
color: color || 0xFF0000, timestamp: new Date(),
|
|
120
|
+
footer,
|
|
121
|
+
author: author || { name: guild?.name ?? "Tickets", icon_url: guild?.iconURL?.({ dynamic: true }) ?? "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1" }
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
exports.webhook = (options) => {
|
|
125
|
+
const { id, token, username, avatar } = options;
|
|
126
|
+
return new Webhook(`https://discord.com/api/webhooks/${id}/${token}`, { username, avatar_url: avatar });
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
exports.getWebhookInfo = (options) => {
|
|
130
|
+
return {
|
|
131
|
+
id: options.webhook?.id,
|
|
132
|
+
token: options.webhook?.token,
|
|
133
|
+
username: options.webhook?.username || "Tickets",
|
|
134
|
+
avatar: options.webhook?.avatar || "https://cdn.discordapp.com/emojis/818757771310792704.png?v=1"
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
exports.getAppealServer = ({ appeals, client } = {}) => {
|
|
139
|
+
if (!appeals?.enabled || !appeals?.mainserver?.checkIfBanned) return null;
|
|
140
|
+
let server = client.guilds.resolve(appeals.mainserver?.id);
|
|
141
|
+
if (!server?.available) return null;
|
|
142
|
+
return server;
|
|
143
143
|
}
|