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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months ago) by rakin
File MIME type: application/typescript
File size: 10907 byte(s)
Release version 2.0
1 import { GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js';
2 import DiscordClient from '../client/Client';
3 import { timeProcess, timeSince } from '../utils/util';
4
5 class Logger {
6 client: DiscordClient;
7
8 constructor(client: DiscordClient) {
9 this.client = client;
10 }
11
12 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
16 if (channel) {
17 return callback(channel);
18 }
19 }
20
21 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
25 if (channel) {
26 return callback(channel);
27 }
28 }
29
30 logEdit(oldMsg: Message, newMsg: Message) {
31 this.channel(async (channel) => {
32 await channel.send({
33 embeds: [
34 new MessageEmbed()
35 .setColor('#007bff')
36 .setTitle('Message Edited in #' + (newMsg.channel as TextChannel).name + " (" + newMsg.channel.id + ")")
37 .setDescription('**-+-+Before**\n' + oldMsg.content + '\n\n**-+-+After**\n' + newMsg.content)
38 .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 logDelete(msg: Message) {
53 this.channel(async (channel) => {
54 const embed = new MessageEmbed()
55 .setColor('#f14a60')
56 .setTitle('Message Deleted in #' + (msg.channel as TextChannel).name + " (" + msg.channel.id + ")")
57 .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 str += `**${a.name}** ${a.url}\n`;
73 });
74
75 embed.addField('Attachments', str);
76 }
77
78 await channel.send({
79 embeds: [
80 embed
81 ]
82 });
83 }, msg);
84 }
85
86 logBanned(ban: GuildBan) {
87 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 new MessageEmbed()
97 .setColor('#f14a60')
98 .setTitle("A user was banned")
99 .setAuthor({
100 name: ban.user.tag,
101 iconURL: ban.user.displayAvatarURL(),
102 })
103 .addField('Reason', r)
104 .addField('User ID', ban.user.id)
105 .setFooter({
106 text: "Banned",
107 })
108 .setTimestamp()
109 ]
110 });
111 }, ban);
112 }
113
114 logUnbanned(ban: GuildBan) {
115 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 logJoined(member: GuildMember) {
136 this.channelJoinLeft(async (channel) => {
137 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 .addField('Account Created', `${member.user.createdAt.toLocaleString()} (${timeSince(member.user.createdAt.getTime())})`)
148 .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 .addField('User ID', member.user.id)
151 .setFooter({
152 text: "Joined",
153 })
154 .setTimestamp()
155 ]
156 });
157 }, member);
158 }
159
160 logLeft(member: GuildMember) {
161 this.channelJoinLeft(async (channel) => {
162 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 .addField('Joined at', `${member.joinedAt!.toLocaleString()} (${timeSince(member.joinedAt!.getTime())})`)
172 .addField('User ID', member.user.id)
173 .addField('Bot?', member.user.bot === true ? 'Yes' : 'No')
174 .setFooter({
175 text: "Left",
176 })
177 .setTimestamp()
178 ]
179 });
180 }, member);
181 }
182
183 logBeaned(member: GuildMember, r: string, d: User) {
184 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 logMute(member: GuildMember, reason: string, timeMs: number | null | undefined, d: User) {
207 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 .addField('Duration Until', typeof timeMs === 'number' ? `${new Date((timeMs / 1000) + Date.now()).toLocaleString()} (${timeProcess(timeMs / 1000)})` : "*No duration set*")
220 .addField('User ID', member.user.id)
221 .setFooter({
222 text: "Muted",
223 })
224 .setTimestamp()
225 ]
226 });
227 }, member);
228 }
229
230 logUnmute(member: GuildMember, d: User) {
231 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 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
256 this.channel(async (channel) => {
257 await channel.send({
258 embeds: [
259 new MessageEmbed()
260 .setColor('GOLD')
261 .setTitle("Member warned")
262 .setAuthor({
263 name: (member as User).tag,
264 iconURL: member.displayAvatarURL(),
265 })
266 .addField('Reason', reason)
267 .addField('Warned by', d.tag)
268 .addField('User ID', member.id)
269 .addField('Warning ID', id + '')
270 .setFooter({
271 text: "Warned",
272 })
273 .setTimestamp()
274 ]
275 });
276 }, msg);
277 }
278
279 logWarndel(msg: Message, member: GuildMember, warn: any, d: User) {
280 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 }
302
303 export default Logger;

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26