/[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 124 by rakin, Mon Jul 29 17:28:41 2024 UTC revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import { roleMention } from '@discordjs/builders';  import { roleMention } from '@discordjs/builders';
2  import { BanOptions, CommandInteraction, FileOptions, Guild, GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js';  import { formatDuration, intervalToDuration } from 'date-fns';
3    import { BanOptions, CommandInteraction, FileOptions, Guild, GuildBan, GuildMember, Message, MessageEmbed, MessageOptions, MessagePayload, TextChannel, User } from 'discord.js';
4  import ms from 'ms';  import ms from 'ms';
5  import DiscordClient from '../client/Client';  import DiscordClient from '../client/Client';
6  import Punishment from '../models/Punishment';  import { IPunishment } from '../models/Punishment';
7  import { timeProcess, timeSince } from '../utils/util';  import { timeSince } from '../utils/util';
8    
9  class Logger {  class Logger {
10      client: DiscordClient;      client: DiscordClient;
# Line 30  class Logger { Line 31  class Logger {
31          }          }
32      }      }
33    
34        async send(guild: Guild, messageOptions: MessageOptions | MessagePayload | string) {
35            let channelID = this.client.config.props[guild!.id].logging_channel;
36            let channel = guild!.channels.cache.find((c: any) => c.id === channelID) as TextChannel;
37    
38            if (channel) {
39                return await channel.send(messageOptions);
40            }
41        }
42    
43        log(guild: Guild, callback: (channel: TextChannel) => any) {
44            this.channel(callback, { guild });
45        }
46    
47      logEdit(oldMsg: Message, newMsg: Message) {      logEdit(oldMsg: Message, newMsg: Message) {
48          this.channel(async (channel) => {          this.channel(async (channel) => {
49              await channel.send({              await channel.send({
# Line 135  class Logger { Line 149  class Logger {
149          }, ban);          }, ban);
150      }      }
151    
152      logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {      logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: IPunishment) {
153          this.channel(async (channel) => {          this.channel(async (channel) => {
154              let r = '*No reason provided*';              let r = '*No reason provided*';
155    
# Line 166  class Logger { Line 180  class Logger {
180                          iconURL: user.displayAvatarURL(),                          iconURL: user.displayAvatarURL(),
181                      })                      })
182                      .addField('Reason', r)                      .addField('Reason', r)
183                      .addField('Softbanned by', model.get().mod_tag)                      .addField('Softbanned by', model.mod_tag)
184                      .addField('User ID', user.id)                      .addField('User ID', user.id)
185                      .setFooter({                      .setFooter({
186                          text: "Softbanned",                          text: "Softbanned",
# Line 179  class Logger { Line 193  class Logger {
193          });          });
194      }      }
195    
196      logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {      logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: IPunishment) {
197          this.channel(async (channel) => {          this.channel(async (channel) => {
198              let r = '*No reason provided*';              let r = '*No reason provided*';
199    
# Line 210  class Logger { Line 224  class Logger {
224                          iconURL: user.displayAvatarURL(),                          iconURL: user.displayAvatarURL(),
225                      })                      })
226                      .addField('Reason', r)                      .addField('Reason', r)
227                      .addField('Banned by', model.get().mod_tag)                      .addField('Banned by', model.mod_tag)
228                      .addField('User ID', user.id)                      .addField('User ID', user.id)
229                      .addField('Duration', ms(model.get().meta?.time))                      .addField('Duration', ms((model.meta as any).time))
230                      .setFooter({                      .setFooter({
231                          text: "Temporarily banned",                          text: "Temporarily banned",
232                      })                      })
# Line 319  class Logger { Line 333  class Logger {
333          }, member);          }, member);
334      }      }
335    
336      logMute(member: GuildMember, reason: string, timeMs: number | null | undefined, d: User, hard: boolean = true) {      logMute(member: GuildMember, reason: string, duration: number | null | undefined, d: User, hard: boolean = true) {
337          this.channel(async (channel) => {          this.channel(async (channel) => {
338              await channel.send({              await channel.send({
339                  embeds: [                  embeds: [
# Line 332  class Logger { Line 346  class Logger {
346                      })                      })
347                      .addField('Reason', reason)                      .addField('Reason', reason)
348                      .addField('Muted by', d.tag)                      .addField('Muted by', d.tag)
349                      .addField('Duration Until', typeof timeMs === 'number' ? `${new Date((timeMs / 1000) + Date.now()).toLocaleString()} (${timeProcess(timeMs / 1000)})` : "*No duration set*")                      .addField('Duration Until', duration ? `${(new Date(Date.now() + duration)).toLocaleString()} (${formatDuration(intervalToDuration({ start: 0, end: duration }))})` : "*No duration set*")
350                      .addField('User ID', member.user.id)                      .addField('User ID', member.user.id)
351                      .addField('Hardmute', hard ? 'Yes' : 'No')                      .addField('Hardmute', hard ? 'Yes' : 'No')
352                      .setFooter({                      .setFooter({

Legend:
Removed from v.124  
changed lines
  Added in v.344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26