crv2/util/MemberUtil.ts

84 lines
2.5 KiB
TypeScript
Raw Permalink Normal View History

2024-04-01 20:04:46 -04:00
import Partner, {
2024-10-25 16:57:33 -04:00
PartnerCommissionType,
PartnerDepartment,
PartnerModel,
PartnerRoleType,
PartnerTitle,
2024-04-01 20:04:46 -04:00
} from "../database/Partner";
import Member, { MemberAdditionalAcknowledgement, MemberModel } from "../database/Member";
2024-04-02 16:39:36 -04:00
import { Client, GuildMember, User } from "discord.js";
2024-04-01 20:04:46 -04:00
import { guildID } from "../config.json";
import { Ref } from "@typegoose/typegoose";
2024-04-01 20:04:46 -04:00
export interface PartnerOptions {
2024-10-25 16:57:33 -04:00
roleType: PartnerRoleType;
commissionType: PartnerCommissionType;
department: PartnerDepartment;
title: PartnerTitle;
directReport: Ref<Partner>;
2024-04-01 20:04:46 -04:00
}
2024-04-02 16:39:36 -04:00
export interface FormatNameOptions {
2024-10-25 16:57:33 -04:00
text: string;
iconURL: string;
2024-04-02 16:39:36 -04:00
}
2024-04-01 20:04:46 -04:00
// TODO: Add the rest of the remaining role configurations
export const PartnerDiscordRoleMap = {
2024-10-25 16:57:33 -04:00
// Director of Engineering, Management, Staff, Technician, Core Team, Play Caller
Engineering: [
2024-10-25 16:57:33 -04:00
"1077646568091570236",
"1077646956890951690",
"446104438969466890",
"701454780828221450",
"453689940140883988",
"1014978134573064293",
],
// Director of Operations, Management, Staff, Moderator, Core Team, Play Caller
Operations: [
2024-10-25 16:57:33 -04:00
"1077647072163020840",
"1077646956890951690",
"446104438969466890",
"455972169449734144",
"453689940140883988",
"1014978134573064293",
],
};
2024-04-01 20:04:46 -04:00
export default class MemberUtil {
2024-10-25 16:57:33 -04:00
public static async createNewPartner(member: Member, options: PartnerOptions) {
const partner = new PartnerModel();
partner.discordID = member.discordID;
partner.roleType = options.roleType;
partner.commissionType = options.commissionType;
partner.department = options.department;
partner.title = options.title;
partner.directReport = options.directReport;
await partner.save();
return partner;
}
2024-04-01 20:04:46 -04:00
2024-10-25 16:57:33 -04:00
public static async getPartner(member: Member) {
return PartnerModel.findOne({ discordID: member.discordID });
}
2024-04-01 20:04:46 -04:00
2024-10-25 16:57:33 -04:00
public static async deletePartner(member: Member) {
return PartnerModel.deleteOne({ discordID: member.discordID });
}
2024-04-01 20:04:46 -04:00
2024-10-25 16:57:33 -04:00
public static addAcknowledgementToMember(
member: Member,
acknowledgement: MemberAdditionalAcknowledgement
) {
if (!member.additionalAcknowledgement || member.additionalAcknowledgement?.length === 0) {
MemberModel.updateOne({ discordID: member.discordID }, { additionalAcknowledgement: [] });
2024-04-01 20:04:46 -04:00
}
2024-10-25 16:57:33 -04:00
if (member.additionalAcknowledgement?.includes(acknowledgement))
throw new Error("This member already has this acknowledgement.");
return MemberModel.updateOne(
{ discordID: member.discordID },
{ $push: { additionalAcknowledgement: acknowledgement } }
);
}
2024-04-01 20:04:46 -04:00
}