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 { 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'; |
5 |
import DiscordClient from '../client/Client'; |
import DiscordClient from '../client/Client'; |
6 |
import { timeProcess, timeSince } from '../utils/util'; |
import { IPunishment } from '../models/Punishment'; |
7 |
|
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) { |
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({ |
149 |
}, ban); |
}, ban); |
150 |
} |
} |
151 |
|
|
152 |
|
logSoftBan(banOptions: BanOptions, guild: Guild, user: User, model: IPunishment) { |
153 |
|
this.channel(async (channel) => { |
154 |
|
let r = '*No reason provided*'; |
155 |
|
|
156 |
|
const auditLog = (await guild.fetchAuditLogs({ |
157 |
|
limit: 1, |
158 |
|
type: 'MEMBER_BAN_ADD', |
159 |
|
})).entries.first(); |
160 |
|
|
161 |
|
if (banOptions.reason) { |
162 |
|
r = banOptions.reason; |
163 |
|
} |
164 |
|
else if (auditLog) { |
165 |
|
console.log(auditLog); |
166 |
|
const { target, reason } = await auditLog; |
167 |
|
|
168 |
|
if (target!.id === user.id && reason) { |
169 |
|
r = await reason; |
170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
|
await channel.send({ |
174 |
|
embeds: [ |
175 |
|
new MessageEmbed() |
176 |
|
.setColor('#f14a60') |
177 |
|
.setTitle("A user was softbanned") |
178 |
|
.setAuthor({ |
179 |
|
name: user.tag, |
180 |
|
iconURL: user.displayAvatarURL(), |
181 |
|
}) |
182 |
|
.addField('Reason', r) |
183 |
|
.addField('Softbanned by', model.mod_tag) |
184 |
|
.addField('User ID', user.id) |
185 |
|
.setFooter({ |
186 |
|
text: "Softbanned", |
187 |
|
}) |
188 |
|
.setTimestamp() |
189 |
|
] |
190 |
|
}); |
191 |
|
}, { |
192 |
|
guild |
193 |
|
}); |
194 |
|
} |
195 |
|
|
196 |
|
logTempBan(banOptions: BanOptions, guild: Guild, user: User, model: IPunishment) { |
197 |
|
this.channel(async (channel) => { |
198 |
|
let r = '*No reason provided*'; |
199 |
|
|
200 |
|
const auditLog = (await guild.fetchAuditLogs({ |
201 |
|
limit: 1, |
202 |
|
type: 'MEMBER_BAN_ADD', |
203 |
|
})).entries.first(); |
204 |
|
|
205 |
|
if (banOptions.reason) { |
206 |
|
r = banOptions.reason; |
207 |
|
} |
208 |
|
else if (auditLog) { |
209 |
|
console.log(auditLog); |
210 |
|
const { target, reason } = await auditLog; |
211 |
|
|
212 |
|
if (target!.id === user.id && reason) { |
213 |
|
r = await reason; |
214 |
|
} |
215 |
|
} |
216 |
|
|
217 |
|
await channel.send({ |
218 |
|
embeds: [ |
219 |
|
new MessageEmbed() |
220 |
|
.setColor('#f14a60') |
221 |
|
.setTitle("A user was temporarily banned") |
222 |
|
.setAuthor({ |
223 |
|
name: user.tag, |
224 |
|
iconURL: user.displayAvatarURL(), |
225 |
|
}) |
226 |
|
.addField('Reason', r) |
227 |
|
.addField('Banned by', model.mod_tag) |
228 |
|
.addField('User ID', user.id) |
229 |
|
.addField('Duration', ms((model.meta as any).time)) |
230 |
|
.setFooter({ |
231 |
|
text: "Temporarily banned", |
232 |
|
}) |
233 |
|
.setTimestamp() |
234 |
|
] |
235 |
|
}); |
236 |
|
}, { |
237 |
|
guild |
238 |
|
}); |
239 |
|
} |
240 |
|
|
241 |
logUnbanned(ban: GuildBan) { |
logUnbanned(ban: GuildBan) { |
242 |
this.channel(async (channel) => { |
this.channel(async (channel) => { |
243 |
await channel.send({ |
await channel.send({ |
333 |
}, member); |
}, member); |
334 |
} |
} |
335 |
|
|
336 |
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) { |
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') |
352 |
.setFooter({ |
.setFooter({ |
353 |
text: "Muted", |
text: "Muted", |
354 |
}) |
}) |