From 98c1e8377031d514f08c5803a4e1acb2c8b27405 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 2 Apr 2024 16:39:49 -0400 Subject: [PATCH] add Whois.ts command (TODO) --- discord/commands/Whois.ts | 81 +++++++++++++++++++++++++++++++++++++++ discord/commands/index.ts | 1 + 2 files changed, 82 insertions(+) create mode 100644 discord/commands/Whois.ts diff --git a/discord/commands/Whois.ts b/discord/commands/Whois.ts new file mode 100644 index 0000000..b7d3174 --- /dev/null +++ b/discord/commands/Whois.ts @@ -0,0 +1,81 @@ +import DiscordInteractionCommand from "../../util/DiscordInteractionCommand"; +import { MemberModel } from "../../database/Member"; +import Partner, {PartnerCommissionType, PartnerDepartment, PartnerModel, PartnerRoleType} from "../../database/Partner"; +import { ChatInputCommandInteraction, EmbedBuilder } from "discord.js"; +import MemberUtil from "../../util/MemberUtil"; + +export default class Whois extends DiscordInteractionCommand { + constructor() { + super("whois", "Retrieves information about a user."); + this.builder.addUserOption(option => option.setName("member").setDescription("The member to get information about.").setRequired(true)); + } + + public async execute(interaction: ChatInputCommandInteraction) { + // defer our reply and perform database/external API operations/lookups + await interaction.deferReply({ ephemeral: false }); + const target = interaction.options.getUser("member", true); + const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID); + 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) return interaction.editReply({ content: `Member target ${target.id} was not located.`}); + // 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); + embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL }); + // set the title to the partner's title if applicable + if (partner?.title) embed.setTitle(partner.title); + // set the thumbnail to the user's avatar + embed.setThumbnail(guildMember.user.displayAvatarURL()); + // initialize the description string + let embedDescription = ''; + if (partner) { + embedDescription += "__**Partner Information**__\n"; + if (partner.emailAddress) embedDescription += `**Email Address**: ${partner.emailAddress}\n`; + switch (partner.department) { + case PartnerDepartment.ENGINEERING: + embedDescription += "**Department**: Dept. of Engineering\n"; + break; + case PartnerDepartment.OPERATIONS: + embedDescription += "**Department**: Dept. of Operations\n"; + break; + case PartnerDepartment.INDEPENDENT_AGENCY: + embedDescription += "**Department**: Independent Agency/Contractor\n"; + break; + } + switch (partner.commissionType) { + case PartnerCommissionType.TENURE: + embedDescription += "**Commission Type**: Tenure\n"; + break; + case PartnerCommissionType.PROVISIONAL: + embedDescription += "**Commission Type**: Provisional\n"; + break; + case PartnerCommissionType.CONTRACTUAL: + embedDescription += "**Commission Type**: Contractual/Independent/Collaborator\n"; + break; + case PartnerCommissionType.ACTING: + embedDescription += "**Commission Type**: Acting\n"; + break; + case PartnerCommissionType.INTERIM: + embedDescription += "**Commission Type**: Interim\n"; + break; + case PartnerCommissionType.TRIAL: + embedDescription += "**Commission Type**: Trial/Intern\n"; + break; + } + if (partner.directReport) { + if (partner.directReport instanceof Partner) { + embedDescription += `**Direct Report**: ${partner.directReport.title}\n`; + } + } + } + embed.setColor(guildMember.displayColor); + embed.setDescription(embedDescription); + embed.setFooter({ text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ''}` }); + + return await interaction.editReply({ embeds: [embed] }); + } +} diff --git a/discord/commands/index.ts b/discord/commands/index.ts index 7c55397..eefa235 100644 --- a/discord/commands/index.ts +++ b/discord/commands/index.ts @@ -1 +1,2 @@ export { default as Ping } from "./Ping"; +export { default as Whois } from "./Whois";