Compare commits
6 Commits
ed90a4c3f9
...
98c1e83770
Author | SHA1 | Date |
---|---|---|
Matthew | 98c1e83770 | |
Matthew | 754983ab08 | |
Matthew | 3e80cba3c1 | |
Matthew | 957c5a8928 | |
Matthew | a1e59fa275 | |
Matthew | 8cd51cac26 |
|
@ -5,6 +5,10 @@ import { prop, getModelForClass } from "@typegoose/typegoose"
|
|||
* Further attributes for class
|
||||
* */
|
||||
|
||||
export interface SharedMemberAttributes {
|
||||
discordID: string | undefined;
|
||||
}
|
||||
|
||||
export type MemberAdditionalAcknowledgement =
|
||||
"Chair of the Board of Governors" |
|
||||
"Vice Chair of the Board of Governors" |
|
||||
|
@ -39,7 +43,7 @@ export enum MemberUsedOperatingSystems {
|
|||
UBUNTU = "os-ubuntu",
|
||||
WIN = "os-win"
|
||||
}
|
||||
export default class Member {
|
||||
export default class Member implements SharedMemberAttributes {
|
||||
@prop({ required: true, unique: true })
|
||||
public discordID: string | undefined;
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import Member from "./Member";
|
|||
* Further attributes for class
|
||||
* */
|
||||
|
||||
import { SharedMemberAttributes } from "./Member";
|
||||
|
||||
export type PartnerTitle =
|
||||
"Director of Engineering" |
|
||||
"Director of Operations" |
|
||||
|
@ -40,10 +42,13 @@ export enum PartnerCommissionType {
|
|||
TRIAL,
|
||||
}
|
||||
|
||||
export default class Partner {
|
||||
export default class Partner implements SharedMemberAttributes {
|
||||
@prop({ required: true, unique: true })
|
||||
public discordID: string | undefined;
|
||||
|
||||
@prop()
|
||||
public emailAddress: string | undefined;
|
||||
|
||||
@prop({ required: true })
|
||||
public roleType: PartnerRoleType | undefined;
|
||||
|
||||
|
|
|
@ -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] });
|
||||
}
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
export { default as Ping } from "./Ping";
|
||||
export { default as Whois } from "./Whois";
|
||||
|
|
12
index.ts
12
index.ts
|
@ -5,6 +5,7 @@ import DiscordInteractionCommand from "./util/DiscordInteractionCommand";
|
|||
import DiscordEvent from "./util/DiscordEvent";
|
||||
import * as DiscordInteractionCommandsIndex from "./discord/commands";
|
||||
import * as DiscordEventsIndex from "./discord/events";
|
||||
import mongoose from "mongoose";
|
||||
|
||||
export const DiscordInteractionCommands: Collection<DiscordInteractionCommand> = new Collection();
|
||||
export const DiscordEvents: Collection<DiscordEvent> = new Collection();
|
||||
|
@ -25,6 +26,17 @@ const discordREST = new REST().setToken(discordBotToken);
|
|||
// const stripeClient = new Stripe(stripeToken, { typescript: true });
|
||||
|
||||
export async function main() {
|
||||
// Connect to the databases
|
||||
try {
|
||||
mongoose.connection.once("open", () => {
|
||||
console.info("[Info - Database] Connected to MongoDB");
|
||||
})
|
||||
// TODO: Fetch the MongoDB URI from the config file
|
||||
await mongoose.connect("mongodb://localhost:27017/crra-main", {});
|
||||
} catch (error) {
|
||||
console.error(`[Error - Database] Failed to connect to MongoDB: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
// Load Discord interaction commands
|
||||
for (const Command of Object.values(DiscordInteractionCommandsIndex)) {
|
||||
const instance = new Command();
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||
import { guildID } from "../config.json";
|
||||
|
||||
export default abstract class DiscordInteractionCommand {
|
||||
public name: string;
|
||||
public description: string;
|
||||
public builder: SlashCommandBuilder;
|
||||
|
||||
protected GUILD_ID: string;
|
||||
|
||||
protected constructor(name: string, description: string) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
@ -12,7 +15,9 @@ export default abstract class DiscordInteractionCommand {
|
|||
|
||||
this.builder.setName(this.name);
|
||||
this.builder.setDescription(this.description);
|
||||
|
||||
this.GUILD_ID = guildID;
|
||||
}
|
||||
|
||||
public abstract execute(interaction: ChatInputCommandInteraction): Error | Promise<void>;
|
||||
public abstract execute(interaction: ChatInputCommandInteraction): Error | Promise<void | any>;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import Partner, {
|
|||
PartnerTitle
|
||||
} from "../database/Partner";
|
||||
import Member, { MemberAdditionalAcknowledgement, MemberModel } from "../database/Member";
|
||||
import { Client } from "discord.js";
|
||||
import { Client, GuildMember, User } from "discord.js";
|
||||
import { guildID } from "../config.json";
|
||||
|
||||
export interface PartnerOptions {
|
||||
|
@ -17,6 +17,11 @@ export interface PartnerOptions {
|
|||
directReport: Partner | string;
|
||||
}
|
||||
|
||||
export interface FormatNameOptions {
|
||||
text: string;
|
||||
iconURL: string;
|
||||
}
|
||||
|
||||
// TODO: Add the rest of the remaining role configurations
|
||||
export const PartnerDiscordRoleMap = {
|
||||
// Director of Engineering, Management, Staff, Technician, Core Team, Play Caller
|
||||
|
@ -53,4 +58,26 @@ export default class MemberUtil {
|
|||
if (member.additionalAcknowledgement?.includes(acknowledgement)) throw new Error("This member already has this acknowledgement.")
|
||||
return MemberModel.updateOne({ discordID: member.discordID }, { $push: { additionalAcknowledgement: acknowledgement } });
|
||||
}
|
||||
|
||||
// TODO: comments and extended formatting
|
||||
public static formatName(target: GuildMember | User, partner?: Partner | null): FormatNameOptions {
|
||||
// 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
|
||||
if (partner?.roleType == PartnerRoleType.MANAGERIAL) {
|
||||
return {
|
||||
text: `${target.displayName} [k]`,
|
||||
iconURL: "https://static.libraryofcode.org/library_of_code_redeg.png"
|
||||
}
|
||||
} else if (partner?.commissionType == PartnerCommissionType.CONTRACTUAL) { // if the commission type is contractual, add a [c] to the end of the name
|
||||
return {
|
||||
text: `${target.displayName} [c]`,
|
||||
iconURL: "https://static.libraryofcode.org/library_of_code_redeg.png"
|
||||
}
|
||||
} else { // otherwise, just set the author to the member's display name
|
||||
return {
|
||||
text: target.displayName,
|
||||
iconURL: target.displayAvatarURL()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue