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"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 8 | |
| 9 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 10 | builder |
| 11 | .setName("about") |
| 12 | .setDescription("Shows info about a user") |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 13 | .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] | 14 | |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 15 | |
| 16 | class Embed { |
| 17 | embed: Discord.MessageEmbed; |
| 18 | title: string; |
| 19 | description: string = ""; |
| 20 | pageId: number = 0; |
| 21 | setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; } |
| 22 | setTitle(title: string) { this.title = title; return this; } |
| 23 | setDescription(description: string) { this.description = description; return this; } |
| 24 | setPageId(pageId: number) { this.pageId = pageId; return this; } |
| 25 | } |
| 26 | |
| 27 | |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 28 | const callback = async (interaction: CommandInteraction) => { |
| 29 | // @ts-ignore |
| 30 | const { renderUser, renderDelta } = interaction.client.logger |
| 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") } |
| 39 | if ((await interaction.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") } |
| 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 |
| 163 | while (true) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 164 | let em = new Discord.MessageEmbed(embeds[page].embed) |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 165 | em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page)); |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 166 | let selectPane = [] |
| 167 | |
| 168 | if (selectPaneOpen) { |
| 169 | let options = []; |
| 170 | embeds.forEach(embed => { |
| 171 | options.push(new SelectMenuOption({ |
| 172 | label: embed.title, |
| 173 | value: embed.pageId.toString(), |
| 174 | description: embed.description || "", |
| 175 | })) |
| 176 | }) |
| 177 | selectPane = [new MessageActionRow().addComponents([ |
| 178 | new Discord.MessageSelectMenu() |
| 179 | .addOptions(options) |
| 180 | .setCustomId("page") |
| 181 | .setMaxValues(1) |
| 182 | .setPlaceholder("Choose a page...") |
| 183 | ])] |
| 184 | } |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 185 | await interaction.editReply({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 186 | embeds: [em], |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 187 | components: selectPane.concat([new MessageActionRow().addComponents([ |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 188 | new MessageButton() |
| 189 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 190 | .setStyle("SECONDARY") |
| 191 | .setCustomId("left") |
| 192 | .setDisabled(page === 0), |
| 193 | new MessageButton() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 194 | .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
| 195 | .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY") |
| 196 | .setCustomId("select") |
| 197 | .setDisabled(false), |
| 198 | new MessageButton() |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 199 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 200 | .setCustomId("right") |
| 201 | .setStyle("SECONDARY") |
| 202 | .setDisabled(page === embeds.length - 1), |
| 203 | new MessageButton() |
| 204 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 205 | .setCustomId("close") |
| 206 | .setStyle("DANGER") |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 207 | ])]) |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 208 | }) |
| 209 | let i |
| 210 | try { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 211 | i = await m.awaitMessageComponent({time: 600000}); |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 212 | } catch { break } |
| 213 | i.deferUpdate() |
| 214 | if (i.component.customId == "left") { |
| 215 | if (page > 0) page--; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 216 | selectPaneOpen = false; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 217 | } else if (i.component.customId == "right") { |
| 218 | if (page < embeds.length - 1) page++; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 219 | selectPaneOpen = false; |
| 220 | } else if (i.component.customId == "select") { |
| 221 | selectPaneOpen = !selectPaneOpen; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 222 | } else if (i.component.customId == "close") { |
| 223 | break; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 224 | } else if (i.component.customId == "page") { |
| 225 | page = parseInt(i.values[0]); |
| 226 | selectPaneOpen = false; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 227 | } else { |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | await interaction.editReply({embeds: [m.embeds[0]], components: [new MessageActionRow().addComponents([ |
| 232 | new MessageButton() |
| 233 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 234 | .setStyle("SECONDARY") |
| 235 | .setCustomId("left") |
| 236 | .setDisabled(true), |
| 237 | new MessageButton() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame^] | 238 | .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
| 239 | .setStyle("SECONDARY") |
| 240 | .setCustomId("select") |
| 241 | .setDisabled(true), |
| 242 | new MessageButton() |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 243 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 244 | .setCustomId("right") |
| 245 | .setStyle("SECONDARY") |
| 246 | .setDisabled(true), |
| 247 | new MessageButton() |
| 248 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 249 | .setCustomId("close") |
| 250 | .setStyle("PRIMARY") |
| 251 | .setDisabled(true) |
| 252 | ])]}) |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| 256 | return true; |
| 257 | } |
| 258 | |
| 259 | export { command }; |
| 260 | export { callback }; |
| 261 | export { check }; |