/[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 105 by rakin, Mon Jul 29 17:28:32 2024 UTC revision 106 by rakin, Mon Jul 29 17:28:37 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 133  class Logger { Line 135  class Logger {
135          }, ban);          }, ban);
136      }      }
137    
138        logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {
139            this.channel(async (channel) => {
140                let r = '*No reason provided*';
141    
142                const auditLog = (await guild.fetchAuditLogs({
143                    limit: 1,
144                    type: 'MEMBER_BAN_ADD',
145                })).entries.first();        
146    
147                if (banOptions.reason) {
148                    r = banOptions.reason;
149                }
150                else if (auditLog) {
151                    console.log(auditLog);  
152                    const { target, reason } = await auditLog;
153    
154                    if (target!.id === user.id && reason) {
155                        r = await reason;
156                    }
157                }
158    
159                await channel.send({
160                    embeds: [
161                        new MessageEmbed()
162                        .setColor('#f14a60')
163                        .setTitle("A user was softbanned")
164                        .setAuthor({
165                            name: user.tag,
166                            iconURL: user.displayAvatarURL(),
167                        })
168                        .addField('Reason', r)
169                        .addField('Softbanned by', model.get().mod_tag)
170                        .addField('User ID', user.id)
171                        .setFooter({
172                            text: "Softbanned",
173                        })
174                        .setTimestamp()
175                    ]
176                });
177            }, {
178                guild
179            });
180        }
181    
182        logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: Punishment) {
183            this.channel(async (channel) => {
184                let r = '*No reason provided*';
185    
186                const auditLog = (await guild.fetchAuditLogs({
187                    limit: 1,
188                    type: 'MEMBER_BAN_ADD',
189                })).entries.first();        
190    
191                if (banOptions.reason) {
192                    r = banOptions.reason;
193                }
194                else if (auditLog) {
195                    console.log(auditLog);  
196                    const { target, reason } = await auditLog;
197    
198                    if (target!.id === user.id && reason) {
199                        r = await reason;
200                    }
201                }
202    
203                await channel.send({
204                    embeds: [
205                        new MessageEmbed()
206                        .setColor('#f14a60')
207                        .setTitle("A user was temporarily banned")
208                        .setAuthor({
209                            name: user.tag,
210                            iconURL: user.displayAvatarURL(),
211                        })
212                        .addField('Reason', r)
213                        .addField('Banned by', model.get().mod_tag)
214                        .addField('User ID', user.id)
215                        .addField('Duration', ms(model.get().meta?.time))
216                        .setFooter({
217                            text: "Temporarily banned",
218                        })
219                        .setTimestamp()
220                    ]
221                });
222            }, {
223                guild
224            });
225        }
226    
227      logUnbanned(ban: GuildBan) {      logUnbanned(ban: GuildBan) {
228          this.channel(async (channel) => {          this.channel(async (channel) => {
229              await channel.send({              await channel.send({

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26