blob: 0a9d962ab889d38d6522ead3df4dae55325a64a0 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from '../../utils/defaults.js';
pineafan3a02ea32022-08-11 21:35:04 +01002import type { HistorySchema } from "../../utils/database.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01003import Discord, {
4 CommandInteraction,
5 GuildMember,
pineafan3a02ea32022-08-11 21:35:04 +01006 Message,
TheCodedProf21c08592022-09-13 14:14:43 -04007 ActionRowBuilder,
8 ButtonBuilder,
pineafan3a02ea32022-08-11 21:35:04 +01009 MessageComponentInteraction,
10 ModalSubmitInteraction,
PineaFan100df682023-01-02 13:26:08 +000011 ButtonStyle,
PineaFana34d04b2023-01-03 22:05:42 +000012 TextInputStyle,
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050013 APIMessageComponentEmoji,
14 SlashCommandSubcommandBuilder
Skyler Grey75ea9172022-08-06 10:22:23 +010015} from "discord.js";
pineafan4edb7762022-06-26 19:21:04 +010016import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
17import getEmojiByName from "../../utils/getEmojiByName.js";
18import client from "../../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +010019import { modalInteractionCollector } from "../../utils/dualCollector.js";
20import pageIndicator from "../../utils/createPageIndicator.js";
pineafan4edb7762022-06-26 19:21:04 +010021
22const command = (builder: SlashCommandSubcommandBuilder) =>
23 builder
PineaFan1dee28f2023-01-16 22:09:07 +000024 .setName("about")
25 // .setNameLocalizations({"ru": "info", "zh-CN": "history", "zh-TW": "notes", "pt-BR": "flags"})
pineafan63fc5e22022-08-04 22:04:10 +010026 .setDescription("Shows moderator information about a user")
Skyler Grey75ea9172022-08-06 10:22:23 +010027 .addUserOption((option) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010028 option.setName("user").setDescription("The user to get information about").setRequired(true)
Skyler Grey75ea9172022-08-06 10:22:23 +010029 );
pineafan4edb7762022-06-26 19:21:04 +010030
pineafan3a02ea32022-08-11 21:35:04 +010031const types: Record<string, { emoji: string; text: string }> = {
Skyler Grey75ea9172022-08-06 10:22:23 +010032 warn: { emoji: "PUNISH.WARN.YELLOW", text: "Warned" },
33 mute: { emoji: "PUNISH.MUTE.YELLOW", text: "Muted" },
34 unmute: { emoji: "PUNISH.MUTE.GREEN", text: "Unmuted" },
35 join: { emoji: "MEMBER.JOIN", text: "Joined" },
36 leave: { emoji: "MEMBER.LEAVE", text: "Left" },
37 kick: { emoji: "MEMBER.KICK", text: "Kicked" },
38 softban: { emoji: "PUNISH.SOFTBAN", text: "Softbanned" },
39 ban: { emoji: "MEMBER.BAN", text: "Banned" },
40 unban: { emoji: "MEMBER.UNBAN", text: "Unbanned" },
41 purge: { emoji: "PUNISH.CLEARHISTORY", text: "Messages cleared" },
42 nickname: { emoji: "PUNISH.NICKNAME.YELLOW", text: "Nickname changed" }
pineafan63fc5e22022-08-04 22:04:10 +010043};
pineafan4edb7762022-06-26 19:21:04 +010044
45function historyToString(history: HistorySchema) {
pineafan3a02ea32022-08-11 21:35:04 +010046 if (!Object.keys(types).includes(history.type)) throw new Error("Invalid history type");
47 let s = `${getEmojiByName(types[history.type]!.emoji)} ${history.amount ? history.amount + " " : ""}${
48 types[history.type]!.text
Skyler Grey11236ba2022-08-08 21:13:33 +010049 } on <t:${Math.round(history.occurredAt.getTime() / 1000)}:F>`;
Skyler Grey75ea9172022-08-06 10:22:23 +010050 if (history.moderator) {
51 s += ` by <@${history.moderator}>`;
52 }
53 if (history.reason) {
54 s += `\n**Reason:**\n> ${history.reason}`;
55 }
56 if (history.before) {
57 s += `\n**Before:**\n> ${history.before}`;
58 }
59 if (history.after) {
60 s += `\n**After:**\n> ${history.after}`;
61 }
pineafan4edb7762022-06-26 19:21:04 +010062 return s + "\n";
63}
64
pineafan4edb7762022-06-26 19:21:04 +010065class TimelineSection {
pineafan3a02ea32022-08-11 21:35:04 +010066 name: string = "";
Skyler Grey75ea9172022-08-06 10:22:23 +010067 content: { data: HistorySchema; rendered: string }[] = [];
pineafan4edb7762022-06-26 19:21:04 +010068
Skyler Grey75ea9172022-08-06 10:22:23 +010069 addContent = (content: { data: HistorySchema; rendered: string }) => {
70 this.content.push(content);
71 return this;
72 };
73 contentLength = () => {
74 return this.content.reduce((acc, cur) => acc + cur.rendered.length, 0);
75 };
pineafan4edb7762022-06-26 19:21:04 +010076 generateName = () => {
pineafan3a02ea32022-08-11 21:35:04 +010077 const first = Math.round(this.content[0]!.data.occurredAt.getTime() / 1000);
78 const last = Math.round(this.content[this.content.length - 1]!.data.occurredAt.getTime() / 1000);
Skyler Grey75ea9172022-08-06 10:22:23 +010079 if (first === last) {
80 return (this.name = `<t:${first}:F>`);
81 }
82 return (this.name = `<t:${first}:F> - <t:${last}:F>`);
pineafan63fc5e22022-08-04 22:04:10 +010083 };
pineafan4edb7762022-06-26 19:21:04 +010084}
85
Skyler Grey75ea9172022-08-06 10:22:23 +010086const monthNames = [
87 "January",
88 "February",
89 "March",
90 "April",
91 "May",
92 "June",
93 "July",
94 "August",
95 "September",
96 "October",
97 "November",
98 "December"
99];
pineafan4edb7762022-06-26 19:21:04 +0100100
pineafan3a02ea32022-08-11 21:35:04 +0100101async function showHistory(member: Discord.GuildMember, interaction: CommandInteraction) {
pineafan4edb7762022-06-26 19:21:04 +0100102 let currentYear = new Date().getFullYear();
pineafan3a02ea32022-08-11 21:35:04 +0100103 let pageIndex: number | null = null;
104 let history, current: TimelineSection;
PineaFan100df682023-01-02 13:26:08 +0000105 history = await client.database.history.read(member.guild.id, member.id, currentYear);
106 history = history
107 .sort(
108 (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
109 b.occurredAt.getTime() - a.occurredAt.getTime()
110 )
111 .reverse();
pineafan3a02ea32022-08-11 21:35:04 +0100112 let m: Message;
PineaFan100df682023-01-02 13:26:08 +0000113 let refresh = false;
pineafan3a02ea32022-08-11 21:35:04 +0100114 let filteredTypes: string[] = [];
pineafan4edb7762022-06-26 19:21:04 +0100115 let openFilterPane = false;
Skyler Greyad002172022-08-16 18:48:26 +0100116 let timedOut = false;
117 let showHistorySelected = false;
118 while (!timedOut && !showHistorySelected) {
pineafan4edb7762022-06-26 19:21:04 +0100119 if (refresh) {
Skyler Grey11236ba2022-08-08 21:13:33 +0100120 history = await client.database.history.read(member.guild.id, member.id, currentYear);
pineafan3a02ea32022-08-11 21:35:04 +0100121 history = history
122 .sort(
123 (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
124 b.occurredAt.getTime() - a.occurredAt.getTime()
125 )
126 .reverse();
pineafan4edb7762022-06-26 19:21:04 +0100127 if (openFilterPane) {
pineafan63fc5e22022-08-04 22:04:10 +0100128 let tempFilteredTypes = filteredTypes;
Skyler Grey75ea9172022-08-06 10:22:23 +0100129 if (filteredTypes.length === 0) {
130 tempFilteredTypes = Object.keys(types);
131 }
pineafan3a02ea32022-08-11 21:35:04 +0100132 history = history.filter((h: { type: string }) => tempFilteredTypes.includes(h.type));
pineafan63fc5e22022-08-04 22:04:10 +0100133 }
pineafan4edb7762022-06-26 19:21:04 +0100134 refresh = false;
135 }
pineafan63fc5e22022-08-04 22:04:10 +0100136 const groups: TimelineSection[] = [];
pineafan4edb7762022-06-26 19:21:04 +0100137 if (history.length > 0) {
pineafan63fc5e22022-08-04 22:04:10 +0100138 current = new TimelineSection();
pineafan3a02ea32022-08-11 21:35:04 +0100139 history.forEach((event: HistorySchema) => {
Skyler Grey11236ba2022-08-08 21:13:33 +0100140 if (current.contentLength() + historyToString(event).length > 2000 || current.content.length === 5) {
pineafan4edb7762022-06-26 19:21:04 +0100141 groups.push(current);
142 current.generateName();
143 current = new TimelineSection();
144 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100145 current.addContent({
146 data: event,
147 rendered: historyToString(event)
148 });
pineafan4edb7762022-06-26 19:21:04 +0100149 });
150 current.generateName();
151 groups.push(current);
Skyler Grey75ea9172022-08-06 10:22:23 +0100152 if (pageIndex === null) {
153 pageIndex = groups.length - 1;
154 }
pineafan4edb7762022-06-26 19:21:04 +0100155 }
pineafan3a02ea32022-08-11 21:35:04 +0100156 if (pageIndex === null) pageIndex = 0;
PineaFana34d04b2023-01-03 22:05:42 +0000157 let components: (ActionRowBuilder<Discord.StringSelectMenuBuilder> | ActionRowBuilder<ButtonBuilder>)[] = []
158 if (openFilterPane) components = components.concat([
159 new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents(
PineaFan5bea7e12023-01-05 21:20:04 +0000160 new Discord.StringSelectMenuBuilder()
161 .setMinValues(1)
162 .setMaxValues(Object.keys(types).length)
163 .setCustomId("filter")
164 .setPlaceholder("Select events to show")
165 .setOptions(...Object.entries(types).map(([key, value]) => new Discord.StringSelectMenuOptionBuilder()
166 .setLabel(value.text)
167 .setValue(key)
168 .setDefault(filteredTypes.includes(key))
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500169 .setEmoji(getEmojiByName(value.emoji, "id") as APIMessageComponentEmoji)
PineaFan5bea7e12023-01-05 21:20:04 +0000170 )))
171 ]);
PineaFana34d04b2023-01-03 22:05:42 +0000172 components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
173 new ButtonBuilder()
174 .setCustomId("prevYear")
175 .setLabel((currentYear - 1).toString())
176 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
177 .setStyle(ButtonStyle.Secondary),
178 new ButtonBuilder()
179 .setCustomId("prevPage")
180 .setLabel("Previous page")
181 .setStyle(ButtonStyle.Primary),
PineaFan5bea7e12023-01-05 21:20:04 +0000182 new ButtonBuilder()
183 .setCustomId("today")
184 .setLabel("Today")
185 .setStyle(ButtonStyle.Primary),
PineaFana34d04b2023-01-03 22:05:42 +0000186 new ButtonBuilder()
187 .setCustomId("nextPage")
188 .setLabel("Next page")
189 .setStyle(ButtonStyle.Primary)
190 .setDisabled(pageIndex >= groups.length - 1 && currentYear === new Date().getFullYear()),
191 new ButtonBuilder()
192 .setCustomId("nextYear")
193 .setLabel((currentYear + 1).toString())
194 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
195 .setStyle(ButtonStyle.Secondary)
196 .setDisabled(currentYear === new Date().getFullYear())
197 ])])
198 components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
199 new ButtonBuilder()
200 .setLabel("Mod notes")
201 .setCustomId("modNotes")
202 .setStyle(ButtonStyle.Primary)
203 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
204 new ButtonBuilder()
205 .setLabel("Filter")
206 .setCustomId("openFilter")
207 .setStyle(openFilterPane ? ButtonStyle.Success : ButtonStyle.Primary)
208 .setEmoji(getEmojiByName("ICONS.FILTER", "id"))
209 ])])
210
Skyler Grey75ea9172022-08-06 10:22:23 +0100211 const end =
212 "\n\nJanuary " +
213 currentYear.toString() +
Skyler Grey11236ba2022-08-08 21:13:33 +0100214 pageIndicator(Math.max(groups.length, 1), groups.length === 0 ? 1 : pageIndex) +
215 (currentYear === new Date().getFullYear() ? monthNames[new Date().getMonth()] : "December") +
Skyler Grey75ea9172022-08-06 10:22:23 +0100216 " " +
217 currentYear.toString();
pineafan4edb7762022-06-26 19:21:04 +0100218 if (groups.length > 0) {
pineafan3a02ea32022-08-11 21:35:04 +0100219 const toRender = groups[Math.min(pageIndex, groups.length - 1)]!;
PineaFana34d04b2023-01-03 22:05:42 +0000220 m = await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100221 embeds: [
222 new EmojiEmbed()
223 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100224 .setTitle("Moderation history for " + member.user.username)
Skyler Grey75ea9172022-08-06 10:22:23 +0100225 .setDescription(
Skyler Grey11236ba2022-08-08 21:13:33 +0100226 `**${toRender.name}**\n\n` + toRender.content.map((c) => c.rendered).join("\n") + end
Skyler Grey75ea9172022-08-06 10:22:23 +0100227 )
228 .setStatus("Success")
229 .setFooter({
PineaFana34d04b2023-01-03 22:05:42 +0000230 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
Skyler Grey75ea9172022-08-06 10:22:23 +0100231 })
232 ],
233 components: components
PineaFana34d04b2023-01-03 22:05:42 +0000234 });
pineafan4edb7762022-06-26 19:21:04 +0100235 } else {
PineaFana34d04b2023-01-03 22:05:42 +0000236 m = await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100237 embeds: [
238 new EmojiEmbed()
239 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100240 .setTitle("Moderation history for " + member.user.username)
PineaFana34d04b2023-01-03 22:05:42 +0000241 .setDescription(`**${currentYear}**\n\n*No events*`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100242 .setStatus("Success")
243 .setFooter({
PineaFana34d04b2023-01-03 22:05:42 +0000244 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
Skyler Grey75ea9172022-08-06 10:22:23 +0100245 })
246 ],
247 components: components
PineaFana34d04b2023-01-03 22:05:42 +0000248 })
pineafan4edb7762022-06-26 19:21:04 +0100249 }
pineafan3a02ea32022-08-11 21:35:04 +0100250 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100251 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000252 i = await m.awaitMessageComponent({
253 time: 300000,
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500254 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id }
PineaFan0d06edc2023-01-17 22:10:31 +0000255 });
pineafan4edb7762022-06-26 19:21:04 +0100256 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100257 interaction.editReply({
258 embeds: [
259 new EmojiEmbed()
260 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100261 .setTitle("Moderation history for " + member.user.username)
pineafan3a02ea32022-08-11 21:35:04 +0100262 .setDescription(m.embeds[0]!.description!)
Skyler Grey75ea9172022-08-06 10:22:23 +0100263 .setStatus("Danger")
264 .setFooter({ text: "Message timed out" })
265 ]
266 });
Skyler Greyad002172022-08-16 18:48:26 +0100267 timedOut = true;
268 continue;
pineafan4edb7762022-06-26 19:21:04 +0100269 }
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500270 await i.deferUpdate();
271 if (i.customId === "filter" && i.isStringSelectMenu()) {
272 filteredTypes = i.values;
pineafan4edb7762022-06-26 19:21:04 +0100273 pageIndex = null;
274 refresh = true;
275 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100276 if (i.customId === "prevYear") {
277 currentYear--;
278 pageIndex = null;
279 refresh = true;
280 }
281 if (i.customId === "nextYear") {
282 currentYear++;
283 pageIndex = null;
284 refresh = true;
285 }
pineafan4edb7762022-06-26 19:21:04 +0100286 if (i.customId === "prevPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100287 pageIndex!--;
288 if (pageIndex! < 0) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100289 pageIndex = null;
290 currentYear--;
291 refresh = true;
292 }
pineafan4edb7762022-06-26 19:21:04 +0100293 }
294 if (i.customId === "nextPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100295 pageIndex!++;
296 if (pageIndex! >= groups.length) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100297 pageIndex = 0;
298 currentYear++;
299 refresh = true;
300 }
pineafan4edb7762022-06-26 19:21:04 +0100301 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100302 if (i.customId === "today") {
303 currentYear = new Date().getFullYear();
304 pageIndex = null;
305 refresh = true;
306 }
307 if (i.customId === "modNotes") {
Skyler Greyad002172022-08-16 18:48:26 +0100308 showHistorySelected = true;
Skyler Grey75ea9172022-08-06 10:22:23 +0100309 }
310 if (i.customId === "openFilter") {
311 openFilterPane = !openFilterPane;
312 refresh = true;
313 }
pineafan4edb7762022-06-26 19:21:04 +0100314 }
Skyler Greyad002172022-08-16 18:48:26 +0100315 return timedOut ? 0 : 1;
pineafan4edb7762022-06-26 19:21:04 +0100316}
317
pineafan3a02ea32022-08-11 21:35:04 +0100318const callback = async (interaction: CommandInteraction): Promise<unknown> => {
319 let m: Message;
Skyler Grey75ea9172022-08-06 10:22:23 +0100320 const member = interaction.options.getMember("user") as Discord.GuildMember;
321 await interaction.reply({
PineaFana34d04b2023-01-03 22:05:42 +0000322 embeds: LoadingEmbed,
Skyler Grey75ea9172022-08-06 10:22:23 +0100323 ephemeral: true,
324 fetchReply: true
325 });
pineafan4edb7762022-06-26 19:21:04 +0100326 let note;
327 let firstLoad = true;
Skyler Greyad002172022-08-16 18:48:26 +0100328 let timedOut = false;
329 while (!timedOut) {
pineafan4edb7762022-06-26 19:21:04 +0100330 note = await client.database.notes.read(member.guild.id, member.id);
PineaFana34d04b2023-01-03 22:05:42 +0000331 if (firstLoad && !note) { await showHistory(member, interaction); }
pineafan4edb7762022-06-26 19:21:04 +0100332 firstLoad = false;
pineafan3a02ea32022-08-11 21:35:04 +0100333 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100334 embeds: [
335 new EmojiEmbed()
336 .setEmoji("MEMBER.JOIN")
337 .setTitle("Mod notes for " + member.user.username)
338 .setDescription(note ? note : "*No note set*")
339 .setStatus("Success")
340 ],
341 components: [
PineaFan100df682023-01-02 13:26:08 +0000342 new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400343 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100344 .setLabel(`${note ? "Modify" : "Create"} note`)
TheCodedProf21c08592022-09-13 14:14:43 -0400345 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100346 .setCustomId("modify")
347 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
TheCodedProf21c08592022-09-13 14:14:43 -0400348 new ButtonBuilder()
PineaFana34d04b2023-01-03 22:05:42 +0000349 .setLabel("Moderation history")
TheCodedProf21c08592022-09-13 14:14:43 -0400350 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100351 .setCustomId("history")
352 .setEmoji(getEmojiByName("ICONS.HISTORY", "id"))
353 ])
354 ]
pineafan3a02ea32022-08-11 21:35:04 +0100355 })) as Message;
356 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100357 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000358 i = await m.awaitMessageComponent({
359 time: 300000,
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500360 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id }
PineaFan0d06edc2023-01-17 22:10:31 +0000361 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100362 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100363 timedOut = true;
364 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100365 }
pineafan4edb7762022-06-26 19:21:04 +0100366 if (i.customId === "modify") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100367 await i.showModal(
PineaFan100df682023-01-02 13:26:08 +0000368 new Discord.ModalBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100369 .setCustomId("modal")
370 .setTitle("Editing moderator note")
371 .addComponents(
PineaFana34d04b2023-01-03 22:05:42 +0000372 new ActionRowBuilder<Discord.TextInputBuilder>().addComponents(
373 new Discord.TextInputBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100374 .setCustomId("note")
375 .setLabel("Note")
376 .setMaxLength(4000)
377 .setRequired(false)
PineaFana34d04b2023-01-03 22:05:42 +0000378 .setStyle(TextInputStyle.Paragraph)
379 .setValue(note ? note : " ")
Skyler Grey75ea9172022-08-06 10:22:23 +0100380 )
381 )
382 );
pineafan4edb7762022-06-26 19:21:04 +0100383 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100384 embeds: [
385 new EmojiEmbed()
386 .setTitle("Mod notes for " + member.user.username)
Skyler Grey11236ba2022-08-08 21:13:33 +0100387 .setDescription("Modal opened. If you can't see it, click back and try again.")
Skyler Grey75ea9172022-08-06 10:22:23 +0100388 .setStatus("Success")
389 .setEmoji("GUILD.TICKET.OPEN")
390 ],
391 components: [
PineaFan100df682023-01-02 13:26:08 +0000392 new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400393 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100394 .setLabel("Back")
395 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400396 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100397 .setCustomId("back")
398 ])
399 ]
pineafan4edb7762022-06-26 19:21:04 +0100400 });
401 let out;
402 try {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500403 out = await modalInteractionCollector(m, interaction.user);
Skyler Grey75ea9172022-08-06 10:22:23 +0100404 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100405 timedOut = true;
406 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100407 }
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500408 if (out === null || out.isButton()) {
pineafan3a02ea32022-08-11 21:35:04 +0100409 continue;
410 } else if (out instanceof ModalSubmitInteraction) {
PineaFana34d04b2023-01-03 22:05:42 +0000411 let toAdd = out.fields.getTextInputValue("note") || null;
412 if (toAdd === " ") toAdd = null;
413 if (toAdd) toAdd = toAdd.trim();
Skyler Grey11236ba2022-08-08 21:13:33 +0100414 await client.database.notes.create(member.guild.id, member.id, toAdd);
Skyler Grey75ea9172022-08-06 10:22:23 +0100415 } else {
416 continue;
417 }
pineafan4edb7762022-06-26 19:21:04 +0100418 } else if (i.customId === "history") {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500419 await i.deferUpdate();
Skyler Grey75ea9172022-08-06 10:22:23 +0100420 if (!(await showHistory(member, interaction))) return;
pineafan4edb7762022-06-26 19:21:04 +0100421 }
422 }
pineafan63fc5e22022-08-04 22:04:10 +0100423};
pineafan4edb7762022-06-26 19:21:04 +0100424
pineafanbd02b4a2022-08-05 22:01:38 +0100425const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100426 const member = interaction.member as GuildMember;
PineaFan100df682023-01-02 13:26:08 +0000427 if (!member.permissions.has("ModerateMembers"))
PineaFan0d06edc2023-01-17 22:10:31 +0000428 return "You do not have the *Moderate Members* permission";
pineafan63fc5e22022-08-04 22:04:10 +0100429 return true;
430};
pineafan4edb7762022-06-26 19:21:04 +0100431
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500432export { command, callback, check };
433export const metadata = {
434 longDescription: "Shows the moderation history (all previous bans, kicks, warns etc.), and moderator notes for a user.",
435 premiumOnly: true,
436}