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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 85 by rakin, Mon Jul 29 17:28:32 2024 UTC revision 214 by rakin, Mon Jul 29 17:29:03 2024 UTC
# Line 1  Line 1 
1  import { roleMention } from '@discordjs/builders';  import { roleMention } from '@discordjs/builders';
2  import { CommandInteraction, FileOptions, GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js';  import { BanOptions, CommandInteraction, FileOptions, Guild, GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js';
3    import ms from 'ms';
4  import DiscordClient from '../client/Client';  import DiscordClient from '../client/Client';
5    import Punishment from '../models/Punishment';
6  import { timeProcess, timeSince } from '../utils/util';  import { timeProcess, timeSince } from '../utils/util';
7    
8  class Logger {  class Logger {
# Line 28  class Logger { Line 30  class Logger {
30          }          }
31      }      }
32    
33        log(guild: Guild, callback: (channel: TextChannel) => any) {
34            this.channel(callback, { guild });
35        }
36    
37      logEdit(oldMsg: Message, newMsg: Message) {      logEdit(oldMsg: Message, newMsg: Message) {
38          this.channel(async (channel) => {          this.channel(async (channel) => {
39              await channel.send({              await channel.send({
# Line 133  class Logger { Line 139  class Logger {
139          }, ban);          }, ban);
140      }      }
141    
142        logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {
143            this.channel(async (channel) => {
144                let r = '*No reason provided*';
145    
146                const auditLog = (await guild.fetchAuditLogs({
147                    limit: 1,
148                    type: 'MEMBER_BAN_ADD',
149                })).entries.first();        
150    
151                if (banOptions.reason) {
152                    r = banOptions.reason;
153                }
154                else if (auditLog) {
155                    console.log(auditLog);  
156                    const { target, reason } = await auditLog;
157    
158                    if (target!.id === user.id && reason) {
159                        r = await reason;
160                    }
161                }
162    
163                await channel.send({
164                    embeds: [
165                        new MessageEmbed()
166                        .setColor('#f14a60')
167                        .setTitle("A user was softbanned")
168                        .setAuthor({
169                            name: user.tag,
170                            iconURL: user.displayAvatarURL(),
171                        })
172                        .addField('Reason', r)
173                        .addField('Softbanned by', model.get().mod_tag)
174                        .addField('User ID', user.id)
175                        .setFooter({
176                            text: "Softbanned",
177                        })
178                        .setTimestamp()
179                    ]
180                });
181            }, {
182                guild
183            });
184        }
185    
186        logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {
187            this.channel(async (channel) => {
188                let r = '*No reason provided*';
189    
190                const auditLog = (await guild.fetchAuditLogs({
191                    limit: 1,
192                    type: 'MEMBER_BAN_ADD',
193                })).entries.first();        
194    
195                if (banOptions.reason) {
196                    r = banOptions.reason;
197                }
198                else if (auditLog) {
199                    console.log(auditLog);  
200                    const { target, reason } = await auditLog;
201    
202                    if (target!.id === user.id && reason) {
203                        r = await reason;
204                    }
205                }
206    
207                await channel.send({
208                    embeds: [
209                        new MessageEmbed()
210                        .setColor('#f14a60')
211                        .setTitle("A user was temporarily banned")
212                        .setAuthor({
213                            name: user.tag,
214                            iconURL: user.displayAvatarURL(),
215                        })
216                        .addField('Reason', r)
217                        .addField('Banned by', model.get().mod_tag)
218                        .addField('User ID', user.id)
219                        .addField('Duration', ms(model.get().meta?.time))
220                        .setFooter({
221                            text: "Temporarily banned",
222                        })
223                        .setTimestamp()
224                    ]
225                });
226            }, {
227                guild
228            });
229        }
230    
231      logUnbanned(ban: GuildBan) {      logUnbanned(ban: GuildBan) {
232          this.channel(async (channel) => {          this.channel(async (channel) => {
233              await channel.send({              await channel.send({
# Line 228  class Logger { Line 323  class Logger {
323          }, member);          }, member);
324      }      }
325    
326      logMute(member: GuildMember, reason: string, timeMs: number | null | undefined, d: User) {      logMute(member: GuildMember, reason: string, timeMs: number | null | undefined, d: User, hard: boolean = true) {
327          this.channel(async (channel) => {          this.channel(async (channel) => {
328              await channel.send({              await channel.send({
329                  embeds: [                  embeds: [
# Line 243  class Logger { Line 338  class Logger {
338                      .addField('Muted by', d.tag)                      .addField('Muted by', d.tag)
339                      .addField('Duration Until', typeof timeMs === 'number' ? `${new Date((timeMs / 1000) + Date.now()).toLocaleString()} (${timeProcess(timeMs / 1000)})` : "*No duration set*")                      .addField('Duration Until', typeof timeMs === 'number' ? `${new Date((timeMs / 1000) + Date.now()).toLocaleString()} (${timeProcess(timeMs / 1000)})` : "*No duration set*")
340                      .addField('User ID', member.user.id)                      .addField('User ID', member.user.id)
341                        .addField('Hardmute', hard ? 'Yes' : 'No')
342                      .setFooter({                      .setFooter({
343                          text: "Muted",                          text: "Muted",
344                      })                      })

Legend:
Removed from v.85  
changed lines
  Added in v.214

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26