blob: bdd73c4beea4dadcd2594aa73e80fbf42a27bbee [file] [log] [blame]
pineafan377794f2022-04-18 19:01:01 +01001import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafanea063042022-05-19 19:08:44 +01002import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan4f164f32022-02-26 22:07:12 +00003import { WrappedCheck } from "jshaiku";
pineafan377794f2022-04-18 19:01:01 +01004import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
5import getEmojiByName from "../../utils/getEmojiByName.js";
6import generateKeyValueList from "../../utils/generateKeyValueList.js";
pineafan34369e62022-05-18 16:52:37 +01007import createPageIndicator from "../../utils/createPageIndicator.js";
pineafan4f164f32022-02-26 22:07:12 +00008
9const command = (builder: SlashCommandSubcommandBuilder) =>
10 builder
11 .setName("about")
12 .setDescription("Shows info about a user")
pineafan377794f2022-04-18 19:01:01 +010013 .addUserOption(option => option.setName("user").setDescription("The user to get info about | Default: Yourself"))
pineafan4f164f32022-02-26 22:07:12 +000014
pineafanea063042022-05-19 19:08:44 +010015
16class 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
pineafan377794f2022-04-18 19:01:01 +010028const 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
pineafanea063042022-05-19 19:08:44 +0100104 let selectPaneOpen = false;
105
pineafan377794f2022-04-18 19:01:01 +0100106 let embeds = [
pineafanea063042022-05-19 19:08:44 +0100107 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),
pineafan377794f2022-04-18 19:01:01 +0100159 ]
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
pineafan167bde32022-05-19 19:33:46 +0100163 let breakReason = ""
pineafan377794f2022-04-18 19:01:01 +0100164 while (true) {
pineafanea063042022-05-19 19:08:44 +0100165 let em = new Discord.MessageEmbed(embeds[page].embed)
pineafan34369e62022-05-18 16:52:37 +0100166 em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page));
pineafanea063042022-05-19 19:08:44 +0100167 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 }
pineafan377794f2022-04-18 19:01:01 +0100186 await interaction.editReply({
pineafan34369e62022-05-18 16:52:37 +0100187 embeds: [em],
pineafanea063042022-05-19 19:08:44 +0100188 components: selectPane.concat([new MessageActionRow().addComponents([
pineafan377794f2022-04-18 19:01:01 +0100189 new MessageButton()
190 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
191 .setStyle("SECONDARY")
192 .setCustomId("left")
193 .setDisabled(page === 0),
194 new MessageButton()
pineafanea063042022-05-19 19:08:44 +0100195 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
196 .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
197 .setCustomId("select")
198 .setDisabled(false),
199 new MessageButton()
pineafan377794f2022-04-18 19:01:01 +0100200 .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")
pineafanea063042022-05-19 19:08:44 +0100208 ])])
pineafan377794f2022-04-18 19:01:01 +0100209 })
210 let i
211 try {
pineafanea063042022-05-19 19:08:44 +0100212 i = await m.awaitMessageComponent({time: 600000});
pineafan167bde32022-05-19 19:33:46 +0100213 } catch { breakReason = "Message timed out"; break }
pineafan377794f2022-04-18 19:01:01 +0100214 i.deferUpdate()
215 if (i.component.customId == "left") {
216 if (page > 0) page--;
pineafanea063042022-05-19 19:08:44 +0100217 selectPaneOpen = false;
pineafan377794f2022-04-18 19:01:01 +0100218 } else if (i.component.customId == "right") {
219 if (page < embeds.length - 1) page++;
pineafanea063042022-05-19 19:08:44 +0100220 selectPaneOpen = false;
221 } else if (i.component.customId == "select") {
222 selectPaneOpen = !selectPaneOpen;
pineafan377794f2022-04-18 19:01:01 +0100223 } else if (i.component.customId == "close") {
pineafan167bde32022-05-19 19:33:46 +0100224 breakReason = "Message closed";
pineafan377794f2022-04-18 19:01:01 +0100225 break;
pineafanea063042022-05-19 19:08:44 +0100226 } else if (i.component.customId == "page") {
227 page = parseInt(i.values[0]);
228 selectPaneOpen = false;
pineafan377794f2022-04-18 19:01:01 +0100229 } else {
pineafan167bde32022-05-19 19:33:46 +0100230 breakReason = "Message closed";
pineafan377794f2022-04-18 19:01:01 +0100231 break;
232 }
233 }
pineafan167bde32022-05-19 19:33:46 +0100234 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([
pineafan377794f2022-04-18 19:01:01 +0100237 new MessageButton()
238 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
239 .setStyle("SECONDARY")
240 .setCustomId("left")
241 .setDisabled(true),
242 new MessageButton()
pineafanea063042022-05-19 19:08:44 +0100243 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
244 .setStyle("SECONDARY")
245 .setCustomId("select")
246 .setDisabled(true),
247 new MessageButton()
pineafan377794f2022-04-18 19:01:01 +0100248 .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")
pineafan167bde32022-05-19 19:33:46 +0100255 .setStyle("DANGER")
pineafan377794f2022-04-18 19:01:01 +0100256 .setDisabled(true)
257 ])]})
pineafan4f164f32022-02-26 22:07:12 +0000258}
259
260const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
261 return true;
262}
263
264export { command };
265export { callback };
266export { check };