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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26