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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26