blob: bed0f8622cdd9e3f4e64c6073e88d2a74cf8048d [file] [log] [blame]
pineafan3a02ea32022-08-11 21:35:04 +01001import type { HistorySchema } from "../../utils/database.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01002import Discord, {
3 CommandInteraction,
4 GuildMember,
pineafan3a02ea32022-08-11 21:35:04 +01005 Interaction,
6 Message,
TheCodedProf21c08592022-09-13 14:14:43 -04007 ActionRowBuilder,
8 ButtonBuilder,
pineafan3a02ea32022-08-11 21:35:04 +01009 MessageComponentInteraction,
10 ModalSubmitInteraction,
pineafan62ce1922022-08-25 20:34:45 +010011 SelectMenuInteraction,
TheCodedProf21c08592022-09-13 14:14:43 -040012 TextInputComponent,
13 ButtonStyle
Skyler Grey75ea9172022-08-06 10:22:23 +010014} from "discord.js";
pineafan3a02ea32022-08-11 21:35:04 +010015import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
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
pineafan63fc5e22022-08-04 22:04:10 +010024 .setName("info")
25 .setDescription("Shows moderator information about a user")
Skyler Grey75ea9172022-08-06 10:22:23 +010026 .addUserOption((option) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010027 option.setName("user").setDescription("The user to get information about").setRequired(true)
Skyler Grey75ea9172022-08-06 10:22:23 +010028 );
pineafan4edb7762022-06-26 19:21:04 +010029
pineafan3a02ea32022-08-11 21:35:04 +010030const types: Record<string, { emoji: string; text: string }> = {
Skyler Grey75ea9172022-08-06 10:22:23 +010031 warn: { emoji: "PUNISH.WARN.YELLOW", text: "Warned" },
32 mute: { emoji: "PUNISH.MUTE.YELLOW", text: "Muted" },
33 unmute: { emoji: "PUNISH.MUTE.GREEN", text: "Unmuted" },
34 join: { emoji: "MEMBER.JOIN", text: "Joined" },
35 leave: { emoji: "MEMBER.LEAVE", text: "Left" },
36 kick: { emoji: "MEMBER.KICK", text: "Kicked" },
37 softban: { emoji: "PUNISH.SOFTBAN", text: "Softbanned" },
38 ban: { emoji: "MEMBER.BAN", text: "Banned" },
39 unban: { emoji: "MEMBER.UNBAN", text: "Unbanned" },
40 purge: { emoji: "PUNISH.CLEARHISTORY", text: "Messages cleared" },
41 nickname: { emoji: "PUNISH.NICKNAME.YELLOW", text: "Nickname changed" }
pineafan63fc5e22022-08-04 22:04:10 +010042};
pineafan4edb7762022-06-26 19:21:04 +010043
44function historyToString(history: HistorySchema) {
pineafan3a02ea32022-08-11 21:35:04 +010045 if (!Object.keys(types).includes(history.type)) throw new Error("Invalid history type");
46 let s = `${getEmojiByName(types[history.type]!.emoji)} ${history.amount ? history.amount + " " : ""}${
47 types[history.type]!.text
Skyler Grey11236ba2022-08-08 21:13:33 +010048 } on <t:${Math.round(history.occurredAt.getTime() / 1000)}:F>`;
Skyler Grey75ea9172022-08-06 10:22:23 +010049 if (history.moderator) {
50 s += ` by <@${history.moderator}>`;
51 }
52 if (history.reason) {
53 s += `\n**Reason:**\n> ${history.reason}`;
54 }
55 if (history.before) {
56 s += `\n**Before:**\n> ${history.before}`;
57 }
58 if (history.after) {
59 s += `\n**After:**\n> ${history.after}`;
60 }
pineafan4edb7762022-06-26 19:21:04 +010061 return s + "\n";
62}
63
pineafan4edb7762022-06-26 19:21:04 +010064class TimelineSection {
pineafan3a02ea32022-08-11 21:35:04 +010065 name: string = "";
Skyler Grey75ea9172022-08-06 10:22:23 +010066 content: { data: HistorySchema; rendered: string }[] = [];
pineafan4edb7762022-06-26 19:21:04 +010067
Skyler Grey75ea9172022-08-06 10:22:23 +010068 addContent = (content: { data: HistorySchema; rendered: string }) => {
69 this.content.push(content);
70 return this;
71 };
72 contentLength = () => {
73 return this.content.reduce((acc, cur) => acc + cur.rendered.length, 0);
74 };
pineafan4edb7762022-06-26 19:21:04 +010075 generateName = () => {
pineafan3a02ea32022-08-11 21:35:04 +010076 const first = Math.round(this.content[0]!.data.occurredAt.getTime() / 1000);
77 const last = Math.round(this.content[this.content.length - 1]!.data.occurredAt.getTime() / 1000);
Skyler Grey75ea9172022-08-06 10:22:23 +010078 if (first === last) {
79 return (this.name = `<t:${first}:F>`);
80 }
81 return (this.name = `<t:${first}:F> - <t:${last}:F>`);
pineafan63fc5e22022-08-04 22:04:10 +010082 };
pineafan4edb7762022-06-26 19:21:04 +010083}
84
Skyler Grey75ea9172022-08-06 10:22:23 +010085const monthNames = [
86 "January",
87 "February",
88 "March",
89 "April",
90 "May",
91 "June",
92 "July",
93 "August",
94 "September",
95 "October",
96 "November",
97 "December"
98];
pineafan4edb7762022-06-26 19:21:04 +010099
pineafan3a02ea32022-08-11 21:35:04 +0100100async function showHistory(member: Discord.GuildMember, interaction: CommandInteraction) {
pineafan4edb7762022-06-26 19:21:04 +0100101 let currentYear = new Date().getFullYear();
pineafan3a02ea32022-08-11 21:35:04 +0100102 let pageIndex: number | null = null;
103 let history, current: TimelineSection;
104 let m: Message;
pineafan4edb7762022-06-26 19:21:04 +0100105 let refresh = true;
pineafan3a02ea32022-08-11 21:35:04 +0100106 let filteredTypes: string[] = [];
pineafan4edb7762022-06-26 19:21:04 +0100107 let openFilterPane = false;
Skyler Greyad002172022-08-16 18:48:26 +0100108 let timedOut = false;
109 let showHistorySelected = false;
110 while (!timedOut && !showHistorySelected) {
pineafan4edb7762022-06-26 19:21:04 +0100111 if (refresh) {
Skyler Grey11236ba2022-08-08 21:13:33 +0100112 history = await client.database.history.read(member.guild.id, member.id, currentYear);
pineafan3a02ea32022-08-11 21:35:04 +0100113 history = history
114 .sort(
115 (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
116 b.occurredAt.getTime() - a.occurredAt.getTime()
117 )
118 .reverse();
pineafan4edb7762022-06-26 19:21:04 +0100119 if (openFilterPane) {
pineafan63fc5e22022-08-04 22:04:10 +0100120 let tempFilteredTypes = filteredTypes;
Skyler Grey75ea9172022-08-06 10:22:23 +0100121 if (filteredTypes.length === 0) {
122 tempFilteredTypes = Object.keys(types);
123 }
pineafan3a02ea32022-08-11 21:35:04 +0100124 history = history.filter((h: { type: string }) => tempFilteredTypes.includes(h.type));
pineafan63fc5e22022-08-04 22:04:10 +0100125 }
pineafan4edb7762022-06-26 19:21:04 +0100126 refresh = false;
127 }
pineafan63fc5e22022-08-04 22:04:10 +0100128 const groups: TimelineSection[] = [];
pineafan4edb7762022-06-26 19:21:04 +0100129 if (history.length > 0) {
pineafan63fc5e22022-08-04 22:04:10 +0100130 current = new TimelineSection();
pineafan3a02ea32022-08-11 21:35:04 +0100131 history.forEach((event: HistorySchema) => {
Skyler Grey11236ba2022-08-08 21:13:33 +0100132 if (current.contentLength() + historyToString(event).length > 2000 || current.content.length === 5) {
pineafan4edb7762022-06-26 19:21:04 +0100133 groups.push(current);
134 current.generateName();
135 current = new TimelineSection();
136 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 current.addContent({
138 data: event,
139 rendered: historyToString(event)
140 });
pineafan4edb7762022-06-26 19:21:04 +0100141 });
142 current.generateName();
143 groups.push(current);
Skyler Grey75ea9172022-08-06 10:22:23 +0100144 if (pageIndex === null) {
145 pageIndex = groups.length - 1;
146 }
pineafan4edb7762022-06-26 19:21:04 +0100147 }
pineafan3a02ea32022-08-11 21:35:04 +0100148 if (pageIndex === null) pageIndex = 0;
pineafan63fc5e22022-08-04 22:04:10 +0100149 const components = (
Skyler Grey75ea9172022-08-06 10:22:23 +0100150 openFilterPane
151 ? [
TheCodedProf21c08592022-09-13 14:14:43 -0400152 new ActionRowBuilder().addComponents([
153 new Discord.SelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100154 .setOptions(
155 Object.entries(types).map(([key, value]) => ({
156 label: value.text,
157 value: key,
158 default: filteredTypes.includes(key),
Skyler Grey11236ba2022-08-08 21:13:33 +0100159 emoji: client.emojis.resolve(getEmojiByName(value.emoji, "id"))
Skyler Grey75ea9172022-08-06 10:22:23 +0100160 }))
161 )
162 .setMinValues(1)
163 .setMaxValues(Object.keys(types).length)
164 .setCustomId("filter")
165 .setPlaceholder("Select at least one event")
166 ])
167 ]
168 : []
169 ).concat([
TheCodedProf21c08592022-09-13 14:14:43 -0400170 new ActionRowBuilder().addComponents([
171 new ButtonBuilder()
pineafan4edb7762022-06-26 19:21:04 +0100172 .setCustomId("prevYear")
173 .setLabel((currentYear - 1).toString())
174 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400175 .setStyle(ButtonStyle.Secondary),
176 new ButtonBuilder().setCustomId("prevPage").setLabel("Previous page").setStyle(ButtonStyle.Primary),
177 new ButtonBuilder().setCustomId("today").setLabel("Today").setStyle(ButtonStyle.Primary),
178 new ButtonBuilder()
pineafan4edb7762022-06-26 19:21:04 +0100179 .setCustomId("nextPage")
180 .setLabel("Next page")
TheCodedProf21c08592022-09-13 14:14:43 -0400181 .setStyle(ButtonStyle.Primary)
Skyler Grey11236ba2022-08-08 21:13:33 +0100182 .setDisabled(pageIndex >= groups.length - 1 && currentYear === new Date().getFullYear()),
TheCodedProf21c08592022-09-13 14:14:43 -0400183 new ButtonBuilder()
pineafan4edb7762022-06-26 19:21:04 +0100184 .setCustomId("nextYear")
185 .setLabel((currentYear + 1).toString())
186 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400187 .setStyle(ButtonStyle.Secondary)
pineafan63fc5e22022-08-04 22:04:10 +0100188 .setDisabled(currentYear === new Date().getFullYear())
Skyler Grey75ea9172022-08-06 10:22:23 +0100189 ]),
TheCodedProf21c08592022-09-13 14:14:43 -0400190 new ActionRowBuilder().addComponents([
191 new ButtonBuilder()
pineafan4edb7762022-06-26 19:21:04 +0100192 .setLabel("Mod notes")
193 .setCustomId("modNotes")
TheCodedProf21c08592022-09-13 14:14:43 -0400194 .setStyle(ButtonStyle.Primary)
pineafan4edb7762022-06-26 19:21:04 +0100195 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
TheCodedProf21c08592022-09-13 14:14:43 -0400196 new ButtonBuilder()
pineafan4edb7762022-06-26 19:21:04 +0100197 .setLabel("Filter")
198 .setCustomId("openFilter")
TheCodedProf21c08592022-09-13 14:14:43 -0400199 .setStyle(openFilterPane ? ButtonStyle.Success : ButtonStyle.Primary)
pineafan4edb7762022-06-26 19:21:04 +0100200 .setEmoji(getEmojiByName("ICONS.FILTER", "id"))
201 ])
pineafan63fc5e22022-08-04 22:04:10 +0100202 ]);
Skyler Grey75ea9172022-08-06 10:22:23 +0100203 const end =
204 "\n\nJanuary " +
205 currentYear.toString() +
Skyler Grey11236ba2022-08-08 21:13:33 +0100206 pageIndicator(Math.max(groups.length, 1), groups.length === 0 ? 1 : pageIndex) +
207 (currentYear === new Date().getFullYear() ? monthNames[new Date().getMonth()] : "December") +
Skyler Grey75ea9172022-08-06 10:22:23 +0100208 " " +
209 currentYear.toString();
pineafan4edb7762022-06-26 19:21:04 +0100210 if (groups.length > 0) {
pineafan3a02ea32022-08-11 21:35:04 +0100211 const toRender = groups[Math.min(pageIndex, groups.length - 1)]!;
212 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100213 embeds: [
214 new EmojiEmbed()
215 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100216 .setTitle("Moderation history for " + member.user.username)
Skyler Grey75ea9172022-08-06 10:22:23 +0100217 .setDescription(
Skyler Grey11236ba2022-08-08 21:13:33 +0100218 `**${toRender.name}**\n\n` + toRender.content.map((c) => c.rendered).join("\n") + end
Skyler Grey75ea9172022-08-06 10:22:23 +0100219 )
220 .setStatus("Success")
221 .setFooter({
Skyler Grey11236ba2022-08-08 21:13:33 +0100222 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : ""
Skyler Grey75ea9172022-08-06 10:22:23 +0100223 })
224 ],
225 components: components
pineafan3a02ea32022-08-11 21:35:04 +0100226 })) as Message;
pineafan4edb7762022-06-26 19:21:04 +0100227 } else {
pineafan3a02ea32022-08-11 21:35:04 +0100228 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100229 embeds: [
230 new EmojiEmbed()
231 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100232 .setTitle("Moderation history for " + member.user.username)
233 .setDescription(`**${currentYear}**\n\n*No events*` + "\n\n" + end)
Skyler Grey75ea9172022-08-06 10:22:23 +0100234 .setStatus("Success")
235 .setFooter({
Skyler Grey11236ba2022-08-08 21:13:33 +0100236 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : ""
Skyler Grey75ea9172022-08-06 10:22:23 +0100237 })
238 ],
239 components: components
pineafan3a02ea32022-08-11 21:35:04 +0100240 })) as Message;
pineafan4edb7762022-06-26 19:21:04 +0100241 }
pineafan3a02ea32022-08-11 21:35:04 +0100242 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100243 try {
244 i = await m.awaitMessageComponent({ time: 300000 });
245 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100246 interaction.editReply({
247 embeds: [
248 new EmojiEmbed()
249 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100250 .setTitle("Moderation history for " + member.user.username)
pineafan3a02ea32022-08-11 21:35:04 +0100251 .setDescription(m.embeds[0]!.description!)
Skyler Grey75ea9172022-08-06 10:22:23 +0100252 .setStatus("Danger")
253 .setFooter({ text: "Message timed out" })
254 ]
255 });
Skyler Greyad002172022-08-16 18:48:26 +0100256 timedOut = true;
257 continue;
pineafan4edb7762022-06-26 19:21:04 +0100258 }
pineafan63fc5e22022-08-04 22:04:10 +0100259 i.deferUpdate();
pineafan4edb7762022-06-26 19:21:04 +0100260 if (i.customId === "filter") {
pineafan62ce1922022-08-25 20:34:45 +0100261 filteredTypes = (i as SelectMenuInteraction).values;
pineafan4edb7762022-06-26 19:21:04 +0100262 pageIndex = null;
263 refresh = true;
264 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100265 if (i.customId === "prevYear") {
266 currentYear--;
267 pageIndex = null;
268 refresh = true;
269 }
270 if (i.customId === "nextYear") {
271 currentYear++;
272 pageIndex = null;
273 refresh = true;
274 }
pineafan4edb7762022-06-26 19:21:04 +0100275 if (i.customId === "prevPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100276 pageIndex!--;
277 if (pageIndex! < 0) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100278 pageIndex = null;
279 currentYear--;
280 refresh = true;
281 }
pineafan4edb7762022-06-26 19:21:04 +0100282 }
283 if (i.customId === "nextPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100284 pageIndex!++;
285 if (pageIndex! >= groups.length) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100286 pageIndex = 0;
287 currentYear++;
288 refresh = true;
289 }
pineafan4edb7762022-06-26 19:21:04 +0100290 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100291 if (i.customId === "today") {
292 currentYear = new Date().getFullYear();
293 pageIndex = null;
294 refresh = true;
295 }
296 if (i.customId === "modNotes") {
Skyler Greyad002172022-08-16 18:48:26 +0100297 showHistorySelected = true;
Skyler Grey75ea9172022-08-06 10:22:23 +0100298 }
299 if (i.customId === "openFilter") {
300 openFilterPane = !openFilterPane;
301 refresh = true;
302 }
pineafan4edb7762022-06-26 19:21:04 +0100303 }
Skyler Greyad002172022-08-16 18:48:26 +0100304 return timedOut ? 0 : 1;
pineafan4edb7762022-06-26 19:21:04 +0100305}
306
pineafan3a02ea32022-08-11 21:35:04 +0100307const callback = async (interaction: CommandInteraction): Promise<unknown> => {
308 let m: Message;
Skyler Grey75ea9172022-08-06 10:22:23 +0100309 const member = interaction.options.getMember("user") as Discord.GuildMember;
310 await interaction.reply({
Skyler Grey11236ba2022-08-08 21:13:33 +0100311 embeds: [new EmojiEmbed().setEmoji("NUCLEUS.LOADING").setTitle("Downloading Data").setStatus("Danger")],
Skyler Grey75ea9172022-08-06 10:22:23 +0100312 ephemeral: true,
313 fetchReply: true
314 });
pineafan4edb7762022-06-26 19:21:04 +0100315 let note;
316 let firstLoad = true;
Skyler Greyad002172022-08-16 18:48:26 +0100317 let timedOut = false;
318 while (!timedOut) {
pineafan4edb7762022-06-26 19:21:04 +0100319 note = await client.database.notes.read(member.guild.id, member.id);
Skyler Grey75ea9172022-08-06 10:22:23 +0100320 if (firstLoad && !note) {
321 await showHistory(member, interaction);
322 }
pineafan4edb7762022-06-26 19:21:04 +0100323 firstLoad = false;
pineafan3a02ea32022-08-11 21:35:04 +0100324 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100325 embeds: [
326 new EmojiEmbed()
327 .setEmoji("MEMBER.JOIN")
328 .setTitle("Mod notes for " + member.user.username)
329 .setDescription(note ? note : "*No note set*")
330 .setStatus("Success")
331 ],
332 components: [
TheCodedProf21c08592022-09-13 14:14:43 -0400333 new ActionRowBuilder().addComponents([
334 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100335 .setLabel(`${note ? "Modify" : "Create"} note`)
TheCodedProf21c08592022-09-13 14:14:43 -0400336 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100337 .setCustomId("modify")
338 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
TheCodedProf21c08592022-09-13 14:14:43 -0400339 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100340 .setLabel("View moderation history")
TheCodedProf21c08592022-09-13 14:14:43 -0400341 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100342 .setCustomId("history")
343 .setEmoji(getEmojiByName("ICONS.HISTORY", "id"))
344 ])
345 ]
pineafan3a02ea32022-08-11 21:35:04 +0100346 })) as Message;
347 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100348 try {
349 i = await m.awaitMessageComponent({ time: 300000 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100350 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100351 timedOut = true;
352 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100353 }
pineafan4edb7762022-06-26 19:21:04 +0100354 if (i.customId === "modify") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100355 await i.showModal(
356 new Discord.Modal()
357 .setCustomId("modal")
358 .setTitle("Editing moderator note")
359 .addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400360 new ActionRowBuilder<TextInputComponent>().addComponents(
Skyler Grey75ea9172022-08-06 10:22:23 +0100361 new TextInputComponent()
362 .setCustomId("note")
363 .setLabel("Note")
364 .setMaxLength(4000)
365 .setRequired(false)
366 .setStyle("PARAGRAPH")
367 .setValue(note ? note : "")
368 )
369 )
370 );
pineafan4edb7762022-06-26 19:21:04 +0100371 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100372 embeds: [
373 new EmojiEmbed()
374 .setTitle("Mod notes for " + member.user.username)
Skyler Grey11236ba2022-08-08 21:13:33 +0100375 .setDescription("Modal opened. If you can't see it, click back and try again.")
Skyler Grey75ea9172022-08-06 10:22:23 +0100376 .setStatus("Success")
377 .setEmoji("GUILD.TICKET.OPEN")
378 ],
379 components: [
TheCodedProf21c08592022-09-13 14:14:43 -0400380 new ActionRowBuilder().addComponents([
381 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100382 .setLabel("Back")
383 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400384 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100385 .setCustomId("back")
386 ])
387 ]
pineafan4edb7762022-06-26 19:21:04 +0100388 });
389 let out;
390 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100391 out = await modalInteractionCollector(
392 m,
pineafan3a02ea32022-08-11 21:35:04 +0100393 (m: Interaction) =>
394 (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === interaction.channelId,
Skyler Grey75ea9172022-08-06 10:22:23 +0100395 (m) => m.customId === "modify"
396 );
397 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100398 timedOut = true;
399 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100400 }
pineafan3a02ea32022-08-11 21:35:04 +0100401 if (out === null) {
402 continue;
403 } else if (out instanceof ModalSubmitInteraction) {
pineafan63fc5e22022-08-04 22:04:10 +0100404 const toAdd = out.fields.getTextInputValue("note") || null;
Skyler Grey11236ba2022-08-08 21:13:33 +0100405 await client.database.notes.create(member.guild.id, member.id, toAdd);
Skyler Grey75ea9172022-08-06 10:22:23 +0100406 } else {
407 continue;
408 }
pineafan4edb7762022-06-26 19:21:04 +0100409 } else if (i.customId === "history") {
410 i.deferUpdate();
Skyler Grey75ea9172022-08-06 10:22:23 +0100411 if (!(await showHistory(member, interaction))) return;
pineafan4edb7762022-06-26 19:21:04 +0100412 }
413 }
pineafan63fc5e22022-08-04 22:04:10 +0100414};
pineafan4edb7762022-06-26 19:21:04 +0100415
pineafanbd02b4a2022-08-05 22:01:38 +0100416const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100417 const member = interaction.member as GuildMember;
pineafan3a02ea32022-08-11 21:35:04 +0100418 if (!member.permissions.has("MODERATE_MEMBERS"))
419 throw new Error("You do not have the *Moderate Members* permission");
pineafan63fc5e22022-08-04 22:04:10 +0100420 return true;
421};
pineafan4edb7762022-06-26 19:21:04 +0100422
423export { command };
424export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100425export { check };