1 |
import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, TextChannel, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
7 |
import getUser from '../../utils/getUser'; |
8 |
import getMember from '../../utils/getMember'; |
9 |
import History from '../../automod/History'; |
10 |
import { fetchEmoji } from '../../utils/Emoji'; |
11 |
|
12 |
export default class HistoryCommand extends BaseCommand { |
13 |
supportsInteractions: boolean = true; |
14 |
|
15 |
constructor() { |
16 |
super('history', 'moderation', []); |
17 |
} |
18 |
|
19 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
20 |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
21 |
await msg.reply({ |
22 |
embeds: [ |
23 |
new MessageEmbed() |
24 |
.setColor('#f14a60') |
25 |
.setDescription(`This command requires at least one argument.`) |
26 |
] |
27 |
}); |
28 |
|
29 |
return; |
30 |
} |
31 |
|
32 |
let user: User | null | undefined; |
33 |
|
34 |
if (options.isInteraction) { |
35 |
user = await <User> options.options.getUser('user'); |
36 |
} |
37 |
else { |
38 |
try { |
39 |
user = await getUser(client, msg as Message, options); |
40 |
|
41 |
if (!user) |
42 |
throw new Error(); |
43 |
} |
44 |
catch (e) { |
45 |
console.log(e); |
46 |
|
47 |
await msg.reply({ |
48 |
embeds: [ |
49 |
new MessageEmbed() |
50 |
.setColor('#f14a60') |
51 |
.setDescription(`Invalid user given.`) |
52 |
] |
53 |
}); |
54 |
|
55 |
return; |
56 |
} |
57 |
} |
58 |
|
59 |
History.get(user.id, msg.guild!, async (data) => { |
60 |
let str = ''; |
61 |
|
62 |
for await (const row of data) { |
63 |
let mod: User | string | undefined; |
64 |
|
65 |
try { |
66 |
mod = await client.users.fetch(row.mod_id); |
67 |
|
68 |
if (!mod) { |
69 |
throw new Error(); |
70 |
} |
71 |
} |
72 |
catch (e) { |
73 |
console.log(e); |
74 |
|
75 |
user = row.user_id; |
76 |
mod = row.mod_id; |
77 |
} |
78 |
|
79 |
str += `\`[${new Date(row.date).toLocaleString()}]\` \`[${typeof mod === 'string' ? mod : mod?.tag}]\` `; |
80 |
|
81 |
let type: string; |
82 |
|
83 |
if (row.type === 'ban') { |
84 |
type = 'Banned'; |
85 |
} |
86 |
else if (row.type === 'unban') { |
87 |
type = 'Unbanned'; |
88 |
} |
89 |
else if (row.type === 'kick') { |
90 |
type = 'Kicked'; |
91 |
} |
92 |
else if (row.type === 'mute') { |
93 |
type = 'Muted'; |
94 |
} |
95 |
else if (row.type === 'unmute') { |
96 |
type = 'Unmuted'; |
97 |
} |
98 |
else if (row.type === 'bean') { |
99 |
type = 'Beaned'; |
100 |
} |
101 |
else if (row.type === 'warn') { |
102 |
type = 'Warned'; |
103 |
} |
104 |
else { |
105 |
type = 'Deleted warning for'; |
106 |
} |
107 |
|
108 |
str += `\`${type}\` \`${typeof user === 'string' ? user : user?.tag}\` \`[Reason: ${row.reason ? row.reason : "No reason provided"}]\`\n`; |
109 |
} |
110 |
|
111 |
await msg.reply({ |
112 |
embeds: [ |
113 |
new MessageEmbed() |
114 |
.setAuthor({ |
115 |
name: user!.tag, |
116 |
iconURL: user?.displayAvatarURL()! |
117 |
}) |
118 |
.setTitle('Moderation history') |
119 |
.setDescription(str == '' ? 'No history' : str) |
120 |
] |
121 |
}); |
122 |
}); |
123 |
} |
124 |
} |