blob: 788054e7562a2fa5cb10a1ca98c9bf94a0b1aa26 [file] [log] [blame]
pineafan377794f2022-04-18 19:01:01 +01001import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00002import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
3import { 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
pineafan377794f2022-04-18 19:01:01 +010015const callback = async (interaction: CommandInteraction) => {
16 // @ts-ignore
17 const { renderUser, renderDelta } = interaction.client.logger
18 let member = (interaction.options.getMember("user") || interaction.member) as Discord.GuildMember;
19 let flags: string[] = [];
20 if ([
21 "438733159748599813", // Pinea
22 "317731855317336067", // Mini
23 "261900651230003201", // Coded
24 "511655498676699136", // Zan
25 ].includes(member.user.id)) { flags.push("NUCLEUSDEVELOPER") }
26 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") }
27 member.user.flags.toArray().map(flag => {
28 flags.push(flag.toString())
29 })
30 if (member.user.bot === true) { flags.push("BOT") }
31 // Check if they are boosting the server
32 if (member.premiumSince) { flags.push("BOOSTER") }
33 let nameReplacements = {
34 "NUCLEUSDEVELOPER": "**Nucleus Developer**",
35 "CLICKSDEVELOPER": "Clicks Developer",
36 "HOUSE_BRAVERY": "Hypesquad Bravery",
37 "HOUSE_BRILLIANCE": "Hypesquad Brilliance",
38 "HOUSE_BALANCE": "Hypesquad Balance",
39 "HYPESQUAD_EVENTS": "Hypesquad Events",
40 "EARLY_SUPPORTER": "Early Supporter",
41 "BUGHUNTER_LEVEL_1": "Bug Hunter Level 1",
42 "BUGHUNTER_LEVEL_2": "Bug Hunter Level 2",
43 "PARTNERED_SERVER_OWNER": "Partnered Server Owner",
44 "DISCORD_EMPLOYEE": "Discord Staff",
45 "EARLY_VERIFIED_BOT_DEVELOPER": "Verified Bot Developer",
46 "BOT": "Bot",
47 "BOOSTER": "Server Booster"
48 }
49 let members = await interaction.guild.members.fetch()
50 let membersArray = [...members.values()]
51 membersArray.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp)
52 let joinPos = membersArray.findIndex(m => m.id === member.user.id)
53
54 let roles = member.roles.cache.filter(r => r.id != interaction.guild.id).sort()
55 let s = "";
56 let count = 0;
57 let ended = false
58 roles.map(item => {
59 if (ended) return;
60 let string = `<@&${item.id}>, `
61 if(s.length + string.length > 1000) {
62 ended = true
63 s += `and ${roles.size - count} more`
64 return
65 };
66 count ++
67 s += string;
68 })
69 if(s.length > 0 && !ended) s = s.slice(0, -2);
70
71 let perms = ""
72 let permsArray = {
73 "ADMINISTRATOR": "Administrator",
74 "MANAGE_GUILD": "Manage Server",
75 "MANAGE_ROLES": "Manage Roles",
76 "MANAGE_CHANNELS": "Manage Channels",
77 "KICK_MEMBERS": "Kick Members",
78 "BAN_MEMBERS": "Ban Members",
79 "MODERATE_MEMBERS": "Moderate Members",
80 "MANAGE_NICKNAMES": "Manage Nicknames",
81 "MANAGE_WEBHOOKS": "Manage Webhooks",
82 "MANAGE_MESSAGES": "Manage Messages",
83 "VIEW_AUDIT_LOG": "View Audit Log",
84 "MENTION_EVERYONE": "Mention Everyone"
85 }
86 Object.keys(permsArray).map(perm => {
87 let hasPerm = member.permissions.has(perm as Discord.PermissionString)
88 perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n`
89 })
90
91 let embeds = [
92 new generateEmojiEmbed()
93 .setTitle("User Info: General")
94 .setStatus("Success")
95 .setEmoji("MEMBER.JOIN")
96 .setDescription(
97 flags.map(flag => {
98 if (nameReplacements[flag]) {
99 return getEmojiByName(`BADGES.${flag}`) + " " + nameReplacements[flag];
100 }
101 }).join("\n") + "\n\n" +
102 generateKeyValueList({
103 "member": renderUser(member.user),
104 "nickname": member.nickname || "*None set*",
105 "id": `\`${member.id}\``,
106 "joined the server": renderDelta(member.joinedTimestamp),
107 "joined discord": renderDelta(member.user.createdTimestamp),
108 "boost status": member.premiumSince ? `Started boosting ${renderDelta(member.premiumSinceTimestamp)}` : "*Not boosting*",
109 "join position": `${joinPos + 1}`
110 })
111 )
112 .setThumbnail(await member.user.displayAvatarURL({dynamic: true}))
113 .setImage((await member.user.fetch()).bannerURL({format: "gif"})),
114 new generateEmojiEmbed()
115 .setTitle("User Info: Roles")
116 .setStatus("Success")
117 .setEmoji("GUILD.ROLES.CREATE")
118 .setDescription(
119 generateKeyValueList({
120 "member": renderUser(member.user),
121 "id": `\`${member.id}\``,
122 "roles": `${member.roles.cache.size - 1}`,
123 }) + "\n" +
pineafan34369e62022-05-18 16:52:37 +0100124 (s.length > 0 ? s : "*None*") + "\n"
pineafan377794f2022-04-18 19:01:01 +0100125 )
126 .setThumbnail(await member.user.displayAvatarURL({dynamic: true})),
127 new generateEmojiEmbed()
128 .setTitle("User Info: Key Permissions")
129 .setStatus("Success")
130 .setEmoji("GUILD.ROLES.CREATE")
131 .setDescription(
132 generateKeyValueList({
133 "member": renderUser(member.user),
134 "id": `\`${member.id}\``,
135 }) + "\n" + perms
136 )
137 .setThumbnail(await member.user.displayAvatarURL({dynamic: true}))
138 ]
139 let m
140 m = await interaction.reply({embeds: [new generateEmojiEmbed().setTitle("Loading").setEmoji("NUCLEUS.LOADING").setStatus("Danger")], fetchReply: true, ephemeral: true});
141 let page = 0
142 while (true) {
pineafan34369e62022-05-18 16:52:37 +0100143 let em = new Discord.MessageEmbed(embeds[page])
144 em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page));
pineafan377794f2022-04-18 19:01:01 +0100145 await interaction.editReply({
pineafan34369e62022-05-18 16:52:37 +0100146 embeds: [em],
pineafan377794f2022-04-18 19:01:01 +0100147 components: [new MessageActionRow().addComponents([
148 new MessageButton()
149 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
150 .setStyle("SECONDARY")
151 .setCustomId("left")
152 .setDisabled(page === 0),
153 new MessageButton()
154 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
155 .setCustomId("right")
156 .setStyle("SECONDARY")
157 .setDisabled(page === embeds.length - 1),
158 new MessageButton()
159 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
160 .setCustomId("close")
161 .setStyle("DANGER")
162 ])]
163 })
164 let i
165 try {
166 i = await m.awaitMessageComponent({componentType: "BUTTON", time: 600000});
167 } catch { break }
168 i.deferUpdate()
169 if (i.component.customId == "left") {
170 if (page > 0) page--;
171 } else if (i.component.customId == "right") {
172 if (page < embeds.length - 1) page++;
173 } else if (i.component.customId == "close") {
174 break;
175 } else {
176 break;
177 }
178 }
179 await interaction.editReply({embeds: [m.embeds[0]], components: [new MessageActionRow().addComponents([
180 new MessageButton()
181 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
182 .setStyle("SECONDARY")
183 .setCustomId("left")
184 .setDisabled(true),
185 new MessageButton()
186 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
187 .setCustomId("right")
188 .setStyle("SECONDARY")
189 .setDisabled(true),
190 new MessageButton()
191 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
192 .setCustomId("close")
193 .setStyle("PRIMARY")
194 .setDisabled(true)
195 ])]})
pineafan4f164f32022-02-26 22:07:12 +0000196}
197
198const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
199 return true;
200}
201
202export { command };
203export { callback };
204export { check };