blob: d34b63477e7a03f644c98f2b1f22ca9ff6245759 [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 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 TextInputStyle,
TheCodedProf4a6d5712023-01-19 15:54:40 -050014 APIMessageComponentEmoji,
TheCodedProff86ba092023-01-27 17:10:07 -050015 SlashCommandSubcommandBuilder
Skyler Grey75ea9172022-08-06 10:22:23 +010016} from "discord.js";
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))
TheCodedProf4a6d5712023-01-19 15:54:40 -0500170 .setEmoji(getEmojiByName(value.emoji, "id") as APIMessageComponentEmoji)
PineaFan5bea7e12023-01-05 21:20:04 +0000171 )))
172 ]);
PineaFana34d04b2023-01-03 22:05:42 +0000173 components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
174 new ButtonBuilder()
175 .setCustomId("prevYear")
176 .setLabel((currentYear - 1).toString())
177 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
178 .setStyle(ButtonStyle.Secondary),
179 new ButtonBuilder()
180 .setCustomId("prevPage")
181 .setLabel("Previous page")
182 .setStyle(ButtonStyle.Primary),
PineaFan5bea7e12023-01-05 21:20:04 +0000183 new ButtonBuilder()
184 .setCustomId("today")
185 .setLabel("Today")
186 .setStyle(ButtonStyle.Primary),
PineaFana34d04b2023-01-03 22:05:42 +0000187 new ButtonBuilder()
188 .setCustomId("nextPage")
189 .setLabel("Next page")
190 .setStyle(ButtonStyle.Primary)
191 .setDisabled(pageIndex >= groups.length - 1 && currentYear === new Date().getFullYear()),
192 new ButtonBuilder()
193 .setCustomId("nextYear")
194 .setLabel((currentYear + 1).toString())
195 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
196 .setStyle(ButtonStyle.Secondary)
197 .setDisabled(currentYear === new Date().getFullYear())
198 ])])
199 components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
200 new ButtonBuilder()
201 .setLabel("Mod notes")
202 .setCustomId("modNotes")
203 .setStyle(ButtonStyle.Primary)
204 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
205 new ButtonBuilder()
206 .setLabel("Filter")
207 .setCustomId("openFilter")
208 .setStyle(openFilterPane ? ButtonStyle.Success : ButtonStyle.Primary)
209 .setEmoji(getEmojiByName("ICONS.FILTER", "id"))
210 ])])
211
Skyler Grey75ea9172022-08-06 10:22:23 +0100212 const end =
213 "\n\nJanuary " +
214 currentYear.toString() +
Skyler Grey11236ba2022-08-08 21:13:33 +0100215 pageIndicator(Math.max(groups.length, 1), groups.length === 0 ? 1 : pageIndex) +
216 (currentYear === new Date().getFullYear() ? monthNames[new Date().getMonth()] : "December") +
Skyler Grey75ea9172022-08-06 10:22:23 +0100217 " " +
218 currentYear.toString();
pineafan4edb7762022-06-26 19:21:04 +0100219 if (groups.length > 0) {
pineafan3a02ea32022-08-11 21:35:04 +0100220 const toRender = groups[Math.min(pageIndex, groups.length - 1)]!;
PineaFana34d04b2023-01-03 22:05:42 +0000221 m = await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100222 embeds: [
223 new EmojiEmbed()
224 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100225 .setTitle("Moderation history for " + member.user.username)
Skyler Grey75ea9172022-08-06 10:22:23 +0100226 .setDescription(
Skyler Grey11236ba2022-08-08 21:13:33 +0100227 `**${toRender.name}**\n\n` + toRender.content.map((c) => c.rendered).join("\n") + end
Skyler Grey75ea9172022-08-06 10:22:23 +0100228 )
229 .setStatus("Success")
230 .setFooter({
PineaFana34d04b2023-01-03 22:05:42 +0000231 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
Skyler Grey75ea9172022-08-06 10:22:23 +0100232 })
233 ],
234 components: components
PineaFana34d04b2023-01-03 22:05:42 +0000235 });
pineafan4edb7762022-06-26 19:21:04 +0100236 } else {
PineaFana34d04b2023-01-03 22:05:42 +0000237 m = await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100238 embeds: [
239 new EmojiEmbed()
240 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100241 .setTitle("Moderation history for " + member.user.username)
PineaFana34d04b2023-01-03 22:05:42 +0000242 .setDescription(`**${currentYear}**\n\n*No events*`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100243 .setStatus("Success")
244 .setFooter({
PineaFana34d04b2023-01-03 22:05:42 +0000245 text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
Skyler Grey75ea9172022-08-06 10:22:23 +0100246 })
247 ],
248 components: components
PineaFana34d04b2023-01-03 22:05:42 +0000249 })
pineafan4edb7762022-06-26 19:21:04 +0100250 }
pineafan3a02ea32022-08-11 21:35:04 +0100251 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100252 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000253 i = await m.awaitMessageComponent({
254 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -0500255 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 +0000256 });
pineafan4edb7762022-06-26 19:21:04 +0100257 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100258 interaction.editReply({
259 embeds: [
260 new EmojiEmbed()
261 .setEmoji("MEMBER.JOIN")
Skyler Grey11236ba2022-08-08 21:13:33 +0100262 .setTitle("Moderation history for " + member.user.username)
pineafan3a02ea32022-08-11 21:35:04 +0100263 .setDescription(m.embeds[0]!.description!)
Skyler Grey75ea9172022-08-06 10:22:23 +0100264 .setStatus("Danger")
265 .setFooter({ text: "Message timed out" })
266 ]
267 });
Skyler Greyad002172022-08-16 18:48:26 +0100268 timedOut = true;
269 continue;
pineafan4edb7762022-06-26 19:21:04 +0100270 }
TheCodedProf267563a2023-01-21 17:00:57 -0500271 await i.deferUpdate();
TheCodedProf4a6d5712023-01-19 15:54:40 -0500272 if (i.customId === "filter" && i.isStringSelectMenu()) {
273 filteredTypes = i.values;
pineafan4edb7762022-06-26 19:21:04 +0100274 pageIndex = null;
275 refresh = true;
276 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100277 if (i.customId === "prevYear") {
278 currentYear--;
279 pageIndex = null;
280 refresh = true;
281 }
282 if (i.customId === "nextYear") {
283 currentYear++;
284 pageIndex = null;
285 refresh = true;
286 }
pineafan4edb7762022-06-26 19:21:04 +0100287 if (i.customId === "prevPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100288 pageIndex!--;
289 if (pageIndex! < 0) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100290 pageIndex = null;
291 currentYear--;
292 refresh = true;
293 }
pineafan4edb7762022-06-26 19:21:04 +0100294 }
295 if (i.customId === "nextPage") {
pineafan3a02ea32022-08-11 21:35:04 +0100296 pageIndex!++;
297 if (pageIndex! >= groups.length) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100298 pageIndex = 0;
299 currentYear++;
300 refresh = true;
301 }
pineafan4edb7762022-06-26 19:21:04 +0100302 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100303 if (i.customId === "today") {
304 currentYear = new Date().getFullYear();
305 pageIndex = null;
306 refresh = true;
307 }
308 if (i.customId === "modNotes") {
Skyler Greyad002172022-08-16 18:48:26 +0100309 showHistorySelected = true;
Skyler Grey75ea9172022-08-06 10:22:23 +0100310 }
311 if (i.customId === "openFilter") {
312 openFilterPane = !openFilterPane;
313 refresh = true;
314 }
pineafan4edb7762022-06-26 19:21:04 +0100315 }
Skyler Greyad002172022-08-16 18:48:26 +0100316 return timedOut ? 0 : 1;
pineafan4edb7762022-06-26 19:21:04 +0100317}
318
pineafan3a02ea32022-08-11 21:35:04 +0100319const callback = async (interaction: CommandInteraction): Promise<unknown> => {
320 let m: Message;
Skyler Grey75ea9172022-08-06 10:22:23 +0100321 const member = interaction.options.getMember("user") as Discord.GuildMember;
322 await interaction.reply({
PineaFana34d04b2023-01-03 22:05:42 +0000323 embeds: LoadingEmbed,
Skyler Grey75ea9172022-08-06 10:22:23 +0100324 ephemeral: true,
325 fetchReply: true
326 });
pineafan4edb7762022-06-26 19:21:04 +0100327 let note;
328 let firstLoad = true;
Skyler Greyad002172022-08-16 18:48:26 +0100329 let timedOut = false;
330 while (!timedOut) {
pineafan4edb7762022-06-26 19:21:04 +0100331 note = await client.database.notes.read(member.guild.id, member.id);
PineaFana34d04b2023-01-03 22:05:42 +0000332 if (firstLoad && !note) { await showHistory(member, interaction); }
pineafan4edb7762022-06-26 19:21:04 +0100333 firstLoad = false;
pineafan3a02ea32022-08-11 21:35:04 +0100334 m = (await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100335 embeds: [
336 new EmojiEmbed()
337 .setEmoji("MEMBER.JOIN")
338 .setTitle("Mod notes for " + member.user.username)
339 .setDescription(note ? note : "*No note set*")
340 .setStatus("Success")
341 ],
342 components: [
PineaFan100df682023-01-02 13:26:08 +0000343 new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400344 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100345 .setLabel(`${note ? "Modify" : "Create"} note`)
TheCodedProf21c08592022-09-13 14:14:43 -0400346 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100347 .setCustomId("modify")
348 .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
TheCodedProf21c08592022-09-13 14:14:43 -0400349 new ButtonBuilder()
PineaFana34d04b2023-01-03 22:05:42 +0000350 .setLabel("Moderation history")
TheCodedProf21c08592022-09-13 14:14:43 -0400351 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100352 .setCustomId("history")
353 .setEmoji(getEmojiByName("ICONS.HISTORY", "id"))
354 ])
355 ]
pineafan3a02ea32022-08-11 21:35:04 +0100356 })) as Message;
357 let i: MessageComponentInteraction;
pineafan4edb7762022-06-26 19:21:04 +0100358 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000359 i = await m.awaitMessageComponent({
360 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -0500361 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 +0000362 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100363 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100364 timedOut = true;
365 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100366 }
pineafan4edb7762022-06-26 19:21:04 +0100367 if (i.customId === "modify") {
Skyler Grey75ea9172022-08-06 10:22:23 +0100368 await i.showModal(
PineaFan100df682023-01-02 13:26:08 +0000369 new Discord.ModalBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100370 .setCustomId("modal")
371 .setTitle("Editing moderator note")
372 .addComponents(
PineaFana34d04b2023-01-03 22:05:42 +0000373 new ActionRowBuilder<Discord.TextInputBuilder>().addComponents(
374 new Discord.TextInputBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100375 .setCustomId("note")
376 .setLabel("Note")
377 .setMaxLength(4000)
378 .setRequired(false)
PineaFana34d04b2023-01-03 22:05:42 +0000379 .setStyle(TextInputStyle.Paragraph)
380 .setValue(note ? note : " ")
Skyler Grey75ea9172022-08-06 10:22:23 +0100381 )
382 )
383 );
pineafan4edb7762022-06-26 19:21:04 +0100384 await interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +0100385 embeds: [
386 new EmojiEmbed()
387 .setTitle("Mod notes for " + member.user.username)
Skyler Grey11236ba2022-08-08 21:13:33 +0100388 .setDescription("Modal opened. If you can't see it, click back and try again.")
Skyler Grey75ea9172022-08-06 10:22:23 +0100389 .setStatus("Success")
390 .setEmoji("GUILD.TICKET.OPEN")
391 ],
392 components: [
PineaFan100df682023-01-02 13:26:08 +0000393 new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400394 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100395 .setLabel("Back")
396 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400397 .setStyle(ButtonStyle.Primary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100398 .setCustomId("back")
399 ])
400 ]
pineafan4edb7762022-06-26 19:21:04 +0100401 });
402 let out;
403 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100404 out = await modalInteractionCollector(
405 m,
pineafan3a02ea32022-08-11 21:35:04 +0100406 (m: Interaction) =>
407 (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === interaction.channelId,
Skyler Grey75ea9172022-08-06 10:22:23 +0100408 (m) => m.customId === "modify"
409 );
410 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100411 timedOut = true;
412 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100413 }
TheCodedProf4a6d5712023-01-19 15:54:40 -0500414 if (out === null || out.isButton()) {
pineafan3a02ea32022-08-11 21:35:04 +0100415 continue;
416 } else if (out instanceof ModalSubmitInteraction) {
PineaFana34d04b2023-01-03 22:05:42 +0000417 let toAdd = out.fields.getTextInputValue("note") || null;
418 if (toAdd === " ") toAdd = null;
419 if (toAdd) toAdd = toAdd.trim();
Skyler Grey11236ba2022-08-08 21:13:33 +0100420 await client.database.notes.create(member.guild.id, member.id, toAdd);
Skyler Grey75ea9172022-08-06 10:22:23 +0100421 } else {
422 continue;
423 }
pineafan4edb7762022-06-26 19:21:04 +0100424 } else if (i.customId === "history") {
TheCodedProf267563a2023-01-21 17:00:57 -0500425 await i.deferUpdate();
Skyler Grey75ea9172022-08-06 10:22:23 +0100426 if (!(await showHistory(member, interaction))) return;
pineafan4edb7762022-06-26 19:21:04 +0100427 }
428 }
pineafan63fc5e22022-08-04 22:04:10 +0100429};
pineafan4edb7762022-06-26 19:21:04 +0100430
pineafanbd02b4a2022-08-05 22:01:38 +0100431const check = (interaction: CommandInteraction) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100432 const member = interaction.member as GuildMember;
PineaFan100df682023-01-02 13:26:08 +0000433 if (!member.permissions.has("ModerateMembers"))
PineaFan0d06edc2023-01-17 22:10:31 +0000434 return "You do not have the *Moderate Members* permission";
pineafan63fc5e22022-08-04 22:04:10 +0100435 return true;
436};
pineafan4edb7762022-06-26 19:21:04 +0100437
438export { command };
439export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100440export { check };