-
Notifications
You must be signed in to change notification settings - Fork 0
/
logSystem.js
85 lines (74 loc) · 2.32 KB
/
logSystem.js
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
const Discord = require("discord.js");
class Log {
static client = null;
static logChannel = null;
static yellow = "#ffd500";
static red = "#cf2525";
static gray = "#1f1f1f";
static configure(client, logChannel) {
this.client = client;
this.logChannel = logChannel;
}
static isInteraction(messageOrInteraction) {
if (messageOrInteraction.commandName) {
return true;
} else {
return false;
}
}
static dcReply(messageOrInteraction, data) {
if (!messageOrInteraction) return;
if (messageOrInteraction.commandName) { //Reply to the interaction
if (messageOrInteraction.replied) {
return messageOrInteraction.editReply(data);
} else {
return messageOrInteraction.reply(data);
}
} else { //Send as message
return messageOrInteraction.channel.send(data);
}
}
static error(body, message) {
this.log(body, message, "error");
}
static warn(body, message) {
this.log(body, message, "warn");
}
static log(body, message, type) {
//Determine importance level and set title and color variable accordingly
let title = "Log (importance level not set)";
let color = this.gray;
switch (type) {
case ("warn"):
title = ":warning: Warning";
color = this.yellow;
break;
case ("error"):
title = ":exclamation: Error";
color = this.red;
break;
}
//Send error in terminal if log channel is not set
if(!this.logChannel) {
return console.log(`\nError channel not set, have you forgot to configure the error channel using Log.configure?\n${body.stack}`);
}
//Assemble embed and send it in the configured log channel
let messageContent = "Message: **none**";
if (message.content) {
messageContent = `Message: **${message.content}**`;
} else {
messageContent = `Slash command: **${message.commandName}**`
}
let channel = this.client.channels.cache.get(this.logChannel);
const embed = new Discord.EmbedBuilder()
.setColor(color)
.setTitle(title)
.setDescription(`**${body.name}:** ${body.message}`)
.addFields(
{ name: "Call stack", value: `\`\`\`${body.stack}\`\`\`` },
{ name: "Origin", value: `Guild: **${message.member.guild.name}** (${message.member.guild.id})\nUser: **${message.member.user.tag}** (${message.member.id})\n${messageContent}` }
);
return channel.send({ embeds: [embed] });
}
}
module.exports = { Log };