/[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 106 by rakin, Mon Jul 29 17:28:37 2024 UTC revision 393 by rakin, Mon Jul 29 17:29:59 2024 UTC
# Line 1  Line 1 
1    /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20  import { roleMention } from '@discordjs/builders';  import { roleMention } from '@discordjs/builders';
21  import { BanOptions, CommandInteraction, FileOptions, Guild, GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js';  import { formatDuration, intervalToDuration } from 'date-fns';
22    import { BanOptions, CommandInteraction, FileOptions, Guild, GuildBan, GuildMember, Message, MessageEmbed, MessageOptions, MessagePayload, TextChannel, User } from 'discord.js';
23  import ms from 'ms';  import ms from 'ms';
24  import DiscordClient from '../client/Client';  import DiscordClient from '../client/Client';
25  import Punishment from '../models/Punishment';  import { IPunishment } from '../models/Punishment';
26  import { timeProcess, timeSince } from '../utils/util';  import { timeSince } from '../utils/util';
27    
28  class Logger {  class Logger {
29      client: DiscordClient;      client: DiscordClient;
# Line 30  class Logger { Line 50  class Logger {
50          }          }
51      }      }
52    
53        async send(guild: Guild, messageOptions: MessageOptions | MessagePayload | string) {
54            let channelID = this.client.config.props[guild!.id].logging_channel;
55            let channel = guild!.channels.cache.find((c: any) => c.id === channelID) as TextChannel;
56    
57            if (channel) {
58                return await channel.send(messageOptions);
59            }
60        }
61    
62        log(guild: Guild, callback: (channel: TextChannel) => any) {
63            this.channel(callback, { guild });
64        }
65    
66      logEdit(oldMsg: Message, newMsg: Message) {      logEdit(oldMsg: Message, newMsg: Message) {
67          this.channel(async (channel) => {          this.channel(async (channel) => {
68              await channel.send({              await channel.send({
# Line 135  class Logger { Line 168  class Logger {
168          }, ban);          }, ban);
169      }      }
170    
171      logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {      logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: IPunishment) {
172          this.channel(async (channel) => {          this.channel(async (channel) => {
173              let r = '*No reason provided*';              let r = '*No reason provided*';
174    
# Line 166  class Logger { Line 199  class Logger {
199                          iconURL: user.displayAvatarURL(),                          iconURL: user.displayAvatarURL(),
200                      })                      })
201                      .addField('Reason', r)                      .addField('Reason', r)
202                      .addField('Softbanned by', model.get().mod_tag)                      .addField('Softbanned by', model.mod_tag)
203                      .addField('User ID', user.id)                      .addField('User ID', user.id)
204                      .setFooter({                      .setFooter({
205                          text: "Softbanned",                          text: "Softbanned",
# Line 179  class Logger { Line 212  class Logger {
212          });          });
213      }      }
214    
215      logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {      logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: IPunishment) {
216          this.channel(async (channel) => {          this.channel(async (channel) => {
217              let r = '*No reason provided*';              let r = '*No reason provided*';
218    
# Line 210  class Logger { Line 243  class Logger {
243                          iconURL: user.displayAvatarURL(),                          iconURL: user.displayAvatarURL(),
244                      })                      })
245                      .addField('Reason', r)                      .addField('Reason', r)
246                      .addField('Banned by', model.get().mod_tag)                      .addField('Banned by', model.mod_tag)
247                      .addField('User ID', user.id)                      .addField('User ID', user.id)
248                      .addField('Duration', ms(model.get().meta?.time))                      .addField('Duration', ms((model.meta as any).time))
249                      .setFooter({                      .setFooter({
250                          text: "Temporarily banned",                          text: "Temporarily banned",
251                      })                      })
# Line 319  class Logger { Line 352  class Logger {
352          }, member);          }, member);
353      }      }
354    
355      logMute(member: GuildMember, reason: string, timeMs: number | null | undefined, d: User) {      logMute(member: GuildMember, reason: string, duration: number | null | undefined, d: User, hard: boolean = true) {
356          this.channel(async (channel) => {          this.channel(async (channel) => {
357              await channel.send({              await channel.send({
358                  embeds: [                  embeds: [
# Line 332  class Logger { Line 365  class Logger {
365                      })                      })
366                      .addField('Reason', reason)                      .addField('Reason', reason)
367                      .addField('Muted by', d.tag)                      .addField('Muted by', d.tag)
368                      .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*")
369                      .addField('User ID', member.user.id)                      .addField('User ID', member.user.id)
370                        .addField('Hardmute', hard ? 'Yes' : 'No')
371                      .setFooter({                      .setFooter({
372                          text: "Muted",                          text: "Muted",
373                      })                      })

Legend:
Removed from v.106  
changed lines
  Added in v.393

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26