forked from engineering/crv2
finishes to Whois.ts
parent
3a2d5d44fc
commit
3b5b8db6c1
|
@ -1,14 +1,15 @@
|
|||
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
||||
import { MemberModel } from "../../database/Member";
|
||||
import { MemberAdditionalAcknowledgement, MemberModel } from "../../database/Member";
|
||||
import Partner, {
|
||||
PartnerCommissionType,
|
||||
PartnerDepartment,
|
||||
PartnerModel,
|
||||
PartnerRoleType,
|
||||
} from "../../database/Partner";
|
||||
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember } from "discord.js";
|
||||
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember, Snowflake } from "discord.js";
|
||||
import MemberUtil from "../../util/MemberUtil";
|
||||
import EmojiConfig from "../../util/EmojiConfig";
|
||||
import Formatters from "../../util/Formatters";
|
||||
|
||||
export default class Whois extends DiscordInteractionCommand {
|
||||
constructor() {
|
||||
|
@ -36,7 +37,7 @@ export default class Whois extends DiscordInteractionCommand {
|
|||
const embed = new EmbedBuilder();
|
||||
// if the role type is managerial, add a [k] to the end of the name
|
||||
// if the partner exists, set the iconURL to the organizational logo
|
||||
const formattedName = MemberUtil.formatName(guildMember, partner);
|
||||
const formattedName = Formatters.formatName(guildMember, partner);
|
||||
embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL });
|
||||
// set the thumbnail to the user's avatar
|
||||
embed.setThumbnail(guildMember.user.displayAvatarURL());
|
||||
|
@ -79,16 +80,23 @@ export default class Whois extends DiscordInteractionCommand {
|
|||
break;
|
||||
}
|
||||
if (partner.directReport) {
|
||||
if (partner.directReport instanceof Partner) {
|
||||
embedDescription += `**Direct Report**: ${partner.directReport.title}\n`;
|
||||
// fetch direct report object ref
|
||||
await partner.populate("directReport");
|
||||
// ensures that the population propagated correctly before adding to embed
|
||||
if (partner.directReport instanceof PartnerModel) {
|
||||
const directReportGuildMember = await guild?.members.fetch(
|
||||
partner.directReport.discordID as Snowflake
|
||||
);
|
||||
// fetches GuildMember for the direct report
|
||||
embedDescription += `**Direct Report**: ${directReportGuildMember ? Formatters.formatName(directReportGuildMember, partner.directReport).text + ", " : ""}${partner.directReport.title}\n`;
|
||||
}
|
||||
}
|
||||
}
|
||||
embed.setColor(guildMember.displayColor);
|
||||
if (embedDescription?.length > 0) embed.setDescription(embedDescription);
|
||||
if (embedDescription?.length > 0)
|
||||
embed.setDescription(`${embedDescription}\n\n<@${guildMember.id}>`);
|
||||
// add status to embed
|
||||
if (guildMember.presence?.status) {
|
||||
// TODO: this currently doesn't work for some reason
|
||||
switch (guildMember.presence.status) {
|
||||
case "online":
|
||||
embed.addFields({ name: "Status", value: "Online", inline: true });
|
||||
|
@ -99,7 +107,7 @@ export default class Whois extends DiscordInteractionCommand {
|
|||
case "dnd":
|
||||
embed.addFields({ name: "Status", value: "Do Not Disturb", inline: true });
|
||||
break;
|
||||
case "offline" || "invisible":
|
||||
case "offline":
|
||||
embed.addFields({ name: "Status", value: "Online", inline: true });
|
||||
break;
|
||||
default:
|
||||
|
@ -107,9 +115,87 @@ export default class Whois extends DiscordInteractionCommand {
|
|||
embed.addFields({ name: "Status", value: "", inline: true });
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
embed.addFields({ name: "Status", value: "Offline", inline: true });
|
||||
}
|
||||
|
||||
// calculations for joined / created at
|
||||
embed.addFields(
|
||||
{
|
||||
name: "Joined At",
|
||||
value: guildMember.joinedTimestamp
|
||||
? `<t:${Math.floor(guildMember.joinedTimestamp / 1000)}>`
|
||||
: "Invalid Date",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Created At",
|
||||
value: guildMember.user.createdTimestamp
|
||||
? `<t:${Math.floor(guildMember.user.createdTimestamp / 1000)}>`
|
||||
: "Invalid Date",
|
||||
inline: true,
|
||||
}
|
||||
);
|
||||
|
||||
// TODO: calculations for commscore
|
||||
embed.addFields({ name: "CommScore™", value: "[PLACEHOLDER]", inline: false });
|
||||
|
||||
// role calculation (sorting roles by their position)
|
||||
let roleString = "";
|
||||
for (const role of guildMember.roles.valueOf().sort((a, b) => b.position - a.position)) {
|
||||
roleString += `<@&${role[1].id}> `;
|
||||
}
|
||||
if (roleString) {
|
||||
embed.addFields({ name: "Roles", value: roleString });
|
||||
} else {
|
||||
embed.addFields({ name: "Roles", value: "None" });
|
||||
}
|
||||
|
||||
// listing permissions
|
||||
const serializedPermissions = guildMember.permissions.serialize();
|
||||
const permissionsArray: string[] = [];
|
||||
// adding serialized string representation of permissions to array to use in embed field
|
||||
if (serializedPermissions.Administrator) permissionsArray.push("Administrator");
|
||||
if (serializedPermissions.ManageGuild) permissionsArray.push("Manage Guild");
|
||||
if (serializedPermissions.ManageChannels) permissionsArray.push("Manage Channels");
|
||||
if (serializedPermissions.ManageRoles) permissionsArray.push("Manage Roles");
|
||||
if (serializedPermissions.ManageMessages) permissionsArray.push("Manage Messages");
|
||||
if (serializedPermissions.ManageEvents) permissionsArray.push("Manage Events");
|
||||
if (serializedPermissions.ManageNicknames) permissionsArray.push("Manage Nicknames");
|
||||
if (serializedPermissions.ManageEmojisAndStickers) permissionsArray.push("Manage Emojis");
|
||||
if (serializedPermissions.ManageWebhooks) permissionsArray.push("Manage Webhooks");
|
||||
if (serializedPermissions.ModerateMembers) permissionsArray.push("Moderate Members");
|
||||
if (serializedPermissions.BanMembers) permissionsArray.push("Ban Members");
|
||||
if (serializedPermissions.KickMembers) permissionsArray.push("Kick Members");
|
||||
if (serializedPermissions.DeafenMembers) permissionsArray.push("Deafen Members");
|
||||
|
||||
// setting key permissions embed field
|
||||
if (permissionsArray?.length > 0) {
|
||||
embed.addFields({ name: "Key Permissions", value: permissionsArray.join(", ") });
|
||||
}
|
||||
|
||||
// determining acknowledgements: MemberAdditionalAcknowledgement || "Guild Owner", "Guild Admin", "Guild Manager", "Guild Moderator"
|
||||
const acknowledgementsArray: MemberAdditionalAcknowledgement[] = [];
|
||||
if (guildMember.id === guildMember.guild.ownerId) {
|
||||
acknowledgementsArray.push("Guild Owner");
|
||||
} else if (serializedPermissions.Administrator) {
|
||||
acknowledgementsArray.push("Guild Admin");
|
||||
} else if (serializedPermissions.ManageGuild) {
|
||||
acknowledgementsArray.push("Guild Manager");
|
||||
} else if (serializedPermissions.ModerateMembers || serializedPermissions.ManageMessages) {
|
||||
acknowledgementsArray.push("Guild Moderator");
|
||||
}
|
||||
|
||||
if (partner?.canPerformDevCommands) {
|
||||
acknowledgementsArray.push("System Developer");
|
||||
}
|
||||
|
||||
// adding acknowledgements to embed
|
||||
if (acknowledgementsArray.length > 0) {
|
||||
embed.addFields({ name: "Acknowledgements", value: acknowledgementsArray.join(", ") });
|
||||
}
|
||||
embed.setFooter({
|
||||
text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ""}`,
|
||||
text: `Discord ID: ${guildMember.id}${databaseMember ? `| Internal ID: ${databaseMember?._id}` : ""}${partner ? ` | Partner ID: ${partner?.id}` : ""}`,
|
||||
});
|
||||
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
|
|
Loading…
Reference in New Issue