1 |
import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, InteractionCollector, Message, MessageActionRow, MessageButton, MessageOptions, ReplyOptions, TextChannel, User } from 'discord.js'; |
import { BanOptions, CommandInteraction, ContextMenuInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, InteractionCollector, Message, MessageActionRow, MessageButton, MessageOptions, ReplyOptions, TextChannel, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
13 |
|
|
14 |
export default class HistoryCommand extends BaseCommand { |
export default class HistoryCommand extends BaseCommand { |
15 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
16 |
|
supportsContextMenu = true; |
17 |
|
|
18 |
constructor() { |
constructor() { |
19 |
super('history', 'moderation', []); |
super('history', 'moderation', ['Moderation History']); |
20 |
} |
} |
21 |
|
|
22 |
async genEmbed(client: DiscordClient, msg: Message | Interaction, user: User, page: number = 1) { |
async genEmbed(client: DiscordClient, msg: Message | Interaction, user: User, page: number = 1) { |
23 |
const limit = 3; |
const limit = 3; |
24 |
const offset = ((page < 1 ? 1 : page) - 1) * limit; |
const offset = ((page < 1 ? 1 : page) - 1) * limit; |
25 |
|
|
26 |
const logs = await Punishment.findAndCountAll({ |
const logs = await Punishment.find({ |
27 |
where: { |
guild_id: msg.guild!.id, |
28 |
guild_id: msg.guild!.id, |
user_id: user.id, |
29 |
user_id: user.id |
}).skip(offset).limit(limit).sort({ createdAt: -1 }); |
|
}, |
|
|
order: [ |
|
|
['createdAt', 'DESC'] |
|
|
], |
|
|
limit, |
|
|
offset |
|
|
}); |
|
30 |
|
|
31 |
let str = ''; |
let str = ''; |
32 |
const maxPage = Math.ceil(logs.count / limit); |
|
33 |
|
const maxPage = Math.ceil((await Punishment.count({ |
34 |
|
guild_id: msg.guild!.id, |
35 |
|
user_id: user.id, |
36 |
|
})) / limit); |
37 |
|
|
38 |
const convert = (type: PunishmentType) => { |
const convert = (type: PunishmentType) => { |
39 |
switch (type) { |
switch (type) { |
40 |
case PunishmentType.BAN: |
case PunishmentType.BAN: |
41 |
return 'Ban'; |
return 'Ban'; |
42 |
case PunishmentType.BEAN: |
case PunishmentType.SOFTBAN: |
43 |
return 'Bean'; |
return 'Soft Ban'; |
44 |
|
case PunishmentType.TEMPBAN: |
45 |
|
return 'Temporary Ban'; |
46 |
|
case PunishmentType.SHOT: |
47 |
|
return 'Shot'; |
48 |
case PunishmentType.MUTE: |
case PunishmentType.MUTE: |
49 |
return 'Mute'; |
return 'Mute'; |
50 |
|
case PunishmentType.HARDMUTE: |
51 |
|
return 'Hardmute'; |
52 |
case PunishmentType.KICK: |
case PunishmentType.KICK: |
53 |
return 'Kick'; |
return 'Kick'; |
54 |
case PunishmentType.WARNING: |
case PunishmentType.WARNING: |
62 |
} |
} |
63 |
}; |
}; |
64 |
|
|
65 |
for await (const log of logs.rows) { |
for await (const log of logs) { |
66 |
str += `**Case ID**: ${log.get().id}\n`; |
str += `**Case ID**: ${log.id}\n`; |
67 |
str += `Type: ${convert(log.get().type)}\n`; |
str += `Type: ${convert(log.type as PunishmentType)}\n`; |
68 |
str += `Reason: ${log.get().reason ? (log.get().reason.trim() === '' ? '*No reason provided*' : log.get().reason) : '*No reason provided*'}\n`; |
str += `Reason: ${log.reason ? (log.reason.trim() === '' ? '*No reason provided*' : log.reason) : '*No reason provided*'}\n`; |
69 |
|
|
70 |
// let mod_tag; |
// let mod_tag; |
71 |
|
|
81 |
// mod_tag = log.get().mod_id; |
// mod_tag = log.get().mod_id; |
82 |
// } |
// } |
83 |
|
|
84 |
str += `Action Executor: ${log.get().mod_tag}\n`; |
str += `Action Executor: ${log.mod_tag}\n`; |
85 |
str += `Date: ${log.get().createdAt.toLocaleString('en-US')}\n`; |
str += `Date: ${log.createdAt.toLocaleString('en-US')}\n`; |
86 |
|
|
87 |
// if (log.get().type === PunishmentType.MUTE) { |
// if (log.get().type === PunishmentType.MUTE) { |
88 |
// str += `Duration: ${(log.get().meta ? JSON.parse(log.get().meta) : {})?.time ?? '*No duration set*'}\n`; |
// str += `Duration: ${(log.get().meta ? JSON.parse(log.get().meta) : {})?.time ?? '*No duration set*'}\n`; |
89 |
// } |
// } |
90 |
|
|
91 |
if (log.get().meta) { |
if (log.meta) { |
92 |
const json = typeof log.get().meta === 'string' ? JSON.parse(log.get().meta) : log.get().meta; |
const json = typeof log.meta === 'string' ? JSON.parse(log.meta) : log.meta; |
93 |
|
|
94 |
if (Object.keys(json).length > 0) { |
if (Object.keys(json).length > 0) { |
95 |
str += "Additional Attributes:\n```\n"; |
str += "Additional Attributes:\n```\n"; |
257 |
|
|
258 |
collector.on('end', async () => { |
collector.on('end', async () => { |
259 |
try { |
try { |
260 |
await message.edit({ |
if (msg instanceof ContextMenuInteraction) { |
261 |
components: [] |
await msg.editReply({ |
262 |
}); |
components: [] |
263 |
|
}); |
264 |
|
} |
265 |
|
else { |
266 |
|
await message.edit({ |
267 |
|
components: [] |
268 |
|
}); |
269 |
|
} |
270 |
} |
} |
271 |
catch (e) { |
catch (e) { |
272 |
console.log(e); |
console.log(e); |
273 |
} |
} |
274 |
}); |
}); |
275 |
} |
} |
|
} |
|
276 |
|
} |