2020-10-29 14:43:27 +00:00
|
|
|
import cache from '../models/cache.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
2020-10-31 12:33:34 +00:00
|
|
|
import { MemberPayload } from '../types/guild.ts'
|
2020-10-30 14:51:40 +00:00
|
|
|
import { Base } from './base.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
import { User } from './user.ts'
|
|
|
|
|
2020-10-30 14:51:40 +00:00
|
|
|
export class Member extends Base {
|
|
|
|
id: string
|
|
|
|
user: User
|
2020-10-23 16:11:00 +00:00
|
|
|
nick?: string
|
2020-10-29 14:43:27 +00:00
|
|
|
roles: string[]
|
2020-10-23 16:11:00 +00:00
|
|
|
joinedAt: string
|
|
|
|
premiumSince?: string
|
2020-10-22 15:50:47 +00:00
|
|
|
deaf: boolean
|
|
|
|
mute: boolean
|
|
|
|
|
|
|
|
constructor (client: Client, data: MemberPayload) {
|
2020-10-30 14:51:40 +00:00
|
|
|
super(client)
|
|
|
|
this.id = data.user.id
|
|
|
|
this.user =
|
|
|
|
cache.get('user', data.user.id) ?? new User(this.client, data.user)
|
2020-10-22 15:50:47 +00:00
|
|
|
this.nick = data.nick
|
2020-10-29 14:43:27 +00:00
|
|
|
this.roles = data.roles
|
2020-10-23 16:11:00 +00:00
|
|
|
this.joinedAt = data.joined_at
|
|
|
|
this.premiumSince = data.premium_since
|
2020-10-22 15:50:47 +00:00
|
|
|
this.deaf = data.deaf
|
|
|
|
this.mute = data.mute
|
2020-11-01 11:22:09 +00:00
|
|
|
// TODO: Cache in Gateway Event Code
|
|
|
|
// cache.set('member', this.id, this)
|
2020-10-29 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 14:51:40 +00:00
|
|
|
protected readFromData (data: MemberPayload): void {
|
|
|
|
super.readFromData(data.user)
|
2020-10-29 14:43:27 +00:00
|
|
|
this.nick = data.nick ?? this.nick
|
|
|
|
this.roles = data.roles ?? this.roles
|
|
|
|
this.joinedAt = data.joined_at ?? this.joinedAt
|
|
|
|
this.premiumSince = data.premium_since ?? this.premiumSince
|
|
|
|
this.deaf = data.deaf ?? this.deaf
|
|
|
|
this.mute = data.mute ?? this.mute
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
}
|