crra/discord/commands/Whois.ts

118 lines
5.0 KiB
TypeScript
Raw Normal View History

2024-10-31 02:38:28 -04:00
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
import { MemberModel } from "../../database/Member";
2024-10-24 22:05:13 -04:00
import Partner, {
PartnerCommissionType,
PartnerDepartment,
PartnerModel,
PartnerRoleType,
2024-10-31 02:38:28 -04:00
} from "../../database/Partner";
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember } from "discord.js";
import MemberUtil from "../../util/MemberUtil";
import EmojiConfig from "../../util/EmojiConfig";
2024-04-02 16:39:49 -04:00
export default class Whois extends DiscordInteractionCommand {
2024-10-24 22:05:13 -04:00
constructor() {
2024-10-31 02:38:28 -04:00
super("whois", "Retrieves information about a user.");
2024-10-24 22:05:13 -04:00
this.builder.addUserOption((option) =>
option
2024-10-31 02:38:28 -04:00
.setName("member")
.setDescription("The member to get information about.")
2024-10-24 22:05:13 -04:00
.setRequired(true)
);
}
2024-04-02 16:39:49 -04:00
2024-10-24 22:05:13 -04:00
public async execute(interaction: ChatInputCommandInteraction) {
// defer our reply and perform database/external API operations/lookups
await interaction.deferReply({ ephemeral: false });
2024-10-31 02:38:28 -04:00
const target = interaction.options.getUser("member", true);
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
2024-10-24 22:05:13 -04:00
const guildMember = await guild?.members.fetch(target.id);
const databaseMember = await MemberModel.findOne({ discordID: target.id });
const partner = await PartnerModel.findOne({ discordID: target.id });
// return an error if target was not located
if (!guildMember)
2024-10-31 02:38:28 -04:00
return interaction.editReply({ content: `Member target ${target.id} was not located.` });
2024-10-24 22:05:13 -04:00
// build our embed
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);
2024-10-31 02:38:28 -04:00
embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL });
2024-10-24 22:05:13 -04:00
// set the thumbnail to the user's avatar
embed.setThumbnail(guildMember.user.displayAvatarURL());
// initialize the description string
2024-10-31 02:38:28 -04:00
let embedDescription = "";
2024-10-24 22:05:13 -04:00
if (partner) {
// set the title to the partner's title if applicable
2024-10-31 02:38:28 -04:00
if (partner.title) embedDescription += `## __${EmojiConfig.LOC} ${partner.title}__\n`;
embedDescription += "### Partner Information\n";
if (partner.emailAddress) embedDescription += `**Email Address**: ${partner.emailAddress}\n`;
2024-10-24 22:05:13 -04:00
switch (partner.department) {
case PartnerDepartment.ENGINEERING:
2024-10-31 02:38:28 -04:00
embedDescription += "**Department**: Dept. of Engineering\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerDepartment.OPERATIONS:
2024-10-31 02:38:28 -04:00
embedDescription += "**Department**: Dept. of Operations\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerDepartment.INDEPENDENT_AGENCY:
2024-10-31 02:38:28 -04:00
embedDescription += "**Department**: Independent Agency/Contractor\n";
2024-10-24 22:05:13 -04:00
break;
}
switch (partner.commissionType) {
case PartnerCommissionType.TENURE:
2024-10-31 02:38:28 -04:00
embedDescription += "**Commission Type**: Tenure\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerCommissionType.PROVISIONAL:
2024-10-31 02:38:28 -04:00
embedDescription += "**Commission Type**: Provisional\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerCommissionType.CONTRACTUAL:
2024-10-31 02:38:28 -04:00
embedDescription += "**Commission Type**: Contractual/Independent/Collaborator\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerCommissionType.ACTING:
2024-10-31 02:38:28 -04:00
embedDescription += "**Commission Type**: Acting\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerCommissionType.INTERIM:
2024-10-31 02:38:28 -04:00
embedDescription += "**Commission Type**: Interim\n";
2024-10-24 22:05:13 -04:00
break;
case PartnerCommissionType.TRIAL:
2024-10-31 02:38:28 -04:00
embedDescription += "**Commission Type**: Trial/Intern\n";
2024-10-24 22:05:13 -04:00
break;
}
if (partner.directReport) {
if (partner.directReport instanceof Partner) {
embedDescription += `**Direct Report**: ${partner.directReport.title}\n`;
2024-10-24 20:40:08 -04:00
}
2024-10-24 22:05:13 -04:00
}
2024-04-02 16:39:49 -04:00
}
2024-10-24 22:05:13 -04:00
embed.setColor(guildMember.displayColor);
if (embedDescription?.length > 0) embed.setDescription(embedDescription);
// add status to embed
if (guildMember.presence?.status) {
// TODO: this currently doesn't work for some reason
switch (guildMember.presence.status) {
2024-10-31 02:38:28 -04:00
case "online":
embed.addFields({ name: "Status", value: "Online", inline: true });
2024-10-24 22:05:13 -04:00
break;
2024-10-31 02:38:28 -04:00
case "idle":
embed.addFields({ name: "Status", value: "Idle", inline: true });
2024-10-24 22:05:13 -04:00
break;
2024-10-31 02:38:28 -04:00
case "dnd":
embed.addFields({ name: "Status", value: "Do Not Disturb", inline: true });
2024-10-24 22:05:13 -04:00
break;
2024-10-31 02:38:28 -04:00
case "offline" || "invisible":
embed.addFields({ name: "Status", value: "Online", inline: true });
2024-10-24 22:05:13 -04:00
break;
default:
// TODO: decide what placeholder we should use for values that fall "out of range"
2024-10-31 02:38:28 -04:00
embed.addFields({ name: "Status", value: "", inline: true });
2024-10-24 22:05:13 -04:00
break;
}
}
embed.setFooter({
2024-10-31 02:38:28 -04:00
text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ""}`,
2024-10-24 22:05:13 -04:00
});
return await interaction.editReply({ embeds: [embed] });
}
2024-04-02 16:39:49 -04:00
}