blob: 59ba2e6a1ca3fdacd089967e77090310d6deb0df [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +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";
pineafan63fc5e22022-08-04 22:04:10 +01009import client from "../../utils/client.js";
pineafan4f164f32022-02-26 22:07:12 +000010
11const command = (builder: SlashCommandSubcommandBuilder) =>
12 builder
pineafan63fc5e22022-08-04 22:04:10 +010013 .setName("about")
14 .setDescription("Shows info about a user")
15 .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;
pineafan63fc5e22022-08-04 22:04:10 +010021 description = "";
22 pageId = 0;
pineafanea063042022-05-19 19:08:44 +010023 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> => {
pineafan63fc5e22022-08-04 22:04:10 +010031 const { renderUser, renderDelta } = client.logger;
32 const member = (interaction.options.getMember("user") || interaction.member) as Discord.GuildMember;
33 const flags: string[] = [];
pineafan377794f2022-04-18 19:01:01 +010034 if ([
35 "438733159748599813", // Pinea
36 "317731855317336067", // Mini
37 "261900651230003201", // Coded
pineafan63fc5e22022-08-04 22:04:10 +010038 "511655498676699136" // Zan
39 ].includes(member.user.id)) { flags.push("NUCLEUSDEVELOPER"); }
40 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 => {
pineafan63fc5e22022-08-04 22:04:10 +010042 flags.push(flag.toString());
43 });
44 if (member.user.bot === true) { flags.push("BOT"); }
pineafan377794f2022-04-18 19:01:01 +010045 // Check if they are boosting the server
pineafan63fc5e22022-08-04 22:04:10 +010046 if (member.premiumSince) { flags.push("BOOSTER"); }
47 const nameReplacements = {
pineafan377794f2022-04-18 19:01:01 +010048 "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"
pineafan63fc5e22022-08-04 22:04:10 +010062 };
63 const members = await interaction.guild.members.fetch();
64 const membersArray = [...members.values()];
65 membersArray.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp);
66 const joinPos = membersArray.findIndex(m => m.id === member.user.id);
pineafan377794f2022-04-18 19:01:01 +010067
pineafan63fc5e22022-08-04 22:04:10 +010068 const 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;
pineafan63fc5e22022-08-04 22:04:10 +010071 let ended = false;
pineafan377794f2022-04-18 19:01:01 +010072 roles.map(item => {
73 if (ended) return;
pineafan63fc5e22022-08-04 22:04:10 +010074 const string = `<@&${item.id}>, `;
pineafan377794f2022-04-18 19:01:01 +010075 if(s.length + string.length > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +010076 ended = true;
77 s += `and ${roles.size - count} more`;
78 return;
79 }
80 count ++;
pineafan377794f2022-04-18 19:01:01 +010081 s += string;
pineafan63fc5e22022-08-04 22:04:10 +010082 });
pineafan377794f2022-04-18 19:01:01 +010083 if(s.length > 0 && !ended) s = s.slice(0, -2);
84
pineafan63fc5e22022-08-04 22:04:10 +010085 let perms = "";
86 const permsArray = {
pineafan377794f2022-04-18 19:01:01 +010087 "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"
pineafan63fc5e22022-08-04 22:04:10 +010099 };
pineafan377794f2022-04-18 19:01:01 +0100100 Object.keys(permsArray).map(perm => {
pineafan63fc5e22022-08-04 22:04:10 +0100101 const hasPerm = member.permissions.has(perm as Discord.PermissionString);
102 perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n`;
103 });
pineafan377794f2022-04-18 19:01:01 +0100104
pineafanea063042022-05-19 19:08:44 +0100105 let selectPaneOpen = false;
106
pineafan63fc5e22022-08-04 22:04:10 +0100107 const 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}\``,
pineafan63fc5e22022-08-04 22:04:10 +0100141 "roles": `${member.roles.cache.size - 1}`
pineafanea063042022-05-19 19:08:44 +0100142 }) + "\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),
pineafan63fc5e22022-08-04 22:04:10 +0100155 "id": `\`${member.id}\``
pineafanea063042022-05-19 19:08:44 +0100156 }) + "\n" + perms
157 )
158 .setThumbnail(await member.user.displayAvatarURL({dynamic: true}))
pineafan63fc5e22022-08-04 22:04:10 +0100159 ).setTitle("Key Permissions").setDescription("Key permissions the user has").setPageId(2)
160 ];
161 let m;
pineafane23c4ec2022-07-27 21:56:27 +0100162 m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true});
pineafan63fc5e22022-08-04 22:04:10 +0100163 let page = 0;
164 let breakReason = "";
pineafan377794f2022-04-18 19:01:01 +0100165 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100166 const em = new Discord.MessageEmbed(embeds[page].embed);
pineafan34369e62022-05-18 16:52:37 +0100167 em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page));
pineafan63fc5e22022-08-04 22:04:10 +0100168 let selectPane = [];
pineafanea063042022-05-19 19:08:44 +0100169
170 if (selectPaneOpen) {
pineafan63fc5e22022-08-04 22:04:10 +0100171 const options = [];
pineafanea063042022-05-19 19:08:44 +0100172 embeds.forEach(embed => {
173 options.push(new SelectMenuOption({
174 label: embed.title,
175 value: embed.pageId.toString(),
pineafan63fc5e22022-08-04 22:04:10 +0100176 description: embed.description || ""
177 }));
178 });
pineafanea063042022-05-19 19:08:44 +0100179 selectPane = [new MessageActionRow().addComponents([
180 new Discord.MessageSelectMenu()
181 .addOptions(options)
182 .setCustomId("page")
183 .setMaxValues(1)
184 .setPlaceholder("Choose a page...")
pineafan63fc5e22022-08-04 22:04:10 +0100185 ])];
pineafanea063042022-05-19 19:08:44 +0100186 }
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 ])])
pineafan63fc5e22022-08-04 22:04:10 +0100210 });
211 let i;
pineafan377794f2022-04-18 19:01:01 +0100212 try {
pineafanc6158ab2022-06-17 16:34:07 +0100213 i = await m.awaitMessageComponent({time: 300000});
pineafan63fc5e22022-08-04 22:04:10 +0100214 } catch { breakReason = "Message timed out"; break; }
215 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 }
pineafan63fc5e22022-08-04 22:04:10 +0100235 const em = new Discord.MessageEmbed(embeds[page].embed);
pineafan167bde32022-05-19 19:33:46 +0100236 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)
pineafan63fc5e22022-08-04 22:04:10 +0100258 ])]});
259};
pineafan4f164f32022-02-26 22:07:12 +0000260
261const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
262 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100263};
pineafan4f164f32022-02-26 22:07:12 +0000264
265export { command };
266export { callback };
267export { check };