Almost working about command
diff --git a/src/commands/user/about.ts b/src/commands/user/about.ts
index d62a426..f94fb24 100644
--- a/src/commands/user/about.ts
+++ b/src/commands/user/about.ts
@@ -2,12 +2,13 @@
import Discord, {
CommandInteraction,
GuildMember,
- Message,
ActionRowBuilder,
- Component,
ButtonBuilder,
MessageComponentInteraction,
- ButtonStyle
+ ButtonStyle,
+ PermissionResolvable,
+ APISelectMenuOption,
+ StringSelectMenuBuilder
} from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@@ -25,11 +26,12 @@
);
class Embed {
- embed: Discord.EmbedBuilder;
- title: string;
+ embed: EmojiEmbed = new EmojiEmbed();
+ title: string = "";
description = "";
pageId = 0;
- setEmbed(embed: Discord.EmbedBuilder) {
+
+ setEmbed(embed: EmojiEmbed) {
this.embed = embed;
return this;
}
@@ -48,9 +50,20 @@
}
const callback = async (interaction: CommandInteraction): Promise<void> => {
- if (!interaction.guild) return;
- const { renderUser, renderDelta } = client.logger;
+ const guild = interaction.guild!;
const member = (interaction.options.getMember("user") ?? interaction.member) as Discord.GuildMember;
+ await userAbout(guild, member, interaction);
+}
+
+async function userAbout(guild: Discord.Guild, member: Discord.GuildMember, interaction: Discord.CommandInteraction | Discord.ContextMenuCommandInteraction) {
+ await member.user.fetch()
+ await member.fetch()
+ await interaction.reply({
+ embeds: LoadingEmbed,
+ fetchReply: true,
+ ephemeral: true
+ });
+ const { renderUser, renderDelta } = client.logger;
const flags: string[] = [];
if (
[
@@ -70,33 +83,32 @@
) {
flags.push("CLICKSDEVELOPER");
}
- member.user.flags.toArray().map((flag) => {
- flags.push(flag.toString());
- });
- if (member.user.bot) {
- flags.push("BOT");
- }
+ if (member.user.flags) { member.user.flags.toArray().map((flag) => { flags.push(flag.toString()); }); }
+ if (member.user.bot) { flags.push("BOT"); }
// Check if they are boosting the server
- if (member.premiumSince) {
- flags.push("BOOSTER");
- }
- const nameReplacements = {
+ if (member.premiumSince) { flags.push("BOOSTER"); }
+ const nameReplacements: Record<string, string> = {
NUCLEUSDEVELOPER: "**Nucleus Developer**",
CLICKSDEVELOPER: "Clicks Developer",
- HOUSE_BRAVERY: "Hypesquad Bravery",
- HOUSE_BRILLIANCE: "Hypesquad Brilliance",
- HOUSE_BALANCE: "Hypesquad Balance",
- HYPESQUAD_EVENTS: "Hypesquad Events",
- EARLY_SUPPORTER: "Early Supporter",
- BUGHUNTER_LEVEL_1: "Bug Hunter Level 1",
- BUGHUNTER_LEVEL_2: "Bug Hunter Level 2",
- PARTNERED_SERVER_OWNER: "Partnered Server Owner",
- DISCORD_EMPLOYEE: "Discord Staff",
- EARLY_VERIFIED_BOT_DEVELOPER: "Verified Bot Developer",
BOT: "Bot",
- BOOSTER: "Server Booster"
+ BOOSTER: "Server Booster",
+ HypeSquadOnlineHouse1: "Hypesquad Bravery",
+ HypeSquadOnlineHouse2: "Hypesquad Brilliance",
+ HypeSquadOnlineHouse3: "Hypesquad Balance",
+ Hypesquad: "Hypesquad Events",
+ PremiumEarlySupporter: "Early Supporter",
+ BugHunterLevel1: "Bug Hunter Level 1",
+ BugHunterLevel2: "Bug Hunter Level 2",
+ Partner: "Partnered Server Owner",
+ Staff: "Discord Staff",
+ VerifiedDeveloper: "Verified Bot Developer"
+ // ActiveDeveloper
+ // CertifiedModerator
+ // Quarantined https://discord-api-types.dev/api/discord-api-types-v10/enum/UserFlags#Quarantined
+ // Spammer https://discord-api-types.dev/api/discord-api-types-v10/enum/UserFlags#Spammer
+ // VerifiedBot
};
- const members = await interaction.guild.members.fetch();
+ const members = await guild.members.fetch();
const membersArray = [...members.values()];
membersArray.sort((a, b) => {
if (a.joinedTimestamp === null) return 1;
@@ -105,7 +117,7 @@
});
const joinPos = membersArray.findIndex((m) => m.id === member.user.id);
- const roles = member.roles.cache.filter((r) => r.id !== interaction.guild!.id).sort();
+ const roles = member.roles.cache.filter((r) => r.id !== guild.id).sort();
let s = "";
let count = 0;
let ended = false;
@@ -122,22 +134,22 @@
if (s.length > 0 && !ended) s = s.slice(0, -2);
let perms = "";
- const permsArray = {
- ADMINISTRATOR: "Administrator",
- MANAGE_GUILD: "Manage Server",
- MANAGE_ROLES: "Manage Roles",
- MANAGE_CHANNELS: "Manage Channels",
- KICK_MEMBERS: "Kick Members",
- BAN_MEMBERS: "Ban Members",
- MODERATE_MEMBERS: "Moderate Members",
- MANAGE_NICKNAMES: "Manage Nicknames",
- MANAGE_WEBHOOKS: "Manage Webhooks",
- MANAGE_MESSAGES: "Manage Messages",
- VIEW_AUDIT_LOG: "View Audit Log",
- MENTION_EVERYONE: "Mention Everyone"
+ const permsArray: Record<string, string> = {
+ Administrator: "Administrator",
+ ManageGuild: "Manage Server",
+ ManageRoles: "Manage Roles",
+ ManageChannels: "Manage Channels",
+ KickMembers: "Kick Members",
+ BanMembers: "Ban Members",
+ ModerateMembers: "Moderate Members",
+ ManageNicknames: "Manage Nicknames",
+ ManageWebhooks: "Manage Webhooks",
+ ManageMessages: "Manage Messages",
+ ViewAuditLog: "View Audit Log",
+ MentionEveryone: "Mention Everyone"
};
Object.keys(permsArray).map((perm) => {
- const hasPerm = member.permissions.has(perm as Discord.PermissionString);
+ const hasPerm = member.permissions.has(perm as PermissionResolvable);
perms += `${getEmojiByName("CONTROL." + (hasPerm ? "TICK" : "CROSS"))} ${permsArray[perm]}\n`;
});
@@ -151,28 +163,26 @@
.setStatus("Success")
.setEmoji("MEMBER.JOIN")
.setDescription(
- flags
- .map((flag) => {
- if (nameReplacements[flag]) {
- return getEmojiByName(`BADGES.${flag}`) + " " + nameReplacements[flag];
- }
- })
- .join("\n") +
- "\n\n" +
- generateKeyValueList({
- member: renderUser(member.user),
- nickname: member.nickname ?? "*None set*",
- id: `\`${member.id}\``,
- "joined the server": renderDelta(member.joinedTimestamp),
- "joined discord": renderDelta(member.user.createdTimestamp),
- "boost status": member.premiumSince
- ? `Started boosting ${renderDelta(member.premiumSinceTimestamp)}`
- : "*Not boosting*",
- "join position": `${joinPos + 1}`
- })
+ flags.map((flag) => {
+ if (nameReplacements[flag]) {
+ const emoji = getEmojiByName(`BADGES.${flag}`)
+ if (emoji) return (emoji + " " + nameReplacements[flag] + "\n");
+ else return nameReplacements[flag] + "\n";
+ }
+ }).join("") + "\n" +
+ generateKeyValueList({
+ member: renderUser(member.user),
+ nickname: member.nickname ?? "*None set*",
+ id: `\`${member.id}\``,
+ "joined the server": renderDelta(member.joinedTimestamp!),
+ "joined discord": renderDelta(member.user.createdTimestamp),
+ "boost status": member.premiumSince
+ ? `Started boosting ${renderDelta(member.premiumSinceTimestamp!)}`
+ : "*Not boosting*",
+ "join position": `${joinPos + 1}`
+ })
)
- .setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
- .setImage((await member.user.fetch()).bannerURL({ format: "gif" }))
+ .setThumbnail(member.user.displayAvatarURL())
)
.setTitle("General")
.setDescription("General information about the user")
@@ -187,13 +197,12 @@
generateKeyValueList({
member: renderUser(member.user),
id: `\`${member.id}\``,
- roles: `${member.roles.cache.size - 1}`
+ roles: `${member.roles.cache.size - 1}` // FIXME
}) +
"\n" +
(s.length > 0 ? s : "*None*") +
"\n"
)
- .setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
)
.setTitle("Roles")
.setDescription("Roles the user has")
@@ -212,26 +221,24 @@
"\n" +
perms
)
- .setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
)
.setTitle("Key Permissions")
.setDescription("Key permissions the user has")
.setPageId(2)
];
- const m = (await interaction.reply({
- embeds: LoadingEmbed,
- fetchReply: true,
- ephemeral: true
- })) as Message;
+ if (member.user.bannerURL() ) { embeds[0]!.embed.setImage(member.user.bannerURL()!); }
let page = 0;
let timedOut = false;
+ for (const embed of embeds) {
+ embed.embed.setDescription(embed.embed.description + "\n" + createPageIndicator(embeds.length, embed.pageId));
+ }
while (!timedOut) {
- const em = new Discord.EmbedBuilder(embeds[page].embed);
- em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page));
- let selectPane = [];
+ const em = embeds[page]!.embed;
+
+ let selectPane: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
if (selectPaneOpen) {
- const options: MessageSelectOptionData[] = [];
+ const options: APISelectMenuOption[] = [];
embeds.forEach((embed) => {
options.push({
label: embed.title,
@@ -240,19 +247,19 @@
});
});
selectPane = [
- new ActionRowBuilder().addComponents([
- new Discord.SelectMenuBuilder()
+ new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
+ new Discord.StringSelectMenuBuilder()
.addOptions(options)
.setCustomId("page")
.setMaxValues(1)
.setPlaceholder("Choose a page...")
- ])
+ )
];
}
- await interaction.editReply({
+ const m = await interaction.editReply({
embeds: [em],
components: selectPane.concat([
- new ActionRowBuilder().addComponents([
+ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
.setStyle(ButtonStyle.Secondary)
@@ -279,21 +286,21 @@
continue;
}
i.deferUpdate();
- if ((i.component as Component).customId === "left") {
+ if (i.customId === "left") {
if (page > 0) page--;
selectPaneOpen = false;
- } else if ((i.component as Component).customId === "right") {
+ } else if (i.customId === "right") {
if (page < embeds.length - 1) page++;
selectPaneOpen = false;
- } else if ((i.component as Component).customId === "select") {
+ } else if (i.customId === "select") {
selectPaneOpen = !selectPaneOpen;
- } else if ((i.component as Component).customId === "page") {
- page = parseInt((i as SelectMenuInteraction).values[0]);
+ } else if (i.customId === "page" && i.isStringSelectMenu()) {
+ page = parseInt(i.values[0]!);
selectPaneOpen = false;
}
}
- const em = new Discord.EmbedBuilder(embeds[page].embed);
- em.setDescription(em.description + "\n" + createPageIndicator(embeds.length, page) + " | Message closed");
+ const em = embeds[page]!.embed;
+ em.setDescription(em.description + " | Message closed");
await interaction.editReply({
embeds: [em],
components: []
@@ -307,3 +314,4 @@
export { command };
export { callback };
export { check };
+export { userAbout };
\ No newline at end of file
diff --git a/src/config/emojis.json b/src/config/emojis.json
index fc90ce4..f29f383 100644
--- a/src/config/emojis.json
+++ b/src/config/emojis.json
@@ -179,18 +179,18 @@
"BADGES": {
"NUCLEUSDEVELOPER": "957722888360853595",
"CLICKSDEVELOPER": "957722888314683462",
- "HOUSE_BRAVERY": "775783765930016789",
- "HOUSE_BRILLIANCE": "775783766152577095",
- "HOUSE_BALANCE": "775783766303440937",
- "HYPESQUAD_EVENTS": "775783766194126908",
- "EARLY_SUPPORTER": "775783766055452693",
- "BUGHUNTER_LEVEL_1": "775783766252847154",
- "BUGHUNTER_LEVEL_2": "775783766130950234",
- "PARTNERED_SERVER_OWNER": "775783766178005033",
- "DISCORD_EMPLOYEE": "775783766383788082",
- "EARLY_VERIFIED_BOT_DEVELOPER": "775783766425600060",
"BOT": "776375959108190239",
- "BOOSTER": "775783766131605545"
+ "BOOSTER": "775783766131605545",
+ "HypeSquadOnlineHouse1": "775783765930016789",
+ "HypeSquadOnlineHouse2": "775783766152577095",
+ "HypeSquadOnlineHouse3": "775783766303440937",
+ "Hypesquad": "775783766194126908",
+ "PremiumEarlySupporter": "775783766055452693",
+ "BugHunterLevel1": "775783766252847154",
+ "BugHunterLevel2": "775783766130950234",
+ "Partner": "775783766178005033",
+ "Staff": "775783766383788082",
+ "VerifiedDeveloper": "775783766425600060"
},
"VOICE": {
"CONNECT": "784785219391193138",
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index 1f2241c..0193f6c 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -119,10 +119,10 @@
client.commands["contextCommands/user/" + context.command.name] = context;
- console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colours.green}Loaded ${file.name} [${i} / ${userFiles.length}]${colours.none}`)
+ console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colours.green}Loaded ${file.name} [${i} / ${totalFiles}]${colours.none}`)
} catch (e) {
errors++;
- console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colours.red}Failed to load ${file.name} [${i} / ${userFiles.length}]${colours.none}`)
+ console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colours.red}Failed to load ${file.name} [${i} / ${totalFiles}]${colours.none}`)
}
}
@@ -187,7 +187,7 @@
}
await registerCommandHandler();
await registerEvents();
- console.log(`${colours.green}Registered commands and events${colours.none}`)
+ console.log(`${colours.green}Registered commands, events and context menus${colours.none}`)
console.log(
(config.enableDevelopment ? `${colours.purple}Bot started in Development mode` :
`${colours.blue}Bot started in Production mode`) + colours.none)
diff --git a/src/utils/generateEmojiEmbed.ts b/src/utils/generateEmojiEmbed.ts
index e1b481a..c0f17ae 100644
--- a/src/utils/generateEmojiEmbed.ts
+++ b/src/utils/generateEmojiEmbed.ts
@@ -10,6 +10,7 @@
class EmojiEmbed extends EmbedBuilder {
_title = "";
_emoji: string | null = null;
+ description = "";
_generateTitle() {
if (this._emoji) { return `${getEmojiByName(this._emoji)} ${this._title}`; }
@@ -21,6 +22,11 @@
super.setTitle(this._generateTitle());
return this;
}
+ override setDescription(description: string) {
+ this.description = description;
+ super.setDescription(description);
+ return this;
+ }
setEmoji(emoji: string) {
this._emoji = emoji;
super.setTitle(this._generateTitle());