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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26