2024-11-09 18:14:10 -05:00
import { GuildMember , User } from "discord.js" ;
import Partner , { PartnerCommissionType , PartnerRoleType } from "../database/Partner" ;
import { FormatNameOptions } from "./MemberUtil" ;
export default class Formatters {
public static formatStandardDate ( date : Date | string | number ) : string {
const resolvedDate = new Date ( date ) ;
if ( ! resolvedDate ) return "" ;
const year = resolvedDate . getFullYear ( ) ;
const month = String ( resolvedDate . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) ;
const day = String ( resolvedDate . getDate ( ) ) . padStart ( 2 , "0" ) ;
const hours = String ( resolvedDate . getHours ( ) ) . padStart ( 2 , "0" ) ;
const minutes = String ( resolvedDate . getMinutes ( ) ) . padStart ( 2 , "0" ) ;
const timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
return ` ${ year } - ${ month } - ${ day } @ ${ hours } : ${ minutes } ( ${ timeZone } ) ` ;
}
// TODO: comments and extended formatting
public static formatName (
target : GuildMember | User ,
partner? : Partner | null
) : FormatNameOptions {
console . debug (
` [MemberUtil] Formatting name for ${ target . displayName } at url ${ target instanceof GuildMember ? target . user . displayAvatarURL ( ) : target . displayAvatarURL ( ) } `
) ;
2025-01-30 21:33:06 -05:00
// if the partner is designated as a KeyHolder, add a [k] to the end of the name
2024-11-09 18:14:10 -05:00
// if the partner exists, set the iconURL to the organizational logo
2025-01-30 21:33:06 -05:00
if ( partner ? . isKeyHolder ) {
2024-11-09 18:14:10 -05:00
return {
text : ` ${ target . displayName } [k] ` ,
iconURL : target.displayAvatarURL ( ) ,
} ;
2025-01-30 21:33:06 -05:00
} else if ( partner ? . roleType === PartnerRoleType . MANAGERIAL ) {
// if a partner is of RoleType MANAGERIAL, add [m] to their name
return {
text : ` ${ target . displayName } [m] ` ,
iconURL :
target instanceof GuildMember
? target . user . displayAvatarURL ( )
: target . displayAvatarURL ( ) ,
} ;
} else if ( partner ? . commissionType === PartnerCommissionType . CONTRACTUAL ) {
2024-11-09 18:14:10 -05:00
// if the commission type is contractual, add a [c] to the end of the name
return {
text : ` ${ target . displayName } [c] ` ,
iconURL :
target instanceof GuildMember
? target . user . displayAvatarURL ( )
: target . displayAvatarURL ( ) ,
} ;
} else {
// otherwise, just set the author to the member's display name
return {
text : target.displayName ,
iconURL :
target instanceof GuildMember
? target . user . displayAvatarURL ( )
: target . displayAvatarURL ( ) ,
} ;
}
}
}