blob: c69f4a9897842d851b677cb9e39f56ffea5725fd [file] [log] [blame]
PineaFan1dee28f2023-01-16 22:09:07 +00001import { LoadingEmbed } from '../../utils/defaultEmbeds.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 Interaction,
7 Message,
TheCodedProf21c08592022-09-13 14:14:43 -04008 ActionRowBuilder,
9 ButtonBuilder,
pineafan3a02ea32022-08-11 21:35:04 +010010 MessageComponentInteraction,
11 ModalSubmitInteraction,
PineaFan100df682023-01-02 13:26:08 +000012 ButtonStyle,
PineaFana34d04b2023-01-03 22:05:42 +000013 StringSelectMenuInteraction,
14 TextInputStyle,
Skyler Grey75ea9172022-08-06 10:22:23 +010015} from "discord.js";
PineaFan5bea7e12023-01-05 21:20:04 +000016import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan4edb7762022-06-26 19:21:04 +010017import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
18import getEmojiByName from "../../utils/getEmojiByName.js";
19import client from "../../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +010020import { modalInteractionCollector } from "../../utils/dualCollector.js";
21import pageIndicator from "../../utils/createPageIndicator.js";
pineafan4edb7762022-06-26 19:21:04 +010022
23const command = (builder: SlashCommandSubcommandBuilder) =>
24 builder
PineaFan1dee28f2023-01-16 22:09:07 +000025 .setName("about")
26 // .setNameLocalizations({"ru": "info", "zh-CN": "history", "zh-TW": "notes", "pt-BR": "flags"})
pineafan63fc5e22022-08-04 22:04:10 +010027 .setDescription("Shows moderator information about a user")
Skyler Grey75ea9172022-08-06 10:22:23 +010028 .addUserOption((option) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010029 option.setName("user").setDescription("The user to get information about").setRequired(true)
Skyler Grey75ea9172022-08-06 10:22:23 +010030 );
pineafan4edb7762022-06-26 19:21:04 +010031
pineafan3a02ea32022-08-11 21:35:04 +010032const types: Record<string, { emoji: string; text: string }> = {
Skyler Grey75ea9172022-08-06 10:22:23 +010033 warn: { emoji: "PUNISH.WARN.YELLOW", text: "Warned" },
34 mute: { emoji: "PUNISH.MUTE.YELLOW", text: "Muted" },
35 unmute: { emoji: "PUNISH.MUTE.GREEN", text: "Unmuted" },
36 join: { emoji: "MEMBER.JOIN", text: "Joined" },
37 leave: { emoji: "MEMBER.LEAVE", text: "Left" },
38 kick: { emoji: "MEMBER.KICK", text: "Kicked" },
39 softban: { emoji: "PUNISH.SOFTBAN", text: "Softbanned" },
40 ban: { emoji: "MEMBER.BAN", text: "Banned" },
41 unban: { emoji: "MEMBER.UNBAN", text: "Unbanned" },
42 purge: { emoji: "PUNISH.CLEARHISTORY", text: "Messages cleared" },
43 nickname: { emoji: "PUNISH.NICKNAME.YELLOW", text: "Nickname changed" }
pineafan63fc5e22022-08-04 22:04:10 +010044};
pineafan4edb7762022-06-26 19:21:04 +010045
46function historyToString(history: HistorySchema) {
pineafan3a02ea32022-08-11 21:35:04 +010047 if (!Object.keys(types).includes(history.type)) throw new Error("Invalid history type");
48 let s = `${getEmojiByName(types[history.type]!.emoji)} ${history.amount ? history.amount + " " : ""}${
49 types[history.type]!.text
Skyler Grey11236ba2022-08-08 21:13:33 +010050 } on <t:${Math.round(history.occurredAt.getTime() / 1000)}:F>`;
Skyler Grey75ea9172022-08-06 10:22:23 +010051 if (history.moderator) {
52 s += ` by <@${history.moderator}>`;
53 }
54 if (history.reason) {
55 s += `\n**Reason:**\n> ${history.reason}`;
56 }
57 if (history.before) {
58 s += `\n**Before:**\n> ${history.before}`;
59 }
60 if (history.after) {
61 s += `\n**After:**\n> ${history.after}`;
62 }
pineafan4edb7762022-06-26 19:21:04 +010063 return s + "\n";
64}
65
pineafan4edb7762022-06-26 19:21:04 +010066class TimelineSection {
pineafan3a02ea32022-08-11 21:35:04 +010067 name: string = "";
Skyler Grey75ea9172022-08-06 10:22:23 +010068 content: { data: HistorySchema; rendered: string }[] = [];
pineafan4edb7762022-06-26 19:21:04 +010069
Skyler Grey75ea9172022-08-06 10:22:23 +010070 addContent = (content: { data: HistorySchema; rendered: string }) => {
71 this.content.push(content);
72 return this;
73 };
74 contentLength = () => {
75 return this.content.reduce((acc, cur) => acc + cur.rendered.length, 0);
76 };
pineafan4edb7762022-06-26 19:21:04 +010077 generateName = () => {
pineafan3a02ea32022-08-11 21:35:04 +010078 const first = Math.round(this.content[0]!.data.occurredAt.getTime() / 1000);
79 const last = Math.round(this.content[this.content.length - 1]!.data.occurredAt.getTime() / 1000);
Skyler Grey75ea9172022-08-06 10:22:23 +010080 if (first === last) {
81 return (this.name = `<t:${first}:F>`);
82 }
83 return (this.name = `<t:${first}:F> - <t:${last}:F>`);
pineafan63fc5e22022-08-04 22:04:10 +010084 };
pineafan4edb7762022-06-26 19:21:04 +010085}
86
Skyler Grey75ea9172022-08-06 10:22:23 +010087const monthNames = [
88 "January",
89 "February",
90 "March",
91 "April",
92 "May",
93 "June",
94 "July",
95 "August",
96 "September",
97 "October",
98 "November",
99 "December"
100];
pineafan4edb7762022-06-26 19:21:04 +0100101
pineafan3a02ea32022-08-11 21:35:04 +0100102async function showHistory(member: Discord.GuildMember, interaction: CommandInteraction) {
pineafan4edb7762022-06-26 19:21:04 +0100103 let currentYear = new Date().getFullYear();
pineafan3a02ea32022-08-11 21:35:04 +0100104 let pageIndex: number | null = null;
105 let history, current: TimelineSection;
PineaFan100df682023-01-02 13:26:08 +0000106 history = await client.database.history.read(member.guild.id, member.id, currentYear);
107 history = history
108 .sort(
109 (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
110 b.occurredAt.getTime() - a.occurredAt.getTime()
111 )
112 .reverse();
pineafan3a02ea32022-08-11 21:35:04 +0100113 let m: Message;
PineaFan100df682023-01-02 13:26:08 +0000114 let refresh = false;
pineafan3a02ea32022-08-11 21:35:04 +0100115 let filteredTypes: string[] = [];
pineafan4edb7762022-06-26 19:21:04 +0100116 let openFilterPane = false;
Skyler Greyad002172022-08-16 18:48:26 +0100117 let timedOut = false;
118 let showHistorySelected = false;
119 while (!timedOut && !showHistorySelected) {
pineafan4edb7762022-06-26 19:21:04 +0100120 if (refresh) {
Skyler Grey11236ba2022-08-08 21:13:33 +0100121 history = await client.database.history.read(member.guild.id, member.id, currentYear);
pineafan3a02ea32022-08-11 21:35:04 +0100122 history = history
123 .sort(
124 (a: { occurredAt: Date }, b: { occurredAt: Date }) =>
125 b.occurredAt.getTime() - a.occurredAt.getTime()
126 )
127 .reverse();
pineafan4edb7762022-06-26 19:21:04 +0100128 if (openFilterPane) {
pineafan63fc5e22022-08-04 22:04:10 +0100129 let tempFilteredTypes = filteredTypes;
Skyler Grey75ea9172022-08-06 10:22:23 +0100130 if (filteredTypes.length === 0) {
131 tempFilteredTypes = Object.keys(types);
132 }
pineafan3a02ea32022-08-11 21:35:04 +0100133 history = history.filter((h: { type: string }) => tempFilteredTypes.includes(h.type));
pineafan63fc5e22022-08-04 22:04:10 +0100134 }
pineafan4edb7762022-06-26 19:21:04 +0100135 refresh = false;
136 }
pineafan63fc5e22022-08-04 22:04:10 +0100137 const groups: TimelineSection[] = [];
pineafan4edb7762022-06-26 19:21:04 +0100138 if (history.length > 0) {
pineafan63fc5e22022-08-04 22:04:10 +0100139 current = new TimelineSection();
pineafan3a02ea32022-08-11 21:35:04 +0100140 history.forEach((event: HistorySchema) => {
Skyler Grey11236ba2022-08-08 21:13:33 +0100141 if (current.contentLength() + historyToString(event).length > 2000 || current.content.length === 5) {
pineafan4edb7762022-06-26 19:21:04 +0100142 groups.push(current);
143 current.generateName();
144 current = new TimelineSection();
145 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100146 current.addContent({
147 data: event,
148 rendered: historyToString(event)
149 });
pineafan4edb7762022-06-26 19:21:04 +0100150 });
151 current.generateName();
152 groups.push(current);
Skyler Grey75ea9172022-08-06 10:22:23 +0100153 if (pageIndex === null) {
154 pageIndex = groups.length - 1;
155 }
pineafan4edb7762022-06-26 19:21:04 +0100156 }
pineafan3a02ea32022-08-11 21:35:04 +0100157 if (pageIndex === null) pageIndex = 0;
PineaFana34d04b2023-01-03 22:05:42 +0000158 let components: (ActionRowBuilder<Discord.StringSelectMenuBuilder> | ActionRowBuilder<ButtonBuilder>)[] = []
159 if (openFilterPane) components = components.concat([
160 new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents(
PineaFan5bea7e12023-01-05 21:20:04 +0000161 new Discord.StringSelectMenuBuilder()
162 .setMinValues(1)
163 .setMaxValues(Object.keys(types).length)
164 .setCustomId("filter")
165 .setPlaceholder("Select events to show")
166 .setOptions(...Object.entries(types).map(([key, value]) => new Discord.StringSelectMenuOptionBuilder()
167 .setLabel(value.text)
168 .setValue(key)
169 .setDefault(filteredTypes.includes(key))
170 // @ts-expect-error
171 .setEmoji(getEmojiByName(value.emoji, "id")) // FIXME: This gives a type error but is valid
172 )))
173 ]);
PineaFana34d04b2023-01-03 22:05:42 +0000174 components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
175 new ButtonBuilder()
176 .setCustomId("prevYear")
177 .setLabel((currentYear - 1).toString())
178 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
179 .setStyle(ButtonStyle.Secondary),
180 new ButtonBuilder()
181 .setCustomId("prevPage")
182 .setLabel("Previous page")
183 .setStyle(ButtonStyle.Primary),
PineaFan5bea7e12023-01-05 21:20:04 +0000184 new ButtonBuilder()
185 .setCustomId("today")
186 .setLabel("Today")
187 .setStyle(ButtonStyle.Primary),
PineaFana34d04b2023-01-03 22:05:42 +0000188 new ButtonBuilder()
189 .setCustomId("nextPage")
190 .setLabel("Next page")
191 .setStyle(ButtonStyle.Primary)
192 .setDisabled(pageIndex >= groups.length - 1 && currentYear === new Date().getFullYear()),
193 new ButtonBuilder()
194 .setCustomId("nextYear")
195 .setLabel((currentYear + 1).toString())
196 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
197 .setStyle(ButtonStyle.Secondary)
198 .setDisabled(currentYear === new Date().getFullYear())
199 ])])
200 components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
201 new ButtonBuilder()
202 .setLabel("Mod notes")
203 .setCustomId("modNotes")
204 .setStyle(ButtonStyle.Primary)
205 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
206 new ButtonBuilder()
207 .setLabel("Filter")
208 .setCustomId("openFilter")
209 .setStyle(openFilterPane ? ButtonStyle.Success : ButtonStyle.Primary)
210 .setEmoji(getEmojiByName("ICONS.FILTER", "id"))
211 ])])
212
Skyler Grey75ea9172022-08-06 10:22:23 +0100213 const end =
214 "\n\nJanuary " +
215 currentYear.toString() +
Skyler Grey11236ba2022-08-08 21:13:33 +0100216 pageIndicator(Math.max(groups.length, 1), groups.length === 0 ? 1 : pageIndex) +
217 (currentYear === new Date().getFullYear() ? monthNames[new Date().getMonth()] : "December") +
Skyler Grey75ea9172022-08-06 10:22:23 +0100218 " " +
219 currentYear.toString();
pineafan4edb7762022-06-26 19:21:04 +0100220 if (groups.length > 0) {
pineafan3a02ea32022-08-11 21:35:04 +0100221 const toRender = groups[Math.min(pageIndex, groups.length - 1)]!;
PineaFana34d04b2023-01-03 22:05:42 +0000222 m = await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100223 embeds: [
224 new EmojiEmbed()
225 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100226 .setTitle("Moderation history for " + member.user.username)
Skyler Grey75ea9172022-08-06 10:22:23 +0100227 .setDescription(
Skyler Grey11236ba2022-08-08 21:13:33 +0100228 `**${toRender.name}**\n\n` + toRender.content.map((c) => c.rendered).join("\n") + end
Skyler Grey75ea9172022-08-06 10:22:23 +0100229 )
230 .setStatus("Success")
231 .setFooter({
PineaFana34d04b2023-01-03 22:05:42 +0000232 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
Skyler Grey75ea9172022-08-06 10:22:23 +0100233 })
234 ],
235 components: components
PineaFana34d04b2023-01-03 22:05:42 +0000236 });
pineafan4edb7762022-06-26 19:21:04 +0100237 } else {
PineaFana34d04b2023-01-03 22:05:42 +0000238 m = await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100239 embeds: [
240 new EmojiEmbed()
241 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100242 .setTitle("Moderation history for " + member.user.username)
PineaFana34d04b2023-01-03 22:05:42 +0000243 .setDescription(`**${currentYear}**\n\n*No events*`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100244 .setStatus("Success")
245 .setFooter({
PineaFana34d04b2023-01-03 22:05:42 +0000246 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
Skyler Grey75ea9172022-08-06 10:22:23 +0100247 })
248 ],
249 components: components
PineaFana34d04b2023-01-03 22:05:42 +0000250 })
pineafan4edb7762022-06-26 19:21:04 +0100251 }
pineafan3a02ea32022-08-11 21:35:04 +0100252 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100253 try {
254 i = await m.awaitMessageComponent({ time: 300000 });
255 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100256 interaction.editReply({
257 embeds: [
258 new EmojiEmbed()
259 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100260 .setTitle("Moderation history for " + member.user.username)
pineafan3a02ea32022-08-11 21:35:04 +0100261 .setDescription(m.embeds[0]!.description!)
Skyler Grey75ea9172022-08-06 10:22:23 +0100262 .setStatus("Danger")
263 .setFooter({ text: "Message timed out" })
264 ]
265 });
Skyler Greyad002172022-08-16 18:48:26 +0100266 timedOut = true;
267 continue;
pineafan4edb7762022-06-26 19:21:04 +0100268 }
pineafan63fc5e22022-08-04 22:04:10 +0100269 i.deferUpdate();
pineafan4edb7762022-06-26 19:21:04 +0100270 if (i.customId === "filter") {
PineaFan100df682023-01-02 13:26:08 +0000271 filteredTypes = (i as StringSelectMenuInteraction).values;
pineafan4edb7762022-06-26 19:21:04 +0100272 pageIndex = null;
273 refresh = true;
274 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100275 if (i.customId === "prevYear") {
276 currentYear--;
277 pageIndex = null;
278 refresh = true;
279 }
280 if (i.customId === "nextYear") {
281 currentYear++;
282 pageIndex = null;
283 refresh = true;
284 }
pineafan4edb7762022-06-26 19:21:04 +0100285 if (i.customId === "prevPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100286 pageIndex!--;
287 if (pageIndex! < 0) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100288 pageIndex = null;
289 currentYear--;
290 refresh = true;
291 }
pineafan4edb7762022-06-26 19:21:04 +0100292 }
293 if (i.customId === "nextPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100294 pageIndex!++;
295 if (pageIndex! >= groups.length) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100296 pageIndex = 0;
297 currentYear++;
298 refresh = true;
299 }
pineafan4edb7762022-06-26 19:21:04 +0100300 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100301 if (i.customId === "today") {
302 currentYear = new Date().getFullYear();
303 pageIndex = null;
304 refresh = true;
305 }
306 if (i.customId === "modNotes") {
Skyler Greyad002172022-08-16 18:48:26 +0100307 showHistorySelected = true;
Skyler Grey75ea9172022-08-06 10:22:23 +0100308 }
309 if (i.customId === "openFilter") {
310 openFilterPane = !openFilterPane;
311 refresh = true;
312 }
pineafan4edb7762022-06-26 19:21:04 +0100313 }
Skyler Greyad002172022-08-16 18:48:26 +0100314 return timedOut ? 0 : 1;
pineafan4edb7762022-06-26 19:21:04 +0100315}
316
pineafan3a02ea32022-08-11 21:35:04 +0100317const callback = async (interaction: CommandInteraction): Promise<unknown> => {
318 let m: Message;
Skyler Grey75ea9172022-08-06 10:22:23 +0100319 const member = interaction.options.getMember("user") as Discord.GuildMember;
320 await interaction.reply({
PineaFana34d04b2023-01-03 22:05:42 +0000321 embeds: LoadingEmbed,
Skyler Grey75ea9172022-08-06 10:22:23 +0100322 ephemeral: true,
323 fetchReply: true
324 });
pineafan4edb7762022-06-26 19:21:04 +0100325 let note;
326 let firstLoad = true;
Skyler Greyad002172022-08-16 18:48:26 +0100327 let timedOut = false;
328 while (!timedOut) {
pineafan4edb7762022-06-26 19:21:04 +0100329 note = await client.database.notes.read(member.guild.id, member.id);
PineaFana34d04b2023-01-03 22:05:42 +0000330 if (firstLoad && !note) { await showHistory(member, interaction); }
pineafan4edb7762022-06-26 19:21:04 +0100331 firstLoad = false;
pineafan3a02ea32022-08-11 21:35:04 +0100332 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100333 embeds: [
334 new EmojiEmbed()
335 .setEmoji("MEMBER.JOIN")
336 .setTitle("Mod notes for " + member.user.username)
337 .setDescription(note ? note : "*No note set*")
338 .setStatus("Success")
339 ],
340 components: [
PineaFan100df682023-01-02 13:26:08 +0000341 new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400342 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100343 .setLabel(`${note ? "Modify" : "Create"} note`)
TheCodedProf21c08592022-09-13 14:14:43 -0400344 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100345 .setCustomId("modify")
346 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
TheCodedProf21c08592022-09-13 14:14:43 -0400347 new ButtonBuilder()
PineaFana34d04b2023-01-03 22:05:42 +0000348 .setLabel("Moderation history")
TheCodedProf21c08592022-09-13 14:14:43 -0400349 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100350 .setCustomId("history")
351 .setEmoji(getEmojiByName("ICONS.HISTORY", "id"))
352 ])
353 ]
pineafan3a02ea32022-08-11 21:35:04 +0100354 })) as Message;
355 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100356 try {
357 i = await m.awaitMessageComponent({ time: 300000 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100358 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100359 timedOut = true;
360 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100361 }
pineafan4edb7762022-06-26 19:21:04 +0100362 if (i.customId === "modify") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100363 await i.showModal(
PineaFan100df682023-01-02 13:26:08 +0000364 new Discord.ModalBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100365 .setCustomId("modal")
366 .setTitle("Editing moderator note")
367 .addComponents(
PineaFana34d04b2023-01-03 22:05:42 +0000368 new ActionRowBuilder<Discord.TextInputBuilder>().addComponents(
369 new Discord.TextInputBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100370 .setCustomId("note")
371 .setLabel("Note")
372 .setMaxLength(4000)
373 .setRequired(false)
PineaFana34d04b2023-01-03 22:05:42 +0000374 .setStyle(TextInputStyle.Paragraph)
375 .setValue(note ? note : " ")
Skyler Grey75ea9172022-08-06 10:22:23 +0100376 )
377 )
378 );
pineafan4edb7762022-06-26 19:21:04 +0100379 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100380 embeds: [
381 new EmojiEmbed()
382 .setTitle("Mod notes for " + member.user.username)
Skyler Grey11236ba2022-08-08 21:13:33 +0100383 .setDescription("Modal opened. If you can't see it, click back and try again.")
Skyler Grey75ea9172022-08-06 10:22:23 +0100384 .setStatus("Success")
385 .setEmoji("GUILD.TICKET.OPEN")
386 ],
387 components: [
PineaFan100df682023-01-02 13:26:08 +0000388 new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400389 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100390 .setLabel("Back")
391 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400392 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100393 .setCustomId("back")
394 ])
395 ]
pineafan4edb7762022-06-26 19:21:04 +0100396 });
397 let out;
398 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100399 out = await modalInteractionCollector(
400 m,
pineafan3a02ea32022-08-11 21:35:04 +0100401 (m: Interaction) =>
402 (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === interaction.channelId,
Skyler Grey75ea9172022-08-06 10:22:23 +0100403 (m) => m.customId === "modify"
404 );
405 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100406 timedOut = true;
407 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100408 }
pineafan3a02ea32022-08-11 21:35:04 +0100409 if (out === null) {
410 continue;
411 } else if (out instanceof ModalSubmitInteraction) {
PineaFana34d04b2023-01-03 22:05:42 +0000412 let toAdd = out.fields.getTextInputValue("note") || null;
413 if (toAdd === " ") toAdd = null;
414 if (toAdd) toAdd = toAdd.trim();
Skyler Grey11236ba2022-08-08 21:13:33 +0100415 await client.database.notes.create(member.guild.id, member.id, toAdd);
Skyler Grey75ea9172022-08-06 10:22:23 +0100416 } else {
417 continue;
418 }
pineafan4edb7762022-06-26 19:21:04 +0100419 } else if (i.customId === "history") {
420 i.deferUpdate();
Skyler Grey75ea9172022-08-06 10:22:23 +0100421 if (!(await showHistory(member, interaction))) return;
pineafan4edb7762022-06-26 19:21:04 +0100422 }
423 }
pineafan63fc5e22022-08-04 22:04:10 +0100424};
pineafan4edb7762022-06-26 19:21:04 +0100425
pineafanbd02b4a2022-08-05 22:01:38 +0100426const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100427 const member = interaction.member as GuildMember;
PineaFan100df682023-01-02 13:26:08 +0000428 if (!member.permissions.has("ModerateMembers"))
pineafan3a02ea32022-08-11 21:35:04 +0100429 throw new Error("You do not have the *Moderate Members* permission");
pineafan63fc5e22022-08-04 22:04:10 +0100430 return true;
431};
pineafan4edb7762022-06-26 19:21:04 +0100432
433export { command };
434export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100435export { check };