blob: 82eda6a06bbcb60254a65658c11772e370073d4b [file] [log] [blame]
pineafane23c4ec2022-07-27 21:56:27 +01001import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
pineafan377794f2022-04-18 19:01:01 +01002import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafanea063042022-05-19 19:08:44 +01003import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan4f164f32022-02-26 22:07:12 +00004import { WrappedCheck } from "jshaiku";
pineafan4edb7762022-06-26 19:21:04 +01005import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan377794f2022-04-18 19:01:01 +01006import getEmojiByName from "../../utils/getEmojiByName.js";
7import generateKeyValueList from "../../utils/generateKeyValueList.js";
pineafan34369e62022-05-18 16:52:37 +01008import createPageIndicator from "../../utils/createPageIndicator.js";
PineappleFanb3dd83c2022-06-17 10:53:48 +01009import client from "../../utils/client.js"
pineafan4f164f32022-02-26 22:07:12 +000010
11const command = (builder: SlashCommandSubcommandBuilder) =>
12 builder
13 .setName("about")
14 .setDescription("Shows info about a user")
pineafan377794f2022-04-18 19:01:01 +010015 .addUserOption(option => option.setName("user").setDescription("The user to get info about | Default: Yourself"))
pineafan4f164f32022-02-26 22:07:12 +000016
pineafanea063042022-05-19 19:08:44 +010017
18class 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
pineafan4edb7762022-06-26 19:21:04 +010030const callback = async (interaction: CommandInteraction): Promise<any> => {
PineappleFanb3dd83c2022-06-17 10:53:48 +010031 const { renderUser, renderDelta } = client.logger
pineafan377794f2022-04-18 19:01:01 +010032 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") }
PineappleFanb3dd83c2022-06-17 10:53:48 +010040 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") }
pineafan377794f2022-04-18 19:01:01 +010041 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
pineafane23c4ec2022-07-27 21:56:27 +010068 let roles = member.roles.cache.filter(r => r.id !== interaction.guild.id).sort()
pineafan377794f2022-04-18 19:01:01 +010069 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
pineafanea063042022-05-19 19:08:44 +0100105 let selectPaneOpen = false;
106
pineafan377794f2022-04-18 19:01:01 +0100107 let embeds = [
pineafanea063042022-05-19 19:08:44 +0100108 new Embed()
pineafan4edb7762022-06-26 19:21:04 +0100109 .setEmbed(new EmojiEmbed()
pineafanea063042022-05-19 19:08:44 +0100110 .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()
pineafan4edb7762022-06-26 19:21:04 +0100133 .setEmbed(new EmojiEmbed()
pineafanea063042022-05-19 19:08:44 +0100134 .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()
pineafan4edb7762022-06-26 19:21:04 +0100148 .setEmbed(new EmojiEmbed()
pineafanea063042022-05-19 19:08:44 +0100149 .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),
pineafan377794f2022-04-18 19:01:01 +0100160 ]
161 let m
pineafane23c4ec2022-07-27 21:56:27 +0100162 m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true});
pineafan377794f2022-04-18 19:01:01 +0100163 let page = 0
pineafan167bde32022-05-19 19:33:46 +0100164 let breakReason = ""
pineafan377794f2022-04-18 19:01:01 +0100165 while (true) {
pineafanea063042022-05-19 19:08:44 +0100166 let em = new Discord.MessageEmbed(embeds[page].embed)
pineafan34369e62022-05-18 16:52:37 +0100167 em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page));
pineafanea063042022-05-19 19:08:44 +0100168 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 }
pineafan377794f2022-04-18 19:01:01 +0100187 await interaction.editReply({
pineafan34369e62022-05-18 16:52:37 +0100188 embeds: [em],
pineafanea063042022-05-19 19:08:44 +0100189 components: selectPane.concat([new MessageActionRow().addComponents([
pineafan377794f2022-04-18 19:01:01 +0100190 new MessageButton()
191 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
192 .setStyle("SECONDARY")
193 .setCustomId("left")
194 .setDisabled(page === 0),
195 new MessageButton()
pineafanea063042022-05-19 19:08:44 +0100196 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
197 .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
198 .setCustomId("select")
199 .setDisabled(false),
200 new MessageButton()
pineafan377794f2022-04-18 19:01:01 +0100201 .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")
pineafanea063042022-05-19 19:08:44 +0100209 ])])
pineafan377794f2022-04-18 19:01:01 +0100210 })
211 let i
212 try {
pineafanc6158ab2022-06-17 16:34:07 +0100213 i = await m.awaitMessageComponent({time: 300000});
pineafan167bde32022-05-19 19:33:46 +0100214 } catch { breakReason = "Message timed out"; break }
pineafan377794f2022-04-18 19:01:01 +0100215 i.deferUpdate()
pineafane23c4ec2022-07-27 21:56:27 +0100216 if (i.component.customId === "left") {
pineafan377794f2022-04-18 19:01:01 +0100217 if (page > 0) page--;
pineafanea063042022-05-19 19:08:44 +0100218 selectPaneOpen = false;
pineafane23c4ec2022-07-27 21:56:27 +0100219 } else if (i.component.customId === "right") {
pineafan377794f2022-04-18 19:01:01 +0100220 if (page < embeds.length - 1) page++;
pineafanea063042022-05-19 19:08:44 +0100221 selectPaneOpen = false;
pineafane23c4ec2022-07-27 21:56:27 +0100222 } else if (i.component.customId === "select") {
pineafanea063042022-05-19 19:08:44 +0100223 selectPaneOpen = !selectPaneOpen;
pineafane23c4ec2022-07-27 21:56:27 +0100224 } else if (i.component.customId === "close") {
pineafan167bde32022-05-19 19:33:46 +0100225 breakReason = "Message closed";
pineafan377794f2022-04-18 19:01:01 +0100226 break;
pineafane23c4ec2022-07-27 21:56:27 +0100227 } else if (i.component.customId === "page") {
pineafanea063042022-05-19 19:08:44 +0100228 page = parseInt(i.values[0]);
229 selectPaneOpen = false;
pineafan377794f2022-04-18 19:01:01 +0100230 } else {
pineafan167bde32022-05-19 19:33:46 +0100231 breakReason = "Message closed";
pineafan377794f2022-04-18 19:01:01 +0100232 break;
233 }
234 }
pineafan167bde32022-05-19 19:33:46 +0100235 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([
pineafan377794f2022-04-18 19:01:01 +0100238 new MessageButton()
239 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
240 .setStyle("SECONDARY")
241 .setCustomId("left")
242 .setDisabled(true),
243 new MessageButton()
pineafanea063042022-05-19 19:08:44 +0100244 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
245 .setStyle("SECONDARY")
246 .setCustomId("select")
247 .setDisabled(true),
248 new MessageButton()
pineafan377794f2022-04-18 19:01:01 +0100249 .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")
pineafan167bde32022-05-19 19:33:46 +0100256 .setStyle("DANGER")
pineafan377794f2022-04-18 19:01:01 +0100257 .setDisabled(true)
258 ])]})
pineafan4f164f32022-02-26 22:07:12 +0000259}
260
261const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
262 return true;
263}
264
265export { command };
266export { callback };
267export { check };