2020-11-02 06:58:23 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
|
|
|
import { Guild } from '../structures/guild.ts'
|
|
|
|
import { Role } from '../structures/role.ts'
|
|
|
|
import { GUILD_ROLE } from '../types/endpoint.ts'
|
|
|
|
import { RolePayload } from '../types/role.ts'
|
2020-11-04 12:38:00 +00:00
|
|
|
import { BaseManager } from './base.ts'
|
2020-10-31 11:45:33 +00:00
|
|
|
|
|
|
|
export class RolesManager extends BaseManager<RolePayload, Role> {
|
|
|
|
guild: Guild
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
constructor (client: Client, guild: Guild) {
|
|
|
|
super(client, `roles:${guild.id}`, Role)
|
2020-10-31 11:45:33 +00:00
|
|
|
this.guild = guild
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
async fetch (id: string): Promise<Role> {
|
|
|
|
return await new Promise((resolve, reject) => {
|
|
|
|
this.client.rest
|
|
|
|
.get(GUILD_ROLE(this.guild.id, id))
|
|
|
|
.then(data => {
|
|
|
|
this.set(id, data as RolePayload)
|
|
|
|
resolve(new Role(this.client, data as RolePayload))
|
|
|
|
})
|
|
|
|
.catch(e => reject(e))
|
2020-10-31 11:45:33 +00:00
|
|
|
})
|
|
|
|
}
|
2020-11-01 13:42:00 +00:00
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async fromPayload(roles: RolePayload[]): Promise<boolean> {
|
2020-11-03 15:19:20 +00:00
|
|
|
for (const role of roles) {
|
2020-11-02 12:08:38 +00:00
|
|
|
await this.set(role.id, role)
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|
2020-11-02 12:08:38 +00:00
|
|
|
return true
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|
2020-11-02 06:58:23 +00:00
|
|
|
}
|