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()}` ); // 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: target.displayAvatarURL(), }; } 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: 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(), }; } } }