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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (show 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 import { roleMention } from '@discordjs/builders';
2 import { 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: 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
17 if (channel) {
18 return callback(channel);
19 }
20 }
21
22 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
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 if (ban.reason) {
99 r = ban.reason;
100 }
101
102 await channel.send({
103 embeds: [
104 new MessageEmbed()
105 .setColor('#f14a60')
106 .setTitle("A user was banned")
107 .setAuthor({
108 name: ban.user.tag,
109 iconURL: ban.user.displayAvatarURL(),
110 })
111 .addField('Reason', r)
112 .addField('User ID', ban.user.id)
113 .setFooter({
114 text: "Banned",
115 })
116 .setTimestamp()
117 ]
118 });
119 }, ban);
120 }
121
122 logUnbanned(ban: GuildBan) {
123 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 logJoined(member: GuildMember) {
144 this.channelJoinLeft(async (channel) => {
145 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 .addField('Account Created', `${member.user.createdAt.toLocaleString()} (${timeSince(member.user.createdAt.getTime())})`)
156 .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 .addField('User ID', member.user.id)
159 .setFooter({
160 text: "Joined",
161 })
162 .setTimestamp()
163 ]
164 });
165 }, member);
166 }
167
168 logLeft(member: GuildMember) {
169 this.channelJoinLeft(async (channel) => {
170 const roles = await member.roles.cache.filter(role => role.id !== member.guild.id).reduce((acc, val) => ` ${acc} ${roleMention(val.id)}`, '');
171
172 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 .setDescription(`**Roles**\n${roles}`)
182 .addField('Joined at', `${member.joinedAt!.toLocaleString()} (${timeSince(member.joinedAt!.getTime())})`)
183 .addField('User ID', member.user.id)
184 .addField('Bot?', member.user.bot === true ? 'Yes' : 'No')
185 .setFooter({
186 text: "Left",
187 })
188 .setTimestamp()
189 ]
190 });
191 }, member);
192 }
193
194 logBeaned(member: GuildMember, r: string, d: User) {
195 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 logMute(member: GuildMember, reason: string, timeMs: number | null | undefined, d: User) {
218 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 .addField('Duration Until', typeof timeMs === 'number' ? `${new Date((timeMs / 1000) + Date.now()).toLocaleString()} (${timeProcess(timeMs / 1000)})` : "*No duration set*")
231 .addField('User ID', member.user.id)
232 .setFooter({
233 text: "Muted",
234 })
235 .setTimestamp()
236 ]
237 });
238 }, member);
239 }
240
241 logUnmute(member: GuildMember, d: User) {
242 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 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
267 this.channel(async (channel) => {
268 await channel.send({
269 embeds: [
270 new MessageEmbed()
271 .setColor('GOLD')
272 .setTitle("Member warned")
273 .setAuthor({
274 name: (member as User).tag,
275 iconURL: member.displayAvatarURL(),
276 })
277 .addField('Reason', reason)
278 .addField('Warned by', d.tag)
279 .addField('User ID', member.id)
280 .addField('Warning ID', id + '')
281 .setFooter({
282 text: "Warned",
283 })
284 .setTimestamp()
285 ]
286 });
287 }, msg);
288 }
289
290 logWarndel(msg: Message, member: GuildMember, warn: any, d: User) {
291 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 }
313
314 export default Logger;

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26