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