harmony/src/structures/role.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

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'
export class Role extends Base {
id: string
name: string
color: number
hoist: boolean
position: number
permissions: Permissions
managed: boolean
mentionable: boolean
2020-12-02 12:29:52 +00:00
get mention(): string {
return `<@&${this.id}>`
}
2020-12-02 12:29:52 +00:00
toString(): string {
return this.mention
}
2020-12-02 12:29:52 +00:00
constructor(client: Client, data: RolePayload) {
super(client, data)
this.id = data.id
this.name = data.name
this.color = data.color
this.hoist = data.hoist
this.position = data.position
this.permissions = new Permissions(data.permissions)
this.managed = data.managed
this.mentionable = data.mentionable
}
2020-12-02 12:29:52 +00:00
protected readFromData(data: RolePayload): void {
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
this.managed = data.managed ?? this.managed
this.mentionable = data.mentionable ?? this.mentionable
}
}