2020-10-22 15:50:47 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
|
|
|
import { Base } from './base.ts'
|
2020-10-31 12:33:34 +00:00
|
|
|
import { RolePayload } from '../types/role.ts'
|
2020-12-02 12:29:52 +00:00
|
|
|
import { Permissions } from '../utils/permissions.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-10-23 16:11:00 +00:00
|
|
|
export class Role extends Base {
|
2020-10-22 15:50:47 +00:00
|
|
|
id: string
|
|
|
|
name: string
|
|
|
|
color: number
|
|
|
|
hoist: boolean
|
|
|
|
position: number
|
2020-11-15 07:32:46 +00:00
|
|
|
permissions: Permissions
|
2020-10-22 15:50:47 +00:00
|
|
|
managed: boolean
|
|
|
|
mentionable: boolean
|
|
|
|
|
2020-12-02 12:29:52 +00:00
|
|
|
get mention(): string {
|
2020-10-23 03:19:40 +00:00
|
|
|
return `<@&${this.id}>`
|
|
|
|
}
|
|
|
|
|
2020-12-02 12:29:52 +00:00
|
|
|
toString(): string {
|
|
|
|
return this.mention
|
|
|
|
}
|
2020-11-09 10:29:16 +00:00
|
|
|
|
2020-12-02 12:29:52 +00:00
|
|
|
constructor(client: Client, data: RolePayload) {
|
2020-10-25 06:50:32 +00:00
|
|
|
super(client, data)
|
2020-10-22 15:50:47 +00:00
|
|
|
this.id = data.id
|
|
|
|
this.name = data.name
|
|
|
|
this.color = data.color
|
|
|
|
this.hoist = data.hoist
|
|
|
|
this.position = data.position
|
2020-11-15 07:32:46 +00:00
|
|
|
this.permissions = new Permissions(data.permissions)
|
2020-10-22 15:50:47 +00:00
|
|
|
this.managed = data.managed
|
|
|
|
this.mentionable = data.mentionable
|
2020-10-29 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 12:29:52 +00:00
|
|
|
protected readFromData(data: RolePayload): void {
|
2020-10-29 14:43:27 +00:00
|
|
|
this.name = data.name ?? this.name
|
|
|
|
this.color = data.color ?? this.color
|
|
|
|
this.hoist = data.hoist ?? this.hoist
|
|
|
|
this.position = data.position ?? this.position
|
2020-12-02 12:29:52 +00:00
|
|
|
this.permissions =
|
|
|
|
data.permissions !== undefined
|
|
|
|
? new Permissions(data.permissions)
|
|
|
|
: this.permissions
|
2020-10-29 14:43:27 +00:00
|
|
|
this.managed = data.managed ?? this.managed
|
|
|
|
this.mentionable = data.mentionable ?? this.mentionable
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
}
|