pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from './../../utils/defaultEmbeds.js'; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 2 | import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js"; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 3 | import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 4 | import { WrappedCheck } from "jshaiku"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 5 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 6 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
| 7 | import generateKeyValueList from "../../utils/generateKeyValueList.js"; |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 8 | import createPageIndicator from "../../utils/createPageIndicator.js"; |
PineappleFan | b3dd83c | 2022-06-17 10:53:48 +0100 | [diff] [blame] | 9 | import client from "../../utils/client.js" |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 10 | |
| 11 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 12 | builder |
| 13 | .setName("about") |
| 14 | .setDescription("Shows info about a user") |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 15 | .addUserOption(option => option.setName("user").setDescription("The user to get info about | Default: Yourself")) |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 16 | |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 17 | |
| 18 | class Embed { |
| 19 | embed: Discord.MessageEmbed; |
| 20 | title: string; |
| 21 | description: string = ""; |
| 22 | pageId: number = 0; |
| 23 | setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; } |
| 24 | setTitle(title: string) { this.title = title; return this; } |
| 25 | setDescription(description: string) { this.description = description; return this; } |
| 26 | setPageId(pageId: number) { this.pageId = pageId; return this; } |
| 27 | } |
| 28 | |
| 29 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 30 | const callback = async (interaction: CommandInteraction): Promise<any> => { |
PineappleFan | b3dd83c | 2022-06-17 10:53:48 +0100 | [diff] [blame] | 31 | const { renderUser, renderDelta } = client.logger |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 32 | let member = (interaction.options.getMember("user") || interaction.member) as Discord.GuildMember; |
| 33 | let flags: string[] = []; |
| 34 | if ([ |
| 35 | "438733159748599813", // Pinea |
| 36 | "317731855317336067", // Mini |
| 37 | "261900651230003201", // Coded |
| 38 | "511655498676699136", // Zan |
| 39 | ].includes(member.user.id)) { flags.push("NUCLEUSDEVELOPER") } |
PineappleFan | b3dd83c | 2022-06-17 10:53:48 +0100 | [diff] [blame] | 40 | if ((await client.guilds.cache.get("684492926528651336")?.members.fetch())?.filter(m => m.roles.cache.has("760896837866749972"))?.map(m => m.id).includes(member.user.id)) { flags.push("CLICKSDEVELOPER") } |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 41 | member.user.flags.toArray().map(flag => { |
| 42 | flags.push(flag.toString()) |
| 43 | }) |
| 44 | if (member.user.bot === true) { flags.push("BOT") } |
| 45 | // Check if they are boosting the server |
| 46 | if (member.premiumSince) { flags.push("BOOSTER") } |
| 47 | let nameReplacements = { |
| 48 | "NUCLEUSDEVELOPER": "**Nucleus Developer**", |
| 49 | "CLICKSDEVELOPER": "Clicks Developer", |
| 50 | "HOUSE_BRAVERY": "Hypesquad Bravery", |
| 51 | "HOUSE_BRILLIANCE": "Hypesquad Brilliance", |
| 52 | "HOUSE_BALANCE": "Hypesquad Balance", |
| 53 | "HYPESQUAD_EVENTS": "Hypesquad Events", |
| 54 | "EARLY_SUPPORTER": "Early Supporter", |
| 55 | "BUGHUNTER_LEVEL_1": "Bug Hunter Level 1", |
| 56 | "BUGHUNTER_LEVEL_2": "Bug Hunter Level 2", |
| 57 | "PARTNERED_SERVER_OWNER": "Partnered Server Owner", |
| 58 | "DISCORD_EMPLOYEE": "Discord Staff", |
| 59 | "EARLY_VERIFIED_BOT_DEVELOPER": "Verified Bot Developer", |
| 60 | "BOT": "Bot", |
| 61 | "BOOSTER": "Server Booster" |
| 62 | } |
| 63 | let members = await interaction.guild.members.fetch() |
| 64 | let membersArray = [...members.values()] |
| 65 | membersArray.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp) |
| 66 | let joinPos = membersArray.findIndex(m => m.id === member.user.id) |
| 67 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 68 | let roles = member.roles.cache.filter(r => r.id !== interaction.guild.id).sort() |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 69 | let s = ""; |
| 70 | let count = 0; |
| 71 | let ended = false |
| 72 | roles.map(item => { |
| 73 | if (ended) return; |
| 74 | let string = `<@&${item.id}>, ` |
| 75 | if(s.length + string.length > 1000) { |
| 76 | ended = true |
| 77 | s += `and ${roles.size - count} more` |
| 78 | return |
| 79 | }; |
| 80 | count ++ |
| 81 | s += string; |
| 82 | }) |
| 83 | if(s.length > 0 && !ended) s = s.slice(0, -2); |
| 84 | |
| 85 | let perms = "" |
| 86 | let permsArray = { |
| 87 | "ADMINISTRATOR": "Administrator", |
| 88 | "MANAGE_GUILD": "Manage Server", |
| 89 | "MANAGE_ROLES": "Manage Roles", |
| 90 | "MANAGE_CHANNELS": "Manage Channels", |
| 91 | "KICK_MEMBERS": "Kick Members", |
| 92 | "BAN_MEMBERS": "Ban Members", |
| 93 | "MODERATE_MEMBERS": "Moderate Members", |
| 94 | "MANAGE_NICKNAMES": "Manage Nicknames", |
| 95 | "MANAGE_WEBHOOKS": "Manage Webhooks", |
| 96 | "MANAGE_MESSAGES": "Manage Messages", |
| 97 | "VIEW_AUDIT_LOG": "View Audit Log", |
| 98 | "MENTION_EVERYONE": "Mention Everyone" |
| 99 | } |
| 100 | Object.keys(permsArray).map(perm => { |
| 101 | let hasPerm = member.permissions.has(perm as Discord.PermissionString) |
| 102 | perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n` |
| 103 | }) |
| 104 | |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 105 | let selectPaneOpen = false; |
| 106 | |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 107 | let embeds = [ |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 108 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 109 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 110 | .setTitle("User Info: General") |
| 111 | .setStatus("Success") |
| 112 | .setEmoji("MEMBER.JOIN") |
| 113 | .setDescription( |
| 114 | flags.map(flag => { |
| 115 | if (nameReplacements[flag]) { |
| 116 | return getEmojiByName(`BADGES.${flag}`) + " " + nameReplacements[flag]; |
| 117 | } |
| 118 | }).join("\n") + "\n\n" + |
| 119 | generateKeyValueList({ |
| 120 | "member": renderUser(member.user), |
| 121 | "nickname": member.nickname || "*None set*", |
| 122 | "id": `\`${member.id}\``, |
| 123 | "joined the server": renderDelta(member.joinedTimestamp), |
| 124 | "joined discord": renderDelta(member.user.createdTimestamp), |
| 125 | "boost status": member.premiumSince ? `Started boosting ${renderDelta(member.premiumSinceTimestamp)}` : "*Not boosting*", |
| 126 | "join position": `${joinPos + 1}` |
| 127 | }) |
| 128 | ) |
| 129 | .setThumbnail(await member.user.displayAvatarURL({dynamic: true})) |
| 130 | .setImage((await member.user.fetch()).bannerURL({format: "gif"})) |
| 131 | ).setTitle("General").setDescription("General information about the user").setPageId(0), |
| 132 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 133 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 134 | .setTitle("User Info: Roles") |
| 135 | .setStatus("Success") |
| 136 | .setEmoji("GUILD.ROLES.CREATE") |
| 137 | .setDescription( |
| 138 | generateKeyValueList({ |
| 139 | "member": renderUser(member.user), |
| 140 | "id": `\`${member.id}\``, |
| 141 | "roles": `${member.roles.cache.size - 1}`, |
| 142 | }) + "\n" + |
| 143 | (s.length > 0 ? s : "*None*") + "\n" |
| 144 | ) |
| 145 | .setThumbnail(await member.user.displayAvatarURL({dynamic: true})) |
| 146 | ).setTitle("Roles").setDescription("Roles the user has").setPageId(1), |
| 147 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 148 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 149 | .setTitle("User Info: Key Permissions") |
| 150 | .setStatus("Success") |
| 151 | .setEmoji("GUILD.ROLES.CREATE") |
| 152 | .setDescription( |
| 153 | generateKeyValueList({ |
| 154 | "member": renderUser(member.user), |
| 155 | "id": `\`${member.id}\``, |
| 156 | }) + "\n" + perms |
| 157 | ) |
| 158 | .setThumbnail(await member.user.displayAvatarURL({dynamic: true})) |
| 159 | ).setTitle("Key Permissions").setDescription("Key permissions the user has").setPageId(2), |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 160 | ] |
| 161 | let m |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 162 | m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true}); |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 163 | let page = 0 |
pineafan | 167bde3 | 2022-05-19 19:33:46 +0100 | [diff] [blame] | 164 | let breakReason = "" |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 165 | while (true) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 166 | let em = new Discord.MessageEmbed(embeds[page].embed) |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 167 | em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page)); |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 168 | let selectPane = [] |
| 169 | |
| 170 | if (selectPaneOpen) { |
| 171 | let options = []; |
| 172 | embeds.forEach(embed => { |
| 173 | options.push(new SelectMenuOption({ |
| 174 | label: embed.title, |
| 175 | value: embed.pageId.toString(), |
| 176 | description: embed.description || "", |
| 177 | })) |
| 178 | }) |
| 179 | selectPane = [new MessageActionRow().addComponents([ |
| 180 | new Discord.MessageSelectMenu() |
| 181 | .addOptions(options) |
| 182 | .setCustomId("page") |
| 183 | .setMaxValues(1) |
| 184 | .setPlaceholder("Choose a page...") |
| 185 | ])] |
| 186 | } |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 187 | await interaction.editReply({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 188 | embeds: [em], |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 189 | components: selectPane.concat([new MessageActionRow().addComponents([ |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 190 | new MessageButton() |
| 191 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 192 | .setStyle("SECONDARY") |
| 193 | .setCustomId("left") |
| 194 | .setDisabled(page === 0), |
| 195 | new MessageButton() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 196 | .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
| 197 | .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY") |
| 198 | .setCustomId("select") |
| 199 | .setDisabled(false), |
| 200 | new MessageButton() |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 201 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 202 | .setCustomId("right") |
| 203 | .setStyle("SECONDARY") |
| 204 | .setDisabled(page === embeds.length - 1), |
| 205 | new MessageButton() |
| 206 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 207 | .setCustomId("close") |
| 208 | .setStyle("DANGER") |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 209 | ])]) |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 210 | }) |
| 211 | let i |
| 212 | try { |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 213 | i = await m.awaitMessageComponent({time: 300000}); |
pineafan | 167bde3 | 2022-05-19 19:33:46 +0100 | [diff] [blame] | 214 | } catch { breakReason = "Message timed out"; break } |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 215 | i.deferUpdate() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 216 | if (i.component.customId === "left") { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 217 | if (page > 0) page--; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 218 | selectPaneOpen = false; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 219 | } else if (i.component.customId === "right") { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 220 | if (page < embeds.length - 1) page++; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 221 | selectPaneOpen = false; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 222 | } else if (i.component.customId === "select") { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 223 | selectPaneOpen = !selectPaneOpen; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 224 | } else if (i.component.customId === "close") { |
pineafan | 167bde3 | 2022-05-19 19:33:46 +0100 | [diff] [blame] | 225 | breakReason = "Message closed"; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 226 | break; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 227 | } else if (i.component.customId === "page") { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 228 | page = parseInt(i.values[0]); |
| 229 | selectPaneOpen = false; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 230 | } else { |
pineafan | 167bde3 | 2022-05-19 19:33:46 +0100 | [diff] [blame] | 231 | breakReason = "Message closed"; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | } |
pineafan | 167bde3 | 2022-05-19 19:33:46 +0100 | [diff] [blame] | 235 | let em = new Discord.MessageEmbed(embeds[page].embed) |
| 236 | em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page) + " | " + breakReason); |
| 237 | await interaction.editReply({embeds: [em], components: [new MessageActionRow().addComponents([ |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 238 | new MessageButton() |
| 239 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 240 | .setStyle("SECONDARY") |
| 241 | .setCustomId("left") |
| 242 | .setDisabled(true), |
| 243 | new MessageButton() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 244 | .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
| 245 | .setStyle("SECONDARY") |
| 246 | .setCustomId("select") |
| 247 | .setDisabled(true), |
| 248 | new MessageButton() |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 249 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 250 | .setCustomId("right") |
| 251 | .setStyle("SECONDARY") |
| 252 | .setDisabled(true), |
| 253 | new MessageButton() |
| 254 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 255 | .setCustomId("close") |
pineafan | 167bde3 | 2022-05-19 19:33:46 +0100 | [diff] [blame] | 256 | .setStyle("DANGER") |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 257 | .setDisabled(true) |
| 258 | ])]}) |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | export { command }; |
| 266 | export { callback }; |
| 267 | export { check }; |