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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26