blob: 4835cd1cf613067081e2351039e42b6373fee36c [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../../utils/defaultEmbeds.js";
Skyler Grey1a67e182022-08-04 23:05:44 +01002import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageActionRowComponent, MessageButton, MessageComponentInteraction, SelectMenuInteraction } from "discord.js";
pineafanea063042022-05-19 19:08:44 +01003import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan4edb7762022-06-26 19:21:04 +01004import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan377794f2022-04-18 19:01:01 +01005import getEmojiByName from "../../utils/getEmojiByName.js";
6import generateKeyValueList from "../../utils/generateKeyValueList.js";
pineafan34369e62022-05-18 16:52:37 +01007import createPageIndicator from "../../utils/createPageIndicator.js";
pineafan63fc5e22022-08-04 22:04:10 +01008import client from "../../utils/client.js";
pineafan4f164f32022-02-26 22:07:12 +00009
10const command = (builder: SlashCommandSubcommandBuilder) =>
11 builder
pineafan63fc5e22022-08-04 22:04:10 +010012 .setName("about")
13 .setDescription("Shows info about a user")
14 .addUserOption(option => option.setName("user").setDescription("The user to get info about | Default: Yourself"));
pineafan4f164f32022-02-26 22:07:12 +000015
pineafanea063042022-05-19 19:08:44 +010016
17class Embed {
18 embed: Discord.MessageEmbed;
19 title: string;
pineafan63fc5e22022-08-04 22:04:10 +010020 description = "";
21 pageId = 0;
pineafanea063042022-05-19 19:08:44 +010022 setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; }
23 setTitle(title: string) { this.title = title; return this; }
24 setDescription(description: string) { this.description = description; return this; }
25 setPageId(pageId: number) { this.pageId = pageId; return this; }
26}
27
28
Skyler Grey1a67e182022-08-04 23:05:44 +010029const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan63fc5e22022-08-04 22:04:10 +010030 const { renderUser, renderDelta } = client.logger;
31 const member = (interaction.options.getMember("user") || interaction.member) as Discord.GuildMember;
32 const flags: string[] = [];
pineafan377794f2022-04-18 19:01:01 +010033 if ([
34 "438733159748599813", // Pinea
35 "317731855317336067", // Mini
36 "261900651230003201", // Coded
pineafan63fc5e22022-08-04 22:04:10 +010037 "511655498676699136" // Zan
38 ].includes(member.user.id)) { flags.push("NUCLEUSDEVELOPER"); }
Skyler Grey1a67e182022-08-04 23:05:44 +010039 if ((await client.guilds.cache.get("684492926528651336")?.members.fetch())?.filter((m: GuildMember) => m.roles.cache.has("760896837866749972"))?.map((m: GuildMember) => m.id).includes(member.user.id)) { flags.push("CLICKSDEVELOPER"); }
pineafan377794f2022-04-18 19:01:01 +010040 member.user.flags.toArray().map(flag => {
pineafan63fc5e22022-08-04 22:04:10 +010041 flags.push(flag.toString());
42 });
43 if (member.user.bot === true) { flags.push("BOT"); }
pineafan377794f2022-04-18 19:01:01 +010044 // Check if they are boosting the server
pineafan63fc5e22022-08-04 22:04:10 +010045 if (member.premiumSince) { flags.push("BOOSTER"); }
46 const nameReplacements = {
pineafan377794f2022-04-18 19:01:01 +010047 "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"
pineafan63fc5e22022-08-04 22:04:10 +010061 };
62 const members = await interaction.guild.members.fetch();
63 const membersArray = [...members.values()];
64 membersArray.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp);
65 const joinPos = membersArray.findIndex(m => m.id === member.user.id);
pineafan377794f2022-04-18 19:01:01 +010066
pineafan63fc5e22022-08-04 22:04:10 +010067 const roles = member.roles.cache.filter(r => r.id !== interaction.guild.id).sort();
pineafan377794f2022-04-18 19:01:01 +010068 let s = "";
69 let count = 0;
pineafan63fc5e22022-08-04 22:04:10 +010070 let ended = false;
pineafan377794f2022-04-18 19:01:01 +010071 roles.map(item => {
72 if (ended) return;
pineafan63fc5e22022-08-04 22:04:10 +010073 const string = `<@&${item.id}>, `;
pineafan377794f2022-04-18 19:01:01 +010074 if(s.length + string.length > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +010075 ended = true;
76 s += `and ${roles.size - count} more`;
77 return;
78 }
79 count ++;
pineafan377794f2022-04-18 19:01:01 +010080 s += string;
pineafan63fc5e22022-08-04 22:04:10 +010081 });
pineafan377794f2022-04-18 19:01:01 +010082 if(s.length > 0 && !ended) s = s.slice(0, -2);
83
pineafan63fc5e22022-08-04 22:04:10 +010084 let perms = "";
85 const permsArray = {
pineafan377794f2022-04-18 19:01:01 +010086 "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"
pineafan63fc5e22022-08-04 22:04:10 +010098 };
pineafan377794f2022-04-18 19:01:01 +010099 Object.keys(permsArray).map(perm => {
pineafan63fc5e22022-08-04 22:04:10 +0100100 const hasPerm = member.permissions.has(perm as Discord.PermissionString);
101 perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n`;
102 });
pineafan377794f2022-04-18 19:01:01 +0100103
pineafanea063042022-05-19 19:08:44 +0100104 let selectPaneOpen = false;
105
pineafan63fc5e22022-08-04 22:04:10 +0100106 const embeds = [
pineafanea063042022-05-19 19:08:44 +0100107 new Embed()
pineafan4edb7762022-06-26 19:21:04 +0100108 .setEmbed(new EmojiEmbed()
pineafanea063042022-05-19 19:08:44 +0100109 .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 )
Skyler Grey1a67e182022-08-04 23:05:44 +0100128 .setThumbnail(member.user.displayAvatarURL({dynamic: true}))
pineafanea063042022-05-19 19:08:44 +0100129 .setImage((await member.user.fetch()).bannerURL({format: "gif"}))
130 ).setTitle("General").setDescription("General information about the user").setPageId(0),
131 new Embed()
pineafan4edb7762022-06-26 19:21:04 +0100132 .setEmbed(new EmojiEmbed()
pineafanea063042022-05-19 19:08:44 +0100133 .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}\``,
pineafan63fc5e22022-08-04 22:04:10 +0100140 "roles": `${member.roles.cache.size - 1}`
pineafanea063042022-05-19 19:08:44 +0100141 }) + "\n" +
142 (s.length > 0 ? s : "*None*") + "\n"
143 )
Skyler Grey1a67e182022-08-04 23:05:44 +0100144 .setThumbnail(member.user.displayAvatarURL({dynamic: true}))
pineafanea063042022-05-19 19:08:44 +0100145 ).setTitle("Roles").setDescription("Roles the user has").setPageId(1),
146 new Embed()
pineafan4edb7762022-06-26 19:21:04 +0100147 .setEmbed(new EmojiEmbed()
pineafanea063042022-05-19 19:08:44 +0100148 .setTitle("User Info: Key Permissions")
149 .setStatus("Success")
150 .setEmoji("GUILD.ROLES.CREATE")
151 .setDescription(
152 generateKeyValueList({
153 "member": renderUser(member.user),
pineafan63fc5e22022-08-04 22:04:10 +0100154 "id": `\`${member.id}\``
pineafanea063042022-05-19 19:08:44 +0100155 }) + "\n" + perms
156 )
Skyler Grey1a67e182022-08-04 23:05:44 +0100157 .setThumbnail(member.user.displayAvatarURL({dynamic: true}))
pineafan63fc5e22022-08-04 22:04:10 +0100158 ).setTitle("Key Permissions").setDescription("Key permissions the user has").setPageId(2)
159 ];
Skyler Grey1a67e182022-08-04 23:05:44 +0100160 const m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true});
pineafan63fc5e22022-08-04 22:04:10 +0100161 let page = 0;
162 let breakReason = "";
pineafan377794f2022-04-18 19:01:01 +0100163 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100164 const em = new Discord.MessageEmbed(embeds[page].embed);
pineafan34369e62022-05-18 16:52:37 +0100165 em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page));
pineafan63fc5e22022-08-04 22:04:10 +0100166 let selectPane = [];
pineafanea063042022-05-19 19:08:44 +0100167
168 if (selectPaneOpen) {
pineafan63fc5e22022-08-04 22:04:10 +0100169 const options = [];
pineafanea063042022-05-19 19:08:44 +0100170 embeds.forEach(embed => {
171 options.push(new SelectMenuOption({
172 label: embed.title,
173 value: embed.pageId.toString(),
pineafan63fc5e22022-08-04 22:04:10 +0100174 description: embed.description || ""
175 }));
176 });
pineafanea063042022-05-19 19:08:44 +0100177 selectPane = [new MessageActionRow().addComponents([
178 new Discord.MessageSelectMenu()
179 .addOptions(options)
180 .setCustomId("page")
181 .setMaxValues(1)
182 .setPlaceholder("Choose a page...")
pineafan63fc5e22022-08-04 22:04:10 +0100183 ])];
pineafanea063042022-05-19 19:08:44 +0100184 }
pineafan377794f2022-04-18 19:01:01 +0100185 await interaction.editReply({
pineafan34369e62022-05-18 16:52:37 +0100186 embeds: [em],
pineafanea063042022-05-19 19:08:44 +0100187 components: selectPane.concat([new MessageActionRow().addComponents([
pineafan377794f2022-04-18 19:01:01 +0100188 new MessageButton()
189 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
190 .setStyle("SECONDARY")
191 .setCustomId("left")
192 .setDisabled(page === 0),
193 new MessageButton()
pineafanea063042022-05-19 19:08:44 +0100194 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
195 .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
196 .setCustomId("select")
197 .setDisabled(false),
198 new MessageButton()
pineafan377794f2022-04-18 19:01:01 +0100199 .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")
pineafanea063042022-05-19 19:08:44 +0100207 ])])
pineafan63fc5e22022-08-04 22:04:10 +0100208 });
Skyler Grey1a67e182022-08-04 23:05:44 +0100209 let i: MessageComponentInteraction;
pineafan377794f2022-04-18 19:01:01 +0100210 try {
Skyler Grey1a67e182022-08-04 23:05:44 +0100211 i = await (m as Message).awaitMessageComponent({time: 300000});
pineafan63fc5e22022-08-04 22:04:10 +0100212 } catch { breakReason = "Message timed out"; break; }
213 i.deferUpdate();
Skyler Grey1a67e182022-08-04 23:05:44 +0100214 if ((i.component as MessageActionRowComponent).customId === "left") {
pineafan377794f2022-04-18 19:01:01 +0100215 if (page > 0) page--;
pineafanea063042022-05-19 19:08:44 +0100216 selectPaneOpen = false;
Skyler Grey1a67e182022-08-04 23:05:44 +0100217 } else if ((i.component as MessageActionRowComponent).customId === "right") {
pineafan377794f2022-04-18 19:01:01 +0100218 if (page < embeds.length - 1) page++;
pineafanea063042022-05-19 19:08:44 +0100219 selectPaneOpen = false;
Skyler Grey1a67e182022-08-04 23:05:44 +0100220 } else if ((i.component as MessageActionRowComponent).customId === "select") {
pineafanea063042022-05-19 19:08:44 +0100221 selectPaneOpen = !selectPaneOpen;
Skyler Grey1a67e182022-08-04 23:05:44 +0100222 } else if ((i.component as MessageActionRowComponent).customId === "close") {
pineafan167bde32022-05-19 19:33:46 +0100223 breakReason = "Message closed";
pineafan377794f2022-04-18 19:01:01 +0100224 break;
Skyler Grey1a67e182022-08-04 23:05:44 +0100225 } else if ((i.component as MessageActionRowComponent).customId === "page") {
226 page = parseInt((i as SelectMenuInteraction).values[0]);
pineafanea063042022-05-19 19:08:44 +0100227 selectPaneOpen = false;
pineafan377794f2022-04-18 19:01:01 +0100228 } else {
pineafan167bde32022-05-19 19:33:46 +0100229 breakReason = "Message closed";
pineafan377794f2022-04-18 19:01:01 +0100230 break;
231 }
232 }
pineafan63fc5e22022-08-04 22:04:10 +0100233 const em = new Discord.MessageEmbed(embeds[page].embed);
pineafan167bde32022-05-19 19:33:46 +0100234 em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page) + " | " + breakReason);
235 await interaction.editReply({embeds: [em], components: [new MessageActionRow().addComponents([
pineafan377794f2022-04-18 19:01:01 +0100236 new MessageButton()
237 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
238 .setStyle("SECONDARY")
239 .setCustomId("left")
240 .setDisabled(true),
241 new MessageButton()
pineafanea063042022-05-19 19:08:44 +0100242 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
243 .setStyle("SECONDARY")
244 .setCustomId("select")
245 .setDisabled(true),
246 new MessageButton()
pineafan377794f2022-04-18 19:01:01 +0100247 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
248 .setCustomId("right")
249 .setStyle("SECONDARY")
250 .setDisabled(true),
251 new MessageButton()
252 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
253 .setCustomId("close")
pineafan167bde32022-05-19 19:33:46 +0100254 .setStyle("DANGER")
pineafan377794f2022-04-18 19:01:01 +0100255 .setDisabled(true)
pineafan63fc5e22022-08-04 22:04:10 +0100256 ])]});
257};
pineafan4f164f32022-02-26 22:07:12 +0000258
Skyler Grey1a67e182022-08-04 23:05:44 +0100259const check = () => {
pineafan4f164f32022-02-26 22:07:12 +0000260 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100261};
pineafan4f164f32022-02-26 22:07:12 +0000262
263export { command };
264export { callback };
Skyler Grey1a67e182022-08-04 23:05:44 +0100265export { check };