-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessCustomCommands.js
More file actions
106 lines (89 loc) · 4.31 KB
/
Copy pathprocessCustomCommands.js
File metadata and controls
106 lines (89 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
async function processCustomCommands(client, message) {
try {
const content = message.content.trim();
const commandName = content.split(' ')[0].toLowerCase();
const command = config.CustomCommands[commandName];
if (!command) {
return;
}
const memberRoles = message.member.roles.cache.map(r => r.id);
const isWhitelisted = command.Roles.Whitelist.length === 0 ||
command.Roles.Whitelist.some(roleId => memberRoles.includes(roleId));
if (!isWhitelisted) {
return;
}
let responseOptions = {};
if (command.type === "EMBED") {
const embed = new EmbedBuilder()
.setColor(command.Embed.Color || null);
if (command.Embed.Title) {
embed.setTitle(replaceCustomCommandPlaceholders(command.Embed.Title, message, { commandName }));
}
if (command.Embed.Description && command.Embed.Description.length > 0) {
const description = command.Embed.Description.map(line =>
replaceCustomCommandPlaceholders(line, message, { commandName })
).join("\n");
embed.setDescription(description);
}
if (command.Embed.Footer && command.Embed.Footer.Text) {
const footerText = replaceCustomCommandPlaceholders(command.Embed.Footer.Text, message, { commandName });
const footerIcon = command.Embed.Footer.Icon ?
replaceCustomCommandPlaceholders(command.Embed.Footer.Icon, message, { commandName }) :
undefined;
embed.setFooter({ text: footerText, iconURL: footerIcon });
}
if (command.Embed.Author && command.Embed.Author.Text) {
const authorName = replaceCustomCommandPlaceholders(command.Embed.Author.Text, message, { commandName });
const authorIcon = command.Embed.Author.Icon ?
replaceCustomCommandPlaceholders(command.Embed.Author.Icon, message, { commandName }) :
undefined;
embed.setAuthor({ name: authorName, iconURL: authorIcon });
}
if (command.Embed.Thumbnail) {
embed.setThumbnail(replaceCustomCommandPlaceholders(command.Embed.Thumbnail, message, { commandName }));
}
if (command.Embed.Image) {
embed.setImage(replaceCustomCommandPlaceholders(command.Embed.Image, message, { commandName }));
}
if (command.Embed.Fields) {
command.Embed.Fields.forEach(field => {
if (field.Name && field.Value) {
const fieldName = replaceCustomCommandPlaceholders(field.Name, message, { commandName });
const fieldValue = replaceCustomCommandPlaceholders(field.Value, message, { commandName });
embed.addFields({ name: fieldName, value: fieldValue, inline: field.Inline ?? false });
}
});
}
responseOptions.embeds = [embed];
if (command.Buttons && Array.isArray(command.Buttons)) {
const buttons = createButtons(command.Buttons, commandName);
if (buttons) {
responseOptions.components = [buttons];
}
}
} else if (command.type === "TEXT") {
responseOptions.content = replaceCustomCommandPlaceholders(command.text, message, { commandName });
}
if (!responseOptions.content && (!responseOptions.embeds || responseOptions.embeds.length === 0)) {
return;
}
try {
if (command.Options.ReplyToUser) {
await message.reply(responseOptions);
} else {
await message.channel.send(responseOptions);
}
if (command.Options.DeleteTriggerMessage) {
try {
await message.delete();
} catch (error) {
console.error('Error deleting message:', error);
}
}
} catch (error) {
console.error('Error sending message:', error);
}
} catch (error) {
console.error('Error processing custom commands:', error);
}
}