2020-10-22 15:50:47 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
2020-10-31 12:33:34 +00:00
|
|
|
import { UserPayload } from '../types/user.ts'
|
2020-11-15 07:32:46 +00:00
|
|
|
import { UserFlagsManager } from "../utils/userFlags.ts"
|
2020-10-22 15:50:47 +00:00
|
|
|
import { Base } from './base.ts'
|
|
|
|
|
2020-10-23 16:11:00 +00:00
|
|
|
export class User extends Base {
|
2020-10-22 15:50:47 +00:00
|
|
|
id: string
|
|
|
|
username: string
|
|
|
|
discriminator: string
|
|
|
|
avatar?: string
|
|
|
|
bot?: boolean
|
|
|
|
system?: boolean
|
2020-10-23 16:11:00 +00:00
|
|
|
mfaEnabled?: boolean
|
2020-10-22 15:50:47 +00:00
|
|
|
locale?: string
|
|
|
|
verified?: boolean
|
|
|
|
email?: string
|
2020-11-15 07:32:46 +00:00
|
|
|
flags?: UserFlagsManager
|
2020-10-23 16:11:00 +00:00
|
|
|
premiumType?: 0 | 1 | 2
|
2020-11-15 07:32:46 +00:00
|
|
|
publicFlags?: UserFlagsManager
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
get tag (): string {
|
|
|
|
return `${this.username}#${this.discriminator}`
|
2020-10-31 11:45:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 17:03:53 +00:00
|
|
|
get nickMention (): string {
|
2020-10-23 03:19:40 +00:00
|
|
|
return `<@!${this.id}>`
|
|
|
|
}
|
|
|
|
|
2020-10-25 17:03:53 +00:00
|
|
|
get mention (): string {
|
2020-10-23 03:19:40 +00:00
|
|
|
return `<@${this.id}>`
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:50:47 +00:00
|
|
|
constructor (client: Client, data: UserPayload) {
|
2020-10-25 06:50:32 +00:00
|
|
|
super(client, data)
|
2020-10-22 15:50:47 +00:00
|
|
|
this.id = data.id
|
|
|
|
this.username = data.username
|
|
|
|
this.discriminator = data.discriminator
|
|
|
|
this.avatar = data.avatar
|
|
|
|
this.bot = data.bot
|
|
|
|
this.system = data.system
|
2020-10-23 16:11:00 +00:00
|
|
|
this.mfaEnabled = data.mfa_enabled
|
2020-10-22 15:50:47 +00:00
|
|
|
this.locale = data.locale
|
|
|
|
this.verified = data.verified
|
|
|
|
this.email = data.email
|
2020-11-15 07:32:46 +00:00
|
|
|
this.flags = new UserFlagsManager(data.flags)
|
2020-10-23 16:11:00 +00:00
|
|
|
this.premiumType = data.premium_type
|
2020-11-15 07:32:46 +00:00
|
|
|
this.publicFlags = new UserFlagsManager(data.public_flags)
|
2020-10-29 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 14:51:40 +00:00
|
|
|
protected readFromData (data: UserPayload): void {
|
2020-10-29 14:43:27 +00:00
|
|
|
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
|
2020-11-15 07:32:46 +00:00
|
|
|
this.flags = new UserFlagsManager(data.flags) ?? this.flags
|
2020-10-29 14:43:27 +00:00
|
|
|
this.premiumType = data.premium_type ?? this.premiumType
|
2020-11-15 07:32:46 +00:00
|
|
|
this.publicFlags = new UserFlagsManager(data.public_flags) ?? this.publicFlags
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
2020-10-31 11:45:33 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
toString (): string {
|
|
|
|
return this.mention
|
2020-10-31 11:45:33 +00:00
|
|
|
}
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|