pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 1 | import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 2 | import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
| 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 | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 7 | |
| 8 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 9 | builder |
| 10 | .setName("about") |
| 11 | .setDescription("Shows info about a user") |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 12 | .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] | 13 | |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 14 | const callback = async (interaction: CommandInteraction) => { |
| 15 | // @ts-ignore |
| 16 | const { renderUser, renderDelta } = interaction.client.logger |
| 17 | let member = (interaction.options.getMember("user") || interaction.member) as Discord.GuildMember; |
| 18 | let flags: string[] = []; |
| 19 | if ([ |
| 20 | "438733159748599813", // Pinea |
| 21 | "317731855317336067", // Mini |
| 22 | "261900651230003201", // Coded |
| 23 | "511655498676699136", // Zan |
| 24 | ].includes(member.user.id)) { flags.push("NUCLEUSDEVELOPER") } |
| 25 | 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") } |
| 26 | member.user.flags.toArray().map(flag => { |
| 27 | flags.push(flag.toString()) |
| 28 | }) |
| 29 | if (member.user.bot === true) { flags.push("BOT") } |
| 30 | // Check if they are boosting the server |
| 31 | if (member.premiumSince) { flags.push("BOOSTER") } |
| 32 | let nameReplacements = { |
| 33 | "NUCLEUSDEVELOPER": "**Nucleus Developer**", |
| 34 | "CLICKSDEVELOPER": "Clicks Developer", |
| 35 | "HOUSE_BRAVERY": "Hypesquad Bravery", |
| 36 | "HOUSE_BRILLIANCE": "Hypesquad Brilliance", |
| 37 | "HOUSE_BALANCE": "Hypesquad Balance", |
| 38 | "HYPESQUAD_EVENTS": "Hypesquad Events", |
| 39 | "EARLY_SUPPORTER": "Early Supporter", |
| 40 | "BUGHUNTER_LEVEL_1": "Bug Hunter Level 1", |
| 41 | "BUGHUNTER_LEVEL_2": "Bug Hunter Level 2", |
| 42 | "PARTNERED_SERVER_OWNER": "Partnered Server Owner", |
| 43 | "DISCORD_EMPLOYEE": "Discord Staff", |
| 44 | "EARLY_VERIFIED_BOT_DEVELOPER": "Verified Bot Developer", |
| 45 | "BOT": "Bot", |
| 46 | "BOOSTER": "Server Booster" |
| 47 | } |
| 48 | let members = await interaction.guild.members.fetch() |
| 49 | let membersArray = [...members.values()] |
| 50 | membersArray.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp) |
| 51 | let joinPos = membersArray.findIndex(m => m.id === member.user.id) |
| 52 | |
| 53 | let roles = member.roles.cache.filter(r => r.id != interaction.guild.id).sort() |
| 54 | let s = ""; |
| 55 | let count = 0; |
| 56 | let ended = false |
| 57 | roles.map(item => { |
| 58 | if (ended) return; |
| 59 | let string = `<@&${item.id}>, ` |
| 60 | if(s.length + string.length > 1000) { |
| 61 | ended = true |
| 62 | s += `and ${roles.size - count} more` |
| 63 | return |
| 64 | }; |
| 65 | count ++ |
| 66 | s += string; |
| 67 | }) |
| 68 | if(s.length > 0 && !ended) s = s.slice(0, -2); |
| 69 | |
| 70 | let perms = "" |
| 71 | let permsArray = { |
| 72 | "ADMINISTRATOR": "Administrator", |
| 73 | "MANAGE_GUILD": "Manage Server", |
| 74 | "MANAGE_ROLES": "Manage Roles", |
| 75 | "MANAGE_CHANNELS": "Manage Channels", |
| 76 | "KICK_MEMBERS": "Kick Members", |
| 77 | "BAN_MEMBERS": "Ban Members", |
| 78 | "MODERATE_MEMBERS": "Moderate Members", |
| 79 | "MANAGE_NICKNAMES": "Manage Nicknames", |
| 80 | "MANAGE_WEBHOOKS": "Manage Webhooks", |
| 81 | "MANAGE_MESSAGES": "Manage Messages", |
| 82 | "VIEW_AUDIT_LOG": "View Audit Log", |
| 83 | "MENTION_EVERYONE": "Mention Everyone" |
| 84 | } |
| 85 | Object.keys(permsArray).map(perm => { |
| 86 | let hasPerm = member.permissions.has(perm as Discord.PermissionString) |
| 87 | perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n` |
| 88 | }) |
| 89 | |
| 90 | let embeds = [ |
| 91 | new generateEmojiEmbed() |
| 92 | .setTitle("User Info: General") |
| 93 | .setStatus("Success") |
| 94 | .setEmoji("MEMBER.JOIN") |
| 95 | .setDescription( |
| 96 | flags.map(flag => { |
| 97 | if (nameReplacements[flag]) { |
| 98 | return getEmojiByName(`BADGES.${flag}`) + " " + nameReplacements[flag]; |
| 99 | } |
| 100 | }).join("\n") + "\n\n" + |
| 101 | generateKeyValueList({ |
| 102 | "member": renderUser(member.user), |
| 103 | "nickname": member.nickname || "*None set*", |
| 104 | "id": `\`${member.id}\``, |
| 105 | "joined the server": renderDelta(member.joinedTimestamp), |
| 106 | "joined discord": renderDelta(member.user.createdTimestamp), |
| 107 | "boost status": member.premiumSince ? `Started boosting ${renderDelta(member.premiumSinceTimestamp)}` : "*Not boosting*", |
| 108 | "join position": `${joinPos + 1}` |
| 109 | }) |
| 110 | ) |
| 111 | .setThumbnail(await member.user.displayAvatarURL({dynamic: true})) |
| 112 | .setImage((await member.user.fetch()).bannerURL({format: "gif"})), |
| 113 | new generateEmojiEmbed() |
| 114 | .setTitle("User Info: Roles") |
| 115 | .setStatus("Success") |
| 116 | .setEmoji("GUILD.ROLES.CREATE") |
| 117 | .setDescription( |
| 118 | generateKeyValueList({ |
| 119 | "member": renderUser(member.user), |
| 120 | "id": `\`${member.id}\``, |
| 121 | "roles": `${member.roles.cache.size - 1}`, |
| 122 | }) + "\n" + |
| 123 | (s.length > 0 ? s : "*None*") |
| 124 | ) |
| 125 | .setThumbnail(await member.user.displayAvatarURL({dynamic: true})), |
| 126 | new generateEmojiEmbed() |
| 127 | .setTitle("User Info: Key Permissions") |
| 128 | .setStatus("Success") |
| 129 | .setEmoji("GUILD.ROLES.CREATE") |
| 130 | .setDescription( |
| 131 | generateKeyValueList({ |
| 132 | "member": renderUser(member.user), |
| 133 | "id": `\`${member.id}\``, |
| 134 | }) + "\n" + perms |
| 135 | ) |
| 136 | .setThumbnail(await member.user.displayAvatarURL({dynamic: true})) |
| 137 | ] |
| 138 | let m |
| 139 | m = await interaction.reply({embeds: [new generateEmojiEmbed().setTitle("Loading").setEmoji("NUCLEUS.LOADING").setStatus("Danger")], fetchReply: true, ephemeral: true}); |
| 140 | let page = 0 |
| 141 | while (true) { |
| 142 | await interaction.editReply({ |
| 143 | embeds: [embeds[page].setFooter({text: `Page ${page + 1} of ${embeds.length}`})], |
| 144 | components: [new MessageActionRow().addComponents([ |
| 145 | new MessageButton() |
| 146 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 147 | .setStyle("SECONDARY") |
| 148 | .setCustomId("left") |
| 149 | .setDisabled(page === 0), |
| 150 | new MessageButton() |
| 151 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 152 | .setCustomId("right") |
| 153 | .setStyle("SECONDARY") |
| 154 | .setDisabled(page === embeds.length - 1), |
| 155 | new MessageButton() |
| 156 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 157 | .setCustomId("close") |
| 158 | .setStyle("DANGER") |
| 159 | ])] |
| 160 | }) |
| 161 | let i |
| 162 | try { |
| 163 | i = await m.awaitMessageComponent({componentType: "BUTTON", time: 600000}); |
| 164 | } catch { break } |
| 165 | i.deferUpdate() |
| 166 | if (i.component.customId == "left") { |
| 167 | if (page > 0) page--; |
| 168 | } else if (i.component.customId == "right") { |
| 169 | if (page < embeds.length - 1) page++; |
| 170 | } else if (i.component.customId == "close") { |
| 171 | break; |
| 172 | } else { |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | await interaction.editReply({embeds: [m.embeds[0]], components: [new MessageActionRow().addComponents([ |
| 177 | new MessageButton() |
| 178 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 179 | .setStyle("SECONDARY") |
| 180 | .setCustomId("left") |
| 181 | .setDisabled(true), |
| 182 | new MessageButton() |
| 183 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 184 | .setCustomId("right") |
| 185 | .setStyle("SECONDARY") |
| 186 | .setDisabled(true), |
| 187 | new MessageButton() |
| 188 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 189 | .setCustomId("close") |
| 190 | .setStyle("PRIMARY") |
| 191 | .setDisabled(true) |
| 192 | ])]}) |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| 196 | return true; |
| 197 | } |
| 198 | |
| 199 | export { command }; |
| 200 | export { callback }; |
| 201 | export { check }; |