/[sudobot]/trunk/src/automod/Logger.ts
ViewVC logotype

Annotation of /trunk/src/automod/Logger.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26