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-25 18:29:26 +00:00
|
|
|
tags?: RoleTags
|
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-12-25 18:29:26 +00:00
|
|
|
this.tags =
|
|
|
|
data.tags !== null
|
|
|
|
? {
|
|
|
|
botID: data.tags?.bot_id,
|
|
|
|
integrationID: data.tags?.integration_id,
|
|
|
|
premiumSubscriber: 'premium_subscriber' in (data.tags ?? {})
|
|
|
|
}
|
|
|
|
: undefined
|
2020-10-29 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 05:28:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-12-25 18:29:26 +00:00
|
|
|
|
|
|
|
export interface RoleTags {
|
|
|
|
/** The id of the bot who has this role */
|
|
|
|
botID?: string
|
|
|
|
/** Whether this is the premium subscriber role for this guild */
|
|
|
|
premiumSubscriber: boolean
|
|
|
|
/** The id of the integration this role belongs to */
|
|
|
|
integrationID?: string
|
|
|
|
}
|