1 |
rakin |
5 |
const { MessageEmbed } = require('discord.js'); |
2 |
rakin |
37 |
const util = require('./util'); |
3 |
rakin |
5 |
|
4 |
|
|
class Logger { |
5 |
|
|
constructor() { |
6 |
|
|
|
7 |
|
|
} |
8 |
|
|
|
9 |
|
|
channel(callback, msg) { |
10 |
rakin |
25 |
let channelID = app.config.props[msg.guild.id].logging_channel; |
11 |
rakin |
5 |
let channel = msg.guild.channels.cache.find(c => c.id === channelID); |
12 |
|
|
|
13 |
|
|
if (channel) { |
14 |
|
|
return callback(channel); |
15 |
|
|
} |
16 |
|
|
} |
17 |
|
|
|
18 |
rakin |
46 |
channelJoinLeft(callback, msg) { |
19 |
|
|
let channelID = app.config.props[msg.guild.id].logging_channel_join_leave; |
20 |
|
|
let channel = msg.guild.channels.cache.find(c => c.id === channelID); |
21 |
|
|
|
22 |
|
|
if (channel) { |
23 |
|
|
return callback(channel); |
24 |
|
|
} |
25 |
|
|
} |
26 |
|
|
|
27 |
rakin |
5 |
logEdit(oldMsg, newMsg) { |
28 |
|
|
this.channel(async (channel) => { |
29 |
|
|
await channel.send({ |
30 |
|
|
embeds: [ |
31 |
|
|
new MessageEmbed() |
32 |
|
|
.setColor('#007bff') |
33 |
|
|
.setTitle('Message Edited in #' + newMsg.channel.name + " (" + newMsg.channel.id + ")") |
34 |
rakin |
25 |
.setDescription('**-+-+Before**\n' + oldMsg.content + '\n\n**-+-+After**\n' + newMsg.content) |
35 |
rakin |
5 |
.addField('ID', newMsg.id) |
36 |
|
|
.setAuthor({ |
37 |
|
|
name: newMsg.author.tag, |
38 |
|
|
iconURL: newMsg.author.displayAvatarURL(), |
39 |
|
|
}) |
40 |
|
|
.setFooter({ |
41 |
|
|
text: "Edited", |
42 |
|
|
}) |
43 |
|
|
.setTimestamp() |
44 |
|
|
] |
45 |
|
|
}); |
46 |
|
|
}, newMsg); |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
logDelete(msg) { |
50 |
|
|
this.channel(async (channel) => { |
51 |
rakin |
25 |
const embed = new MessageEmbed() |
52 |
|
|
.setColor('#f14a60') |
53 |
|
|
.setTitle('Message Deleted in #' + msg.channel.name + " (" + msg.channel.id + ")") |
54 |
|
|
.setDescription(msg.content) |
55 |
|
|
.setAuthor({ |
56 |
|
|
name: msg.author.tag, |
57 |
|
|
iconURL: msg.author.displayAvatarURL(), |
58 |
|
|
}) |
59 |
|
|
.addField('ID', msg.id) |
60 |
|
|
.setFooter({ |
61 |
|
|
text: "Deleted", |
62 |
|
|
}) |
63 |
|
|
.setTimestamp(); |
64 |
|
|
|
65 |
|
|
if (msg.attachments.size > 0) { |
66 |
|
|
let str = ''; |
67 |
|
|
|
68 |
|
|
msg.attachments.forEach(a => { |
69 |
rakin |
41 |
str += `**${a.name}** ${a.url}\n`; |
70 |
rakin |
25 |
}); |
71 |
|
|
|
72 |
|
|
embed.addField('Attachments', str); |
73 |
|
|
} |
74 |
|
|
|
75 |
rakin |
5 |
await channel.send({ |
76 |
|
|
embeds: [ |
77 |
rakin |
25 |
embed |
78 |
|
|
] |
79 |
|
|
}); |
80 |
|
|
}, msg); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
logBanned(ban) { |
84 |
|
|
this.channel(async (channel) => { |
85 |
|
|
let r = '*No reason provided*'; |
86 |
|
|
|
87 |
|
|
if (ban.reason) { |
88 |
|
|
r = ban.reason; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
await channel.send({ |
92 |
|
|
embeds: [ |
93 |
rakin |
5 |
new MessageEmbed() |
94 |
|
|
.setColor('#f14a60') |
95 |
rakin |
25 |
.setTitle("A user was banned") |
96 |
rakin |
5 |
.setAuthor({ |
97 |
rakin |
25 |
name: ban.user.tag, |
98 |
|
|
iconURL: ban.user.displayAvatarURL(), |
99 |
rakin |
5 |
}) |
100 |
rakin |
25 |
.addField('Reason', r) |
101 |
|
|
.addField('User ID', ban.user.id) |
102 |
rakin |
5 |
.setFooter({ |
103 |
rakin |
25 |
text: "Banned", |
104 |
rakin |
5 |
}) |
105 |
|
|
.setTimestamp() |
106 |
|
|
] |
107 |
|
|
}); |
108 |
rakin |
25 |
}, ban); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
logUnbanned(ban) { |
112 |
|
|
this.channel(async (channel) => { |
113 |
|
|
await channel.send({ |
114 |
|
|
embeds: [ |
115 |
|
|
new MessageEmbed() |
116 |
|
|
.setColor('#f14a60') |
117 |
|
|
.setTitle("A user was unbanned") |
118 |
|
|
.setAuthor({ |
119 |
|
|
name: ban.user.tag, |
120 |
|
|
iconURL: ban.user.displayAvatarURL(), |
121 |
|
|
}) |
122 |
|
|
.addField('User ID', ban.user.id) |
123 |
|
|
.setFooter({ |
124 |
|
|
text: "Unbanned", |
125 |
|
|
}) |
126 |
|
|
.setTimestamp() |
127 |
|
|
] |
128 |
|
|
}); |
129 |
|
|
}, ban); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
logJoined(member) { |
133 |
rakin |
46 |
this.channelJoinLeft(async (channel) => { |
134 |
rakin |
25 |
await channel.send({ |
135 |
|
|
embeds: [ |
136 |
|
|
new MessageEmbed() |
137 |
|
|
.setColor('#007bff') |
138 |
|
|
.setTitle("New member joined") |
139 |
|
|
.setAuthor({ |
140 |
|
|
name: member.user.tag, |
141 |
|
|
iconURL: member.user.displayAvatarURL(), |
142 |
|
|
}) |
143 |
|
|
.setDescription(`<@${member.user.id}> just joined the server!`) |
144 |
rakin |
50 |
.addField('Account Created', `${member.user.createdAt.toLocaleString()} (${util.timeSince(member.user.createdAt.getTime())})`) |
145 |
rakin |
37 |
.addField('New Account?', (new Date().getTime() - member.user.createdAt.getTime()) <= 3 * 24 * 60 * 60 * 1000 ? ":warning: Yes :warning:" : "No") |
146 |
|
|
.addField('Bot?', member.user.bot === true ? 'Yes' : 'No') |
147 |
rakin |
25 |
.addField('User ID', member.user.id) |
148 |
|
|
.setFooter({ |
149 |
|
|
text: "Joined", |
150 |
|
|
}) |
151 |
|
|
.setTimestamp() |
152 |
|
|
] |
153 |
|
|
}); |
154 |
|
|
}, member); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
logLeft(member) { |
158 |
rakin |
46 |
this.channelJoinLeft(async (channel) => { |
159 |
rakin |
25 |
await channel.send({ |
160 |
|
|
embeds: [ |
161 |
|
|
new MessageEmbed() |
162 |
|
|
.setColor('#f14a60') |
163 |
|
|
.setTitle("Member left") |
164 |
|
|
.setAuthor({ |
165 |
|
|
name: member.user.tag, |
166 |
|
|
iconURL: member.user.displayAvatarURL(), |
167 |
|
|
}) |
168 |
rakin |
50 |
.addField('Joined at', `${member.joinedAt.toLocaleString()} (${util.timeSince(member.joinedAt.getTime())})`) |
169 |
rakin |
25 |
.addField('User ID', member.user.id) |
170 |
rakin |
37 |
.addField('Bot?', member.user.bot === true ? 'Yes' : 'No') |
171 |
rakin |
25 |
.setFooter({ |
172 |
|
|
text: "Left", |
173 |
|
|
}) |
174 |
|
|
.setTimestamp() |
175 |
|
|
] |
176 |
|
|
}); |
177 |
|
|
}, member); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
logBeaned(member, r, d) { |
181 |
|
|
this.channel(async (channel) => { |
182 |
|
|
await channel.send({ |
183 |
|
|
embeds: [ |
184 |
|
|
new MessageEmbed() |
185 |
|
|
.setColor('#007bff') |
186 |
|
|
.setTitle("Member beaned") |
187 |
|
|
.setAuthor({ |
188 |
|
|
name: member.user.tag, |
189 |
|
|
iconURL: member.user.displayAvatarURL(), |
190 |
|
|
}) |
191 |
|
|
.addField('Reason', r) |
192 |
|
|
.addField('Beaned by', d.tag) |
193 |
|
|
.addField('User ID', member.user.id) |
194 |
|
|
.setFooter({ |
195 |
|
|
text: "Beaned", |
196 |
|
|
}) |
197 |
|
|
.setTimestamp() |
198 |
|
|
] |
199 |
|
|
}); |
200 |
|
|
}, member); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
logMute(member, reason, timeMs, d) { |
204 |
|
|
this.channel(async (channel) => { |
205 |
|
|
await channel.send({ |
206 |
|
|
embeds: [ |
207 |
|
|
new MessageEmbed() |
208 |
|
|
.setColor('#f14a60') |
209 |
|
|
.setTitle("Member muted") |
210 |
|
|
.setAuthor({ |
211 |
|
|
name: member.user.tag, |
212 |
|
|
iconURL: member.user.displayAvatarURL(), |
213 |
|
|
}) |
214 |
|
|
.addField('Reason', reason) |
215 |
|
|
.addField('Muted by', d.tag) |
216 |
|
|
.addField('Duration Until', typeof timeMs === 'number' ? new Date((timeMs / 1000) + Date.now()).toLocaleString() : "*No duration set*") |
217 |
|
|
.addField('User ID', member.user.id) |
218 |
|
|
.setFooter({ |
219 |
|
|
text: "Muted", |
220 |
|
|
}) |
221 |
|
|
.setTimestamp() |
222 |
|
|
] |
223 |
|
|
}); |
224 |
|
|
}, member); |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
logUnmute(member, d) { |
228 |
|
|
this.channel(async (channel) => { |
229 |
|
|
await channel.send({ |
230 |
|
|
embeds: [ |
231 |
|
|
new MessageEmbed() |
232 |
|
|
.setColor('#007bff') |
233 |
|
|
.setTitle("Member unmuted") |
234 |
|
|
.setAuthor({ |
235 |
|
|
name: member.user.tag, |
236 |
|
|
iconURL: member.user.displayAvatarURL(), |
237 |
|
|
}) |
238 |
|
|
.addField('Unmuted by', d.tag) |
239 |
|
|
.addField('User ID', member.user.id) |
240 |
|
|
.setFooter({ |
241 |
|
|
text: "Unmuted", |
242 |
|
|
}) |
243 |
|
|
.setTimestamp() |
244 |
|
|
] |
245 |
|
|
}); |
246 |
|
|
}, member); |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
logWarn(msg, member, d, reason) { |
250 |
|
|
if (member.user) |
251 |
|
|
member = member.user; |
252 |
|
|
|
253 |
|
|
this.channel(async (channel) => { |
254 |
|
|
await channel.send({ |
255 |
|
|
embeds: [ |
256 |
|
|
new MessageEmbed() |
257 |
|
|
.setColor('GOLD') |
258 |
|
|
.setTitle("Member warned") |
259 |
|
|
.setAuthor({ |
260 |
|
|
name: member.tag, |
261 |
|
|
iconURL: member.displayAvatarURL(), |
262 |
|
|
}) |
263 |
|
|
.addField('Reason', reason) |
264 |
|
|
.addField('Warned by', d.tag) |
265 |
|
|
.addField('User ID', member.id) |
266 |
|
|
.setFooter({ |
267 |
|
|
text: "Warned", |
268 |
|
|
}) |
269 |
|
|
.setTimestamp() |
270 |
|
|
] |
271 |
|
|
}); |
272 |
rakin |
5 |
}, msg); |
273 |
|
|
} |
274 |
rakin |
25 |
|
275 |
|
|
logWarndel(msg, member, warn, d) { |
276 |
|
|
this.channel(async (channel) => { |
277 |
|
|
await channel.send({ |
278 |
|
|
embeds: [ |
279 |
|
|
new MessageEmbed() |
280 |
|
|
.setColor('GOLD') |
281 |
|
|
.setTitle("Warning deleted") |
282 |
|
|
.setAuthor({ |
283 |
|
|
name: member.user.tag, |
284 |
|
|
iconURL: member.user.displayAvatarURL(), |
285 |
|
|
}) |
286 |
|
|
.addField('Warned by', d.tag + '') |
287 |
|
|
.addField('Warning ID', warn.id + '') |
288 |
|
|
.addField('User ID', member.user.id) |
289 |
|
|
.setFooter({ |
290 |
|
|
text: "Warning Deleted", |
291 |
|
|
}) |
292 |
|
|
.setTimestamp() |
293 |
|
|
] |
294 |
|
|
}); |
295 |
|
|
}, msg); |
296 |
|
|
} |
297 |
rakin |
5 |
} |
298 |
|
|
|
299 |
rakin |
50 |
module.exports = Logger; |