2024-04-01 20:04:46 -04:00
import Partner , {
PartnerCommissionType ,
PartnerDepartment ,
PartnerModel ,
PartnerRoleType ,
PartnerTitle
} 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" ;
export interface PartnerOptions {
roleType : PartnerRoleType ;
commissionType : PartnerCommissionType ;
department : PartnerDepartment ;
title : PartnerTitle ;
directReport : Partner | string ;
}
2024-04-02 16:39:36 -04:00
export interface FormatNameOptions {
text : string ;
iconURL : string ;
}
2024-04-01 20:04:46 -04:00
// TODO: Add the rest of the remaining role configurations
export const PartnerDiscordRoleMap = {
// Director of Engineering, Management, Staff, Technician, Core Team, Play Caller
"Director of Engineering" : [ "1077646568091570236" , "1077646956890951690" , "446104438969466890" , "701454780828221450" , "453689940140883988" , "1014978134573064293" ] ,
// Director of Operations, Management, Staff, Moderator, Core Team, Play Caller
"Director of Operations" : [ "1077647072163020840" , "1077646956890951690" , "446104438969466890" , "455972169449734144" , "453689940140883988" , "1014978134573064293" ]
}
export default class MemberUtil {
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 ;
}
public static async getPartner ( member : Member ) {
return PartnerModel . findOne ( { discordID : member.discordID } ) ;
}
public static async deletePartner ( member : Member ) {
return PartnerModel . deleteOne ( { discordID : member.discordID } ) ;
}
public static addAcknowledgementToMember ( member : Member , acknowledgement : MemberAdditionalAcknowledgement ) {
if ( ! member . additionalAcknowledgement || member . additionalAcknowledgement ? . length === 0 ) {
MemberModel . updateOne ( { discordID : member.discordID } , { additionalAcknowledgement : [ ] } ) ;
}
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-02 16:39:36 -04:00
// 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 ) {
2024-04-05 20:12:56 -04:00
console . log ( ` [MemberUtil] Formatting name for ${ target . displayName } ` )
2024-04-02 16:39:36 -04:00
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
2024-04-05 20:12:56 -04:00
console . log ( ` [MemberUtil] Formatting name for ${ target . displayName } ` )
2024-04-02 16:39:36 -04:00
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
2024-04-05 20:12:56 -04:00
console . log ( ` [MemberUtil] Formatting name for ${ target . displayName } at url ${ target instanceof GuildMember ? target . user . displayAvatarURL ( ) : target . displayAvatarURL ( ) } ` ) ;
2024-04-02 16:39:36 -04:00
return {
text : target.displayName ,
2024-04-05 20:12:56 -04:00
iconURL : target instanceof GuildMember ? target . user . displayAvatarURL ( ) : target . displayAvatarURL ( )
2024-04-02 16:39:36 -04:00
}
}
}
2024-04-01 20:04:46 -04:00
}