Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 1 | import { HistorySchema } from "../../utils/database.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | GuildMember, |
| 5 | MessageActionRow, |
| 6 | MessageButton, |
| 7 | TextInputComponent |
| 8 | } from "discord.js"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 9 | import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 10 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 11 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
| 12 | import client from "../../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
| 14 | import pageIndicator from "../../utils/createPageIndicator.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 15 | |
| 16 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 17 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | .setName("info") |
| 19 | .setDescription("Shows moderator information about a user") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 20 | .addUserOption((option) => |
| 21 | option |
| 22 | .setName("user") |
| 23 | .setDescription("The user to get information about") |
| 24 | .setRequired(true) |
| 25 | ); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 26 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 27 | const types = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 28 | warn: { emoji: "PUNISH.WARN.YELLOW", text: "Warned" }, |
| 29 | mute: { emoji: "PUNISH.MUTE.YELLOW", text: "Muted" }, |
| 30 | unmute: { emoji: "PUNISH.MUTE.GREEN", text: "Unmuted" }, |
| 31 | join: { emoji: "MEMBER.JOIN", text: "Joined" }, |
| 32 | leave: { emoji: "MEMBER.LEAVE", text: "Left" }, |
| 33 | kick: { emoji: "MEMBER.KICK", text: "Kicked" }, |
| 34 | softban: { emoji: "PUNISH.SOFTBAN", text: "Softbanned" }, |
| 35 | ban: { emoji: "MEMBER.BAN", text: "Banned" }, |
| 36 | unban: { emoji: "MEMBER.UNBAN", text: "Unbanned" }, |
| 37 | purge: { emoji: "PUNISH.CLEARHISTORY", text: "Messages cleared" }, |
| 38 | nickname: { emoji: "PUNISH.NICKNAME.YELLOW", text: "Nickname changed" } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 40 | |
| 41 | function historyToString(history: HistorySchema) { |
| 42 | let s = `${getEmojiByName(types[history.type].emoji)} ${ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 43 | history.amount ? history.amount + " " : "" |
| 44 | }${types[history.type].text} on <t:${Math.round( |
| 45 | history.occurredAt.getTime() / 1000 |
| 46 | )}:F>`; |
| 47 | if (history.moderator) { |
| 48 | s += ` by <@${history.moderator}>`; |
| 49 | } |
| 50 | if (history.reason) { |
| 51 | s += `\n**Reason:**\n> ${history.reason}`; |
| 52 | } |
| 53 | if (history.before) { |
| 54 | s += `\n**Before:**\n> ${history.before}`; |
| 55 | } |
| 56 | if (history.after) { |
| 57 | s += `\n**After:**\n> ${history.after}`; |
| 58 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 59 | return s + "\n"; |
| 60 | } |
| 61 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 62 | class TimelineSection { |
| 63 | name: string; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 64 | content: { data: HistorySchema; rendered: string }[] = []; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 65 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 66 | addContent = (content: { data: HistorySchema; rendered: string }) => { |
| 67 | this.content.push(content); |
| 68 | return this; |
| 69 | }; |
| 70 | contentLength = () => { |
| 71 | return this.content.reduce((acc, cur) => acc + cur.rendered.length, 0); |
| 72 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 73 | generateName = () => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 74 | const first = Math.round( |
| 75 | this.content[0].data.occurredAt.getTime() / 1000 |
| 76 | ); |
| 77 | const last = Math.round( |
| 78 | this.content[this.content.length - 1].data.occurredAt.getTime() / |
| 79 | 1000 |
| 80 | ); |
| 81 | if (first === last) { |
| 82 | return (this.name = `<t:${first}:F>`); |
| 83 | } |
| 84 | return (this.name = `<t:${first}:F> - <t:${last}:F>`); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 85 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 88 | const monthNames = [ |
| 89 | "January", |
| 90 | "February", |
| 91 | "March", |
| 92 | "April", |
| 93 | "May", |
| 94 | "June", |
| 95 | "July", |
| 96 | "August", |
| 97 | "September", |
| 98 | "October", |
| 99 | "November", |
| 100 | "December" |
| 101 | ]; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 102 | |
| 103 | async function showHistory(member, interaction: CommandInteraction) { |
| 104 | let currentYear = new Date().getFullYear(); |
| 105 | let pageIndex = null; |
| 106 | let m, history, current; |
| 107 | let refresh = true; |
| 108 | let filteredTypes = []; |
| 109 | let openFilterPane = false; |
| 110 | while (true) { |
| 111 | if (refresh) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 112 | history = await client.database.history.read( |
| 113 | member.guild.id, |
| 114 | member.id, |
| 115 | currentYear |
| 116 | ); |
| 117 | history = history |
| 118 | .sort((a, b) => b.occurredAt.getTime() - a.occurredAt.getTime()) |
| 119 | .reverse(); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 120 | if (openFilterPane) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 121 | let tempFilteredTypes = filteredTypes; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 122 | if (filteredTypes.length === 0) { |
| 123 | tempFilteredTypes = Object.keys(types); |
| 124 | } |
| 125 | history = history.filter((h) => |
| 126 | tempFilteredTypes.includes(h.type) |
| 127 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 128 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 129 | refresh = false; |
| 130 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 131 | const groups: TimelineSection[] = []; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 132 | if (history.length > 0) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 133 | current = new TimelineSection(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 134 | history.forEach((event) => { |
| 135 | if ( |
| 136 | current.contentLength() + historyToString(event).length > |
| 137 | 2000 || |
| 138 | current.content.length === 5 |
| 139 | ) { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 140 | groups.push(current); |
| 141 | current.generateName(); |
| 142 | current = new TimelineSection(); |
| 143 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 144 | current.addContent({ |
| 145 | data: event, |
| 146 | rendered: historyToString(event) |
| 147 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 148 | }); |
| 149 | current.generateName(); |
| 150 | groups.push(current); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 151 | if (pageIndex === null) { |
| 152 | pageIndex = groups.length - 1; |
| 153 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 154 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 155 | const components = ( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 156 | openFilterPane |
| 157 | ? [ |
| 158 | new MessageActionRow().addComponents([ |
| 159 | new Discord.MessageSelectMenu() |
| 160 | .setOptions( |
| 161 | Object.entries(types).map(([key, value]) => ({ |
| 162 | label: value.text, |
| 163 | value: key, |
| 164 | default: filteredTypes.includes(key), |
| 165 | emoji: client.emojis.resolve( |
| 166 | getEmojiByName(value.emoji, "id") |
| 167 | ) |
| 168 | })) |
| 169 | ) |
| 170 | .setMinValues(1) |
| 171 | .setMaxValues(Object.keys(types).length) |
| 172 | .setCustomId("filter") |
| 173 | .setPlaceholder("Select at least one event") |
| 174 | ]) |
| 175 | ] |
| 176 | : [] |
| 177 | ).concat([ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 178 | new MessageActionRow().addComponents([ |
| 179 | new MessageButton() |
| 180 | .setCustomId("prevYear") |
| 181 | .setLabel((currentYear - 1).toString()) |
| 182 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 183 | .setStyle("SECONDARY"), |
| 184 | new MessageButton() |
| 185 | .setCustomId("prevPage") |
| 186 | .setLabel("Previous page") |
| 187 | .setStyle("PRIMARY"), |
| 188 | new MessageButton() |
| 189 | .setCustomId("today") |
| 190 | .setLabel("Today") |
| 191 | .setStyle("PRIMARY"), |
| 192 | new MessageButton() |
| 193 | .setCustomId("nextPage") |
| 194 | .setLabel("Next page") |
| 195 | .setStyle("PRIMARY") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 196 | .setDisabled( |
| 197 | pageIndex >= groups.length - 1 && |
| 198 | currentYear === new Date().getFullYear() |
| 199 | ), |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 200 | new MessageButton() |
| 201 | .setCustomId("nextYear") |
| 202 | .setLabel((currentYear + 1).toString()) |
| 203 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 204 | .setStyle("SECONDARY") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 205 | .setDisabled(currentYear === new Date().getFullYear()) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 206 | ]), |
| 207 | new MessageActionRow().addComponents([ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 208 | new MessageButton() |
| 209 | .setLabel("Mod notes") |
| 210 | .setCustomId("modNotes") |
| 211 | .setStyle("PRIMARY") |
| 212 | .setEmoji(getEmojiByName("ICONS.EDIT", "id")), |
| 213 | new MessageButton() |
| 214 | .setLabel("Filter") |
| 215 | .setCustomId("openFilter") |
| 216 | .setStyle(openFilterPane ? "SUCCESS" : "PRIMARY") |
| 217 | .setEmoji(getEmojiByName("ICONS.FILTER", "id")) |
| 218 | ]) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 219 | ]); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 220 | const end = |
| 221 | "\n\nJanuary " + |
| 222 | currentYear.toString() + |
| 223 | pageIndicator( |
| 224 | Math.max(groups.length, 1), |
| 225 | groups.length === 0 ? 1 : pageIndex |
| 226 | ) + |
| 227 | (currentYear === new Date().getFullYear() |
| 228 | ? monthNames[new Date().getMonth()] |
| 229 | : "December") + |
| 230 | " " + |
| 231 | currentYear.toString(); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 232 | if (groups.length > 0) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 233 | const toRender = groups[Math.min(pageIndex, groups.length - 1)]; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 234 | m = await interaction.editReply({ |
| 235 | embeds: [ |
| 236 | new EmojiEmbed() |
| 237 | .setEmoji("MEMBER.JOIN") |
| 238 | .setTitle( |
| 239 | "Moderation history for " + member.user.username |
| 240 | ) |
| 241 | .setDescription( |
| 242 | `**${toRender.name}**\n\n` + |
| 243 | toRender.content |
| 244 | .map((c) => c.rendered) |
| 245 | .join("\n") + |
| 246 | end |
| 247 | ) |
| 248 | .setStatus("Success") |
| 249 | .setFooter({ |
| 250 | text: |
| 251 | openFilterPane && filteredTypes.length |
| 252 | ? "Filters are currently enabled" |
| 253 | : "" |
| 254 | }) |
| 255 | ], |
| 256 | components: components |
| 257 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 258 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 259 | m = await interaction.editReply({ |
| 260 | embeds: [ |
| 261 | new EmojiEmbed() |
| 262 | .setEmoji("MEMBER.JOIN") |
| 263 | .setTitle( |
| 264 | "Moderation history for " + member.user.username |
| 265 | ) |
| 266 | .setDescription( |
| 267 | `**${currentYear}**\n\n*No events*` + "\n\n" + end |
| 268 | ) |
| 269 | .setStatus("Success") |
| 270 | .setFooter({ |
| 271 | text: |
| 272 | openFilterPane && filteredTypes.length |
| 273 | ? "Filters are currently enabled" |
| 274 | : "" |
| 275 | }) |
| 276 | ], |
| 277 | components: components |
| 278 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 279 | } |
| 280 | let i; |
| 281 | try { |
| 282 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 283 | } catch (e) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 284 | interaction.editReply({ |
| 285 | embeds: [ |
| 286 | new EmojiEmbed() |
| 287 | .setEmoji("MEMBER.JOIN") |
| 288 | .setTitle( |
| 289 | "Moderation history for " + member.user.username |
| 290 | ) |
| 291 | .setDescription(m.embeds[0].description) |
| 292 | .setStatus("Danger") |
| 293 | .setFooter({ text: "Message timed out" }) |
| 294 | ] |
| 295 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 296 | return 0; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 297 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 298 | i.deferUpdate(); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 299 | if (i.customId === "filter") { |
| 300 | filteredTypes = i.values; |
| 301 | pageIndex = null; |
| 302 | refresh = true; |
| 303 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 304 | if (i.customId === "prevYear") { |
| 305 | currentYear--; |
| 306 | pageIndex = null; |
| 307 | refresh = true; |
| 308 | } |
| 309 | if (i.customId === "nextYear") { |
| 310 | currentYear++; |
| 311 | pageIndex = null; |
| 312 | refresh = true; |
| 313 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 314 | if (i.customId === "prevPage") { |
| 315 | pageIndex--; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 316 | if (pageIndex < 0) { |
| 317 | pageIndex = null; |
| 318 | currentYear--; |
| 319 | refresh = true; |
| 320 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 321 | } |
| 322 | if (i.customId === "nextPage") { |
| 323 | pageIndex++; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 324 | if (pageIndex >= groups.length) { |
| 325 | pageIndex = 0; |
| 326 | currentYear++; |
| 327 | refresh = true; |
| 328 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 329 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 330 | if (i.customId === "today") { |
| 331 | currentYear = new Date().getFullYear(); |
| 332 | pageIndex = null; |
| 333 | refresh = true; |
| 334 | } |
| 335 | if (i.customId === "modNotes") { |
| 336 | return 1; |
| 337 | } |
| 338 | if (i.customId === "openFilter") { |
| 339 | openFilterPane = !openFilterPane; |
| 340 | refresh = true; |
| 341 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 345 | const callback = async ( |
| 346 | interaction: CommandInteraction |
| 347 | ): Promise<void | unknown> => { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 348 | let m; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 349 | const member = interaction.options.getMember("user") as Discord.GuildMember; |
| 350 | await interaction.reply({ |
| 351 | embeds: [ |
| 352 | new EmojiEmbed() |
| 353 | .setEmoji("NUCLEUS.LOADING") |
| 354 | .setTitle("Downloading Data") |
| 355 | .setStatus("Danger") |
| 356 | ], |
| 357 | ephemeral: true, |
| 358 | fetchReply: true |
| 359 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 360 | let note; |
| 361 | let firstLoad = true; |
| 362 | while (true) { |
| 363 | note = await client.database.notes.read(member.guild.id, member.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 364 | if (firstLoad && !note) { |
| 365 | await showHistory(member, interaction); |
| 366 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 367 | firstLoad = false; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 368 | m = await interaction.editReply({ |
| 369 | embeds: [ |
| 370 | new EmojiEmbed() |
| 371 | .setEmoji("MEMBER.JOIN") |
| 372 | .setTitle("Mod notes for " + member.user.username) |
| 373 | .setDescription(note ? note : "*No note set*") |
| 374 | .setStatus("Success") |
| 375 | ], |
| 376 | components: [ |
| 377 | new MessageActionRow().addComponents([ |
| 378 | new MessageButton() |
| 379 | .setLabel(`${note ? "Modify" : "Create"} note`) |
| 380 | .setStyle("PRIMARY") |
| 381 | .setCustomId("modify") |
| 382 | .setEmoji(getEmojiByName("ICONS.EDIT", "id")), |
| 383 | new MessageButton() |
| 384 | .setLabel("View moderation history") |
| 385 | .setStyle("PRIMARY") |
| 386 | .setCustomId("history") |
| 387 | .setEmoji(getEmojiByName("ICONS.HISTORY", "id")) |
| 388 | ]) |
| 389 | ] |
| 390 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 391 | let i; |
| 392 | try { |
| 393 | i = await m.awaitMessageComponent({ time: 300000 }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 394 | } catch (e) { |
| 395 | return; |
| 396 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 397 | if (i.customId === "modify") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 398 | await i.showModal( |
| 399 | new Discord.Modal() |
| 400 | .setCustomId("modal") |
| 401 | .setTitle("Editing moderator note") |
| 402 | .addComponents( |
| 403 | new MessageActionRow<TextInputComponent>().addComponents( |
| 404 | new TextInputComponent() |
| 405 | .setCustomId("note") |
| 406 | .setLabel("Note") |
| 407 | .setMaxLength(4000) |
| 408 | .setRequired(false) |
| 409 | .setStyle("PARAGRAPH") |
| 410 | .setValue(note ? note : "") |
| 411 | ) |
| 412 | ) |
| 413 | ); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 414 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 415 | embeds: [ |
| 416 | new EmojiEmbed() |
| 417 | .setTitle("Mod notes for " + member.user.username) |
| 418 | .setDescription( |
| 419 | "Modal opened. If you can't see it, click back and try again." |
| 420 | ) |
| 421 | .setStatus("Success") |
| 422 | .setEmoji("GUILD.TICKET.OPEN") |
| 423 | ], |
| 424 | components: [ |
| 425 | new MessageActionRow().addComponents([ |
| 426 | new MessageButton() |
| 427 | .setLabel("Back") |
| 428 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 429 | .setStyle("PRIMARY") |
| 430 | .setCustomId("back") |
| 431 | ]) |
| 432 | ] |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 433 | }); |
| 434 | let out; |
| 435 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 436 | out = await modalInteractionCollector( |
| 437 | m, |
| 438 | (m) => m.channel.id === interaction.channel.id, |
| 439 | (m) => m.customId === "modify" |
| 440 | ); |
| 441 | } catch (e) { |
| 442 | continue; |
| 443 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 444 | if (out.fields) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 445 | const toAdd = out.fields.getTextInputValue("note") || null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 446 | await client.database.notes.create( |
| 447 | member.guild.id, |
| 448 | member.id, |
| 449 | toAdd |
| 450 | ); |
| 451 | } else { |
| 452 | continue; |
| 453 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 454 | } else if (i.customId === "history") { |
| 455 | i.deferUpdate(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 456 | if (!(await showHistory(member, interaction))) return; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 457 | } |
| 458 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 459 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 460 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 461 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 462 | const member = interaction.member as GuildMember; |
| 463 | if (!member.permissions.has("MODERATE_MEMBERS")) |
| 464 | throw "You do not have the *Moderate Members* permission"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 465 | return true; |
| 466 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 467 | |
| 468 | export { command }; |
| 469 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 470 | export { check }; |