forked from engineering/crv2
strings are always truthy fix
parent
c40f26c640
commit
f27ec17bed
|
@ -1,103 +1,139 @@
|
||||||
import DiscordInteractionCommand from "../../util/DiscordInteractionCommand";
|
import DiscordInteractionCommand from '../../util/DiscordInteractionCommand';
|
||||||
import { MemberModel } from "../../database/Member";
|
import { MemberModel } from '../../database/Member';
|
||||||
import Partner, { PartnerCommissionType, PartnerDepartment, PartnerModel, PartnerRoleType } from "../../database/Partner";
|
import Partner, {
|
||||||
import { ChatInputCommandInteraction, EmbedBuilder, GuildMember } from "discord.js";
|
PartnerCommissionType,
|
||||||
import MemberUtil from "../../util/MemberUtil";
|
PartnerDepartment,
|
||||||
import EmojiConfig from "../../util/EmojiConfig"
|
PartnerModel,
|
||||||
|
PartnerRoleType,
|
||||||
|
} from '../../database/Partner';
|
||||||
|
import {
|
||||||
|
ChatInputCommandInteraction,
|
||||||
|
EmbedBuilder,
|
||||||
|
GuildMember,
|
||||||
|
} from 'discord.js';
|
||||||
|
import MemberUtil from '../../util/MemberUtil';
|
||||||
|
import EmojiConfig from '../../util/EmojiConfig';
|
||||||
|
|
||||||
export default class Whois extends DiscordInteractionCommand {
|
export default class Whois extends DiscordInteractionCommand {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("whois", "Retrieves information about a user.");
|
super('whois', 'Retrieves information about a user.');
|
||||||
this.builder.addUserOption(option => option.setName("member").setDescription("The member to get information about.").setRequired(true));
|
this.builder.addUserOption((option) =>
|
||||||
}
|
option
|
||||||
|
.setName('member')
|
||||||
|
.setDescription('The member to get information about.')
|
||||||
|
.setRequired(true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public async execute(interaction: ChatInputCommandInteraction) {
|
public async execute(interaction: ChatInputCommandInteraction) {
|
||||||
// defer our reply and perform database/external API operations/lookups
|
// defer our reply and perform database/external API operations/lookups
|
||||||
await interaction.deferReply({ ephemeral: false });
|
await interaction.deferReply({ ephemeral: false });
|
||||||
const target = interaction.options.getUser("member", true);
|
const target = interaction.options.getUser('member', true);
|
||||||
const guild = interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
const guild =
|
||||||
const guildMember = await guild?.members.fetch(target.id);
|
interaction.guild || interaction.client.guilds.cache.get(this.GUILD_ID);
|
||||||
const databaseMember = await MemberModel.findOne({ discordID: target.id });
|
const guildMember = await guild?.members.fetch(target.id);
|
||||||
const partner = await PartnerModel.findOne({ discordID: target.id });
|
const databaseMember = await MemberModel.findOne({ discordID: target.id });
|
||||||
// return an error if target was not located
|
const partner = await PartnerModel.findOne({ discordID: target.id });
|
||||||
if (!guildMember) return interaction.editReply({ content: `Member target ${target.id} was not located.`});
|
// return an error if target was not located
|
||||||
// build our embed
|
if (!guildMember)
|
||||||
const embed = new EmbedBuilder();
|
return interaction.editReply({
|
||||||
// if the role type is managerial, add a [k] to the end of the name
|
content: `Member target ${target.id} was not located.`,
|
||||||
// if the partner exists, set the iconURL to the organizational logo
|
});
|
||||||
const formattedName = MemberUtil.formatName(guildMember, partner);
|
// build our embed
|
||||||
embed.setAuthor({ name: formattedName.text, iconURL: formattedName.iconURL });
|
const embed = new EmbedBuilder();
|
||||||
// set the thumbnail to the user's avatar
|
// if the role type is managerial, add a [k] to the end of the name
|
||||||
embed.setThumbnail(guildMember.user.displayAvatarURL());
|
// if the partner exists, set the iconURL to the organizational logo
|
||||||
// initialize the description string
|
const formattedName = MemberUtil.formatName(guildMember, partner);
|
||||||
let embedDescription = '';
|
embed.setAuthor({
|
||||||
if (partner) {
|
name: formattedName.text,
|
||||||
// set the title to the partner's title if applicable
|
iconURL: formattedName.iconURL,
|
||||||
if (partner.title) embedDescription += `## __${EmojiConfig.LOC} ${partner.title}__\n`;
|
});
|
||||||
embedDescription += "### Partner Information\n";
|
// set the thumbnail to the user's avatar
|
||||||
if (partner.emailAddress) embedDescription += `**Email Address**: ${partner.emailAddress}\n`;
|
embed.setThumbnail(guildMember.user.displayAvatarURL());
|
||||||
switch (partner.department) {
|
// initialize the description string
|
||||||
case PartnerDepartment.ENGINEERING:
|
let embedDescription = '';
|
||||||
embedDescription += "**Department**: Dept. of Engineering\n";
|
if (partner) {
|
||||||
break;
|
// set the title to the partner's title if applicable
|
||||||
case PartnerDepartment.OPERATIONS:
|
if (partner.title)
|
||||||
embedDescription += "**Department**: Dept. of Operations\n";
|
embedDescription += `## __${EmojiConfig.LOC} ${partner.title}__\n`;
|
||||||
break;
|
embedDescription += '### Partner Information\n';
|
||||||
case PartnerDepartment.INDEPENDENT_AGENCY:
|
if (partner.emailAddress)
|
||||||
embedDescription += "**Department**: Independent Agency/Contractor\n";
|
embedDescription += `**Email Address**: ${partner.emailAddress}\n`;
|
||||||
break;
|
switch (partner.department) {
|
||||||
}
|
case PartnerDepartment.ENGINEERING:
|
||||||
switch (partner.commissionType) {
|
embedDescription += '**Department**: Dept. of Engineering\n';
|
||||||
case PartnerCommissionType.TENURE:
|
break;
|
||||||
embedDescription += "**Commission Type**: Tenure\n";
|
case PartnerDepartment.OPERATIONS:
|
||||||
break;
|
embedDescription += '**Department**: Dept. of Operations\n';
|
||||||
case PartnerCommissionType.PROVISIONAL:
|
break;
|
||||||
embedDescription += "**Commission Type**: Provisional\n";
|
case PartnerDepartment.INDEPENDENT_AGENCY:
|
||||||
break;
|
embedDescription += '**Department**: Independent Agency/Contractor\n';
|
||||||
case PartnerCommissionType.CONTRACTUAL:
|
break;
|
||||||
embedDescription += "**Commission Type**: Contractual/Independent/Collaborator\n";
|
}
|
||||||
break;
|
switch (partner.commissionType) {
|
||||||
case PartnerCommissionType.ACTING:
|
case PartnerCommissionType.TENURE:
|
||||||
embedDescription += "**Commission Type**: Acting\n";
|
embedDescription += '**Commission Type**: Tenure\n';
|
||||||
break;
|
break;
|
||||||
case PartnerCommissionType.INTERIM:
|
case PartnerCommissionType.PROVISIONAL:
|
||||||
embedDescription += "**Commission Type**: Interim\n";
|
embedDescription += '**Commission Type**: Provisional\n';
|
||||||
break;
|
break;
|
||||||
case PartnerCommissionType.TRIAL:
|
case PartnerCommissionType.CONTRACTUAL:
|
||||||
embedDescription += "**Commission Type**: Trial/Intern\n";
|
embedDescription +=
|
||||||
break;
|
'**Commission Type**: Contractual/Independent/Collaborator\n';
|
||||||
}
|
break;
|
||||||
if (partner.directReport) {
|
case PartnerCommissionType.ACTING:
|
||||||
if (partner.directReport instanceof Partner) {
|
embedDescription += '**Commission Type**: Acting\n';
|
||||||
embedDescription += `**Direct Report**: ${partner.directReport.title}\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);
|
}
|
||||||
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) {
|
|
||||||
case "online":
|
|
||||||
embed.addFields({ name: "Status", value: "Online", inline: true });
|
|
||||||
break;
|
|
||||||
case "idle":
|
|
||||||
embed.addFields({ name: "Status", value: "Idle", inline: true });
|
|
||||||
break;
|
|
||||||
case "dnd":
|
|
||||||
embed.addFields({ name: "Status", value: "Do Not Disturb", inline: true });
|
|
||||||
break;
|
|
||||||
case "offline" || "invisible":
|
|
||||||
embed.addFields({ name: "Status", value: "Online", inline: true });
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// TODO: decide what placeholder we should use for values that fall "out of range"
|
|
||||||
embed.addFields({ name: "Status", value: "", inline: true });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
embed.setFooter({ text: `Discord ID: ${guildMember.id}${databaseMember ? `Internal ID: ${databaseMember?._id}` : ''}` });
|
|
||||||
|
|
||||||
return await interaction.editReply({ embeds: [embed] });
|
|
||||||
}
|
}
|
||||||
|
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) {
|
||||||
|
case 'online':
|
||||||
|
embed.addFields({ name: 'Status', value: 'Online', inline: true });
|
||||||
|
break;
|
||||||
|
case 'idle':
|
||||||
|
embed.addFields({ name: 'Status', value: 'Idle', inline: true });
|
||||||
|
break;
|
||||||
|
case 'dnd':
|
||||||
|
embed.addFields({
|
||||||
|
name: 'Status',
|
||||||
|
value: 'Do Not Disturb',
|
||||||
|
inline: true,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'offline':
|
||||||
|
embed.addFields({ name: 'Status', value: 'offline', inline: true });
|
||||||
|
break;
|
||||||
|
case 'invisible':
|
||||||
|
embed.addFields({ name: 'Status', value: 'invisible', inline: true });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// TODO: decide what placeholder we should use for values that fall "out of range"
|
||||||
|
embed.addFields({ name: 'Status', value: '', inline: true });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
embed.setFooter({
|
||||||
|
text: `Discord ID: ${guildMember.id}${
|
||||||
|
databaseMember ? `Internal ID: ${databaseMember?._id}` : ''
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await interaction.editReply({ embeds: [embed] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue