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; |
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) { |
log(guild: Guild, callback: (channel: TextChannel) => any) { |
44 |
this.channel(callback, { guild }); |
this.channel(callback, { guild }); |
45 |
} |
} |
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 |
|
|
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", |
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 |
|
|
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 |
}) |
}) |
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: [ |
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({ |