harmony/src/structures/user.ts

70 lines
2 KiB
TypeScript
Raw Normal View History

import { Client } from '../models/client.ts'
2020-10-31 12:33:34 +00:00
import { UserPayload } from '../types/user.ts'
import { UserFlagsManager } from "../utils/userFlags.ts"
import { Base } from './base.ts'
export class User extends Base {
id: string
username: string
discriminator: string
avatar?: string
bot?: boolean
system?: boolean
mfaEnabled?: boolean
locale?: string
verified?: boolean
email?: string
flags?: UserFlagsManager
premiumType?: 0 | 1 | 2
publicFlags?: UserFlagsManager
get tag (): string {
return `${this.username}#${this.discriminator}`
}
get nickMention (): string {
return `<@!${this.id}>`
}
get mention (): string {
return `<@${this.id}>`
}
constructor (client: Client, data: UserPayload) {
super(client, data)
this.id = data.id
this.username = data.username
this.discriminator = data.discriminator
this.avatar = data.avatar
this.bot = data.bot
this.system = data.system
this.mfaEnabled = data.mfa_enabled
this.locale = data.locale
this.verified = data.verified
this.email = data.email
this.flags = new UserFlagsManager(data.flags)
this.premiumType = data.premium_type
this.publicFlags = new UserFlagsManager(data.public_flags)
}
protected readFromData (data: UserPayload): void {
super.readFromData(data)
this.username = data.username ?? this.username
this.discriminator = data.discriminator ?? this.discriminator
this.avatar = data.avatar ?? this.avatar
this.bot = data.bot ?? this.bot
this.system = data.system ?? this.system
this.mfaEnabled = data.mfa_enabled ?? this.mfaEnabled
this.locale = data.locale ?? this.locale
this.verified = data.verified ?? this.verified
this.email = data.email ?? this.email
this.flags = new UserFlagsManager(data.flags) ?? this.flags
this.premiumType = data.premium_type ?? this.premiumType
this.publicFlags = new UserFlagsManager(data.public_flags) ?? this.publicFlags
}
toString (): string {
return this.mention
}
}