blob: e43ecb7c93ace2d4495a8d97c2f4ef608c0e9ded [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed, Embed } from "../../utils/defaults.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01002import Discord, {
3 CommandInteraction,
4 GuildMember,
TheCodedProf21c08592022-09-13 14:14:43 -04005 ActionRowBuilder,
TheCodedProf21c08592022-09-13 14:14:43 -04006 ButtonBuilder,
Skyler Grey75ea9172022-08-06 10:22:23 +01007 MessageComponentInteraction,
PineaFanc729e762023-01-02 22:11:34 +00008 ButtonStyle,
9 PermissionResolvable,
10 APISelectMenuOption,
11 StringSelectMenuBuilder
Skyler Grey75ea9172022-08-06 10:22:23 +010012} from "discord.js";
PineaFan100df682023-01-02 13:26:08 +000013import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
pineafan4edb7762022-06-26 19:21:04 +010014import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
pineafan377794f2022-04-18 19:01:01 +010015import getEmojiByName from "../../utils/getEmojiByName.js";
16import generateKeyValueList from "../../utils/generateKeyValueList.js";
pineafan34369e62022-05-18 16:52:37 +010017import createPageIndicator from "../../utils/createPageIndicator.js";
pineafan63fc5e22022-08-04 22:04:10 +010018import client from "../../utils/client.js";
pineafan4f164f32022-02-26 22:07:12 +000019
20const command = (builder: SlashCommandSubcommandBuilder) =>
21 builder
pineafan63fc5e22022-08-04 22:04:10 +010022 .setName("about")
23 .setDescription("Shows info about a user")
Skyler Grey75ea9172022-08-06 10:22:23 +010024 .addUserOption((option) =>
Skyler Grey11236ba2022-08-08 21:13:33 +010025 option.setName("user").setDescription("The user to get info about | Default: Yourself")
Skyler Grey75ea9172022-08-06 10:22:23 +010026 );
pineafanea063042022-05-19 19:08:44 +010027
Skyler Grey1a67e182022-08-04 23:05:44 +010028const callback = async (interaction: CommandInteraction): Promise<void> => {
PineaFanc729e762023-01-02 22:11:34 +000029 const guild = interaction.guild!;
Skyler Grey11236ba2022-08-08 21:13:33 +010030 const member = (interaction.options.getMember("user") ?? interaction.member) as Discord.GuildMember;
PineaFanc729e762023-01-02 22:11:34 +000031 await userAbout(guild, member, interaction);
32}
33
34async function userAbout(guild: Discord.Guild, member: Discord.GuildMember, interaction: Discord.CommandInteraction | Discord.ContextMenuCommandInteraction) {
35 await member.user.fetch()
36 await member.fetch()
37 await interaction.reply({
38 embeds: LoadingEmbed,
39 fetchReply: true,
40 ephemeral: true
41 });
42 const { renderUser, renderDelta } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010043 const flags: string[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +010044 if (
45 [
46 "438733159748599813", // Pinea
47 "317731855317336067", // Mini
48 "261900651230003201", // Coded
49 "511655498676699136" // Zan
50 ].includes(member.user.id)
51 ) {
52 flags.push("NUCLEUSDEVELOPER");
53 }
54 if (
55 (await client.guilds.cache.get("684492926528651336")?.members.fetch())
Skyler Grey11236ba2022-08-08 21:13:33 +010056 ?.filter((m: GuildMember) => m.roles.cache.has("760896837866749972"))
Skyler Grey75ea9172022-08-06 10:22:23 +010057 ?.map((m: GuildMember) => m.id)
58 .includes(member.user.id)
59 ) {
60 flags.push("CLICKSDEVELOPER");
61 }
PineaFanc729e762023-01-02 22:11:34 +000062 if (member.user.flags) { member.user.flags.toArray().map((flag) => { flags.push(flag.toString()); }); }
63 if (member.user.bot) { flags.push("BOT"); }
pineafan377794f2022-04-18 19:01:01 +010064 // Check if they are boosting the server
PineaFanc729e762023-01-02 22:11:34 +000065 if (member.premiumSince) { flags.push("BOOSTER"); }
66 const nameReplacements: Record<string, string> = {
Skyler Grey75ea9172022-08-06 10:22:23 +010067 NUCLEUSDEVELOPER: "**Nucleus Developer**",
68 CLICKSDEVELOPER: "Clicks Developer",
Skyler Grey75ea9172022-08-06 10:22:23 +010069 BOT: "Bot",
PineaFanc729e762023-01-02 22:11:34 +000070 BOOSTER: "Server Booster",
71 HypeSquadOnlineHouse1: "Hypesquad Bravery",
72 HypeSquadOnlineHouse2: "Hypesquad Brilliance",
73 HypeSquadOnlineHouse3: "Hypesquad Balance",
74 Hypesquad: "Hypesquad Events",
75 PremiumEarlySupporter: "Early Supporter",
76 BugHunterLevel1: "Bug Hunter Level 1",
77 BugHunterLevel2: "Bug Hunter Level 2",
78 Partner: "Partnered Server Owner",
79 Staff: "Discord Staff",
PineaFana34d04b2023-01-03 22:05:42 +000080 VerifiedDeveloper: "Verified Bot Developer",
81 ActiveDeveloper: "Active Developer",
PineaFan538d3752023-01-12 21:48:23 +000082 Quarantined: "Quarantined [[What does this mean?]](https://support.discord.com/hc/en-us/articles/6461420677527)",
PineaFana34d04b2023-01-03 22:05:42 +000083 Spammer: "Likely Spammer"
PineaFanc729e762023-01-02 22:11:34 +000084 // CertifiedModerator
PineaFanc729e762023-01-02 22:11:34 +000085 // VerifiedBot
pineafan63fc5e22022-08-04 22:04:10 +010086 };
PineaFanc729e762023-01-02 22:11:34 +000087 const members = await guild.members.fetch();
pineafan63fc5e22022-08-04 22:04:10 +010088 const membersArray = [...members.values()];
Skyler Greyc634e2b2022-08-06 17:50:48 +010089 membersArray.sort((a, b) => {
90 if (a.joinedTimestamp === null) return 1;
91 if (b.joinedTimestamp === null) return -1;
92 return a.joinedTimestamp - b.joinedTimestamp;
93 });
Skyler Grey75ea9172022-08-06 10:22:23 +010094 const joinPos = membersArray.findIndex((m) => m.id === member.user.id);
pineafan377794f2022-04-18 19:01:01 +010095
PineaFanc729e762023-01-02 22:11:34 +000096 const roles = member.roles.cache.filter((r) => r.id !== guild.id).sort();
pineafan377794f2022-04-18 19:01:01 +010097 let s = "";
98 let count = 0;
pineafan63fc5e22022-08-04 22:04:10 +010099 let ended = false;
PineaFana34d04b2023-01-03 22:05:42 +0000100 for (const roleId of roles) {
101 const string = `<@&${roleId[1].id}>, `;
Skyler Grey75ea9172022-08-06 10:22:23 +0100102 if (s.length + string.length > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100103 ended = true;
104 s += `and ${roles.size - count} more`;
Skyler Greyc634e2b2022-08-06 17:50:48 +0100105 break;
pineafan63fc5e22022-08-04 22:04:10 +0100106 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100107 count++;
pineafan377794f2022-04-18 19:01:01 +0100108 s += string;
Skyler Greyc634e2b2022-08-06 17:50:48 +0100109 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100110 if (s.length > 0 && !ended) s = s.slice(0, -2);
pineafan377794f2022-04-18 19:01:01 +0100111
pineafan63fc5e22022-08-04 22:04:10 +0100112 let perms = "";
PineaFanc729e762023-01-02 22:11:34 +0000113 const permsArray: Record<string, string> = {
114 Administrator: "Administrator",
115 ManageGuild: "Manage Server",
116 ManageRoles: "Manage Roles",
117 ManageChannels: "Manage Channels",
118 KickMembers: "Kick Members",
119 BanMembers: "Ban Members",
120 ModerateMembers: "Moderate Members",
121 ManageNicknames: "Manage Nicknames",
122 ManageWebhooks: "Manage Webhooks",
123 ManageMessages: "Manage Messages",
124 ViewAuditLog: "View Audit Log",
125 MentionEveryone: "Mention Everyone"
pineafan63fc5e22022-08-04 22:04:10 +0100126 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100127 Object.keys(permsArray).map((perm) => {
PineaFanc729e762023-01-02 22:11:34 +0000128 const hasPerm = member.permissions.has(perm as PermissionResolvable);
Skyler Grey11236ba2022-08-08 21:13:33 +0100129 perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n`;
pineafan63fc5e22022-08-04 22:04:10 +0100130 });
pineafan377794f2022-04-18 19:01:01 +0100131
pineafanea063042022-05-19 19:08:44 +0100132 let selectPaneOpen = false;
133
pineafan63fc5e22022-08-04 22:04:10 +0100134 const embeds = [
pineafanea063042022-05-19 19:08:44 +0100135 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +0100136 .setEmbed(
137 new EmojiEmbed()
138 .setTitle("User Info: General")
139 .setStatus("Success")
140 .setEmoji("MEMBER.JOIN")
141 .setDescription(
PineaFanc729e762023-01-02 22:11:34 +0000142 flags.map((flag) => {
143 if (nameReplacements[flag]) {
144 const emoji = getEmojiByName(`BADGES.${flag}`)
145 if (emoji) return (emoji + " " + nameReplacements[flag] + "\n");
146 else return nameReplacements[flag] + "\n";
147 }
148 }).join("") + "\n" +
149 generateKeyValueList({
150 member: renderUser(member.user),
151 nickname: member.nickname ?? "*None set*",
152 id: `\`${member.id}\``,
153 "joined the server": renderDelta(member.joinedTimestamp!),
154 "joined discord": renderDelta(member.user.createdTimestamp),
155 "boost status": member.premiumSince
156 ? `Started boosting ${renderDelta(member.premiumSinceTimestamp!)}`
157 : "*Not boosting*",
158 "join position": `${joinPos + 1}`
159 })
Skyler Grey75ea9172022-08-06 10:22:23 +0100160 )
PineaFanc729e762023-01-02 22:11:34 +0000161 .setThumbnail(member.user.displayAvatarURL())
Skyler Grey75ea9172022-08-06 10:22:23 +0100162 )
163 .setTitle("General")
164 .setDescription("General information about the user")
165 .setPageId(0),
pineafanea063042022-05-19 19:08:44 +0100166 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +0100167 .setEmbed(
168 new EmojiEmbed()
169 .setTitle("User Info: Roles")
170 .setStatus("Success")
171 .setEmoji("GUILD.ROLES.CREATE")
172 .setDescription(
173 generateKeyValueList({
174 member: renderUser(member.user),
175 id: `\`${member.id}\``,
PineaFanc729e762023-01-02 22:11:34 +0000176 roles: `${member.roles.cache.size - 1}` // FIXME
Skyler Grey75ea9172022-08-06 10:22:23 +0100177 }) +
178 "\n" +
179 (s.length > 0 ? s : "*None*") +
180 "\n"
181 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100182 )
183 .setTitle("Roles")
184 .setDescription("Roles the user has")
185 .setPageId(1),
pineafanea063042022-05-19 19:08:44 +0100186 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +0100187 .setEmbed(
188 new EmojiEmbed()
189 .setTitle("User Info: Key Permissions")
190 .setStatus("Success")
191 .setEmoji("GUILD.ROLES.CREATE")
192 .setDescription(
193 generateKeyValueList({
194 member: renderUser(member.user),
195 id: `\`${member.id}\``
196 }) +
197 "\n" +
198 perms
199 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100200 )
201 .setTitle("Key Permissions")
202 .setDescription("Key permissions the user has")
203 .setPageId(2)
pineafan63fc5e22022-08-04 22:04:10 +0100204 ];
PineaFanc729e762023-01-02 22:11:34 +0000205 if (member.user.bannerURL() ) { embeds[0]!.embed.setImage(member.user.bannerURL()!); }
pineafan63fc5e22022-08-04 22:04:10 +0100206 let page = 0;
Skyler Greyad002172022-08-16 18:48:26 +0100207 let timedOut = false;
PineaFanc729e762023-01-02 22:11:34 +0000208 for (const embed of embeds) {
209 embed.embed.setDescription(embed.embed.description + "\n" + createPageIndicator(embeds.length, embed.pageId));
210 }
Skyler Greyad002172022-08-16 18:48:26 +0100211 while (!timedOut) {
PineaFanc729e762023-01-02 22:11:34 +0000212 const em = embeds[page]!.embed;
213
214 let selectPane: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafanea063042022-05-19 19:08:44 +0100215
216 if (selectPaneOpen) {
PineaFanc729e762023-01-02 22:11:34 +0000217 const options: APISelectMenuOption[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100218 embeds.forEach((embed) => {
Skyler Greyad002172022-08-16 18:48:26 +0100219 options.push({
220 label: embed.title,
221 value: embed.pageId.toString(),
222 description: embed.description || ""
223 });
pineafan63fc5e22022-08-04 22:04:10 +0100224 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100225 selectPane = [
PineaFanc729e762023-01-02 22:11:34 +0000226 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
227 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100228 .addOptions(options)
229 .setCustomId("page")
230 .setMaxValues(1)
231 .setPlaceholder("Choose a page...")
PineaFanc729e762023-01-02 22:11:34 +0000232 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100233 ];
pineafanea063042022-05-19 19:08:44 +0100234 }
PineaFanc729e762023-01-02 22:11:34 +0000235 const m = await interaction.editReply({
pineafan34369e62022-05-18 16:52:37 +0100236 embeds: [em],
Skyler Grey75ea9172022-08-06 10:22:23 +0100237 components: selectPane.concat([
PineaFanc729e762023-01-02 22:11:34 +0000238 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400239 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100240 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400241 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100242 .setCustomId("left")
243 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400244 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100245 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400246 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100247 .setCustomId("select")
248 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400249 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100250 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
251 .setCustomId("right")
TheCodedProf21c08592022-09-13 14:14:43 -0400252 .setStyle(ButtonStyle.Secondary)
Skyler Greyad002172022-08-16 18:48:26 +0100253 .setDisabled(page === embeds.length - 1)
Skyler Grey75ea9172022-08-06 10:22:23 +0100254 ])
255 ])
pineafan63fc5e22022-08-04 22:04:10 +0100256 });
Skyler Grey1a67e182022-08-04 23:05:44 +0100257 let i: MessageComponentInteraction;
pineafan377794f2022-04-18 19:01:01 +0100258 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000259 i = await m.awaitMessageComponent({
260 time: 300000,
261 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
262 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100263 } catch {
Skyler Greyad002172022-08-16 18:48:26 +0100264 timedOut = true;
265 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100266 }
pineafan63fc5e22022-08-04 22:04:10 +0100267 i.deferUpdate();
PineaFanc729e762023-01-02 22:11:34 +0000268 if (i.customId === "left") {
pineafan377794f2022-04-18 19:01:01 +0100269 if (page > 0) page--;
pineafanea063042022-05-19 19:08:44 +0100270 selectPaneOpen = false;
PineaFanc729e762023-01-02 22:11:34 +0000271 } else if (i.customId === "right") {
pineafan377794f2022-04-18 19:01:01 +0100272 if (page < embeds.length - 1) page++;
pineafanea063042022-05-19 19:08:44 +0100273 selectPaneOpen = false;
PineaFanc729e762023-01-02 22:11:34 +0000274 } else if (i.customId === "select") {
pineafanea063042022-05-19 19:08:44 +0100275 selectPaneOpen = !selectPaneOpen;
PineaFanc729e762023-01-02 22:11:34 +0000276 } else if (i.customId === "page" && i.isStringSelectMenu()) {
277 page = parseInt(i.values[0]!);
pineafanea063042022-05-19 19:08:44 +0100278 selectPaneOpen = false;
pineafan377794f2022-04-18 19:01:01 +0100279 }
280 }
PineaFanc729e762023-01-02 22:11:34 +0000281 const em = embeds[page]!.embed;
282 em.setDescription(em.description + " | Message closed");
Skyler Grey75ea9172022-08-06 10:22:23 +0100283 await interaction.editReply({
284 embeds: [em],
Skyler Greyad002172022-08-16 18:48:26 +0100285 components: []
Skyler Grey75ea9172022-08-06 10:22:23 +0100286 });
pineafan63fc5e22022-08-04 22:04:10 +0100287};
pineafan4f164f32022-02-26 22:07:12 +0000288
Skyler Grey1a67e182022-08-04 23:05:44 +0100289const check = () => {
pineafan4f164f32022-02-26 22:07:12 +0000290 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100291};
pineafan4f164f32022-02-26 22:07:12 +0000292
293export { command };
294export { callback };
Skyler Grey1a67e182022-08-04 23:05:44 +0100295export { check };
PineaFanc729e762023-01-02 22:11:34 +0000296export { userAbout };