2020-11-08 07:57:24 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
|
|
|
import { Channel } from '../structures/channel.ts'
|
|
|
|
import { Guild } from '../structures/guild.ts'
|
|
|
|
import { CategoryChannel } from '../structures/guildCategoryChannel.ts'
|
|
|
|
import { GuildTextChannel } from '../structures/guildTextChannel.ts'
|
|
|
|
import { VoiceChannel } from '../structures/guildVoiceChannel.ts'
|
2020-11-08 08:31:00 +00:00
|
|
|
import {
|
|
|
|
GuildChannelCategoryPayload,
|
|
|
|
GuildTextChannelPayload,
|
|
|
|
GuildVoiceChannelPayload
|
|
|
|
} from '../types/channel.ts'
|
2020-11-08 07:57:24 +00:00
|
|
|
import { CHANNEL } from '../types/endpoint.ts'
|
|
|
|
import { BaseChildManager } from './baseChild.ts'
|
|
|
|
import { ChannelsManager } from './channels.ts'
|
2020-11-01 13:42:00 +00:00
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
export type GuildChannelPayloads = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload
|
2020-11-01 13:42:00 +00:00
|
|
|
export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
export class GuildChannelsManager extends BaseChildManager<GuildChannelPayloads, GuildChannel> {
|
2020-11-01 13:42:00 +00:00
|
|
|
guild: Guild
|
|
|
|
|
2020-11-02 12:08:38 +00:00
|
|
|
constructor(client: Client, parent: ChannelsManager, guild: Guild) {
|
|
|
|
super(client, parent as any)
|
2020-11-01 13:42:00 +00:00
|
|
|
this.guild = guild
|
|
|
|
}
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async get(id: string): Promise<GuildChannel | undefined> {
|
2020-11-01 13:42:00 +00:00
|
|
|
const res = await this.parent.get(id)
|
2020-11-03 15:19:20 +00:00
|
|
|
if (res !== undefined && res.guild.id === this.guild.id) return res
|
2020-11-03 09:21:29 +00:00
|
|
|
else return undefined
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async delete(id: string): Promise<boolean> {
|
2020-11-01 13:42:00 +00:00
|
|
|
return this.client.rest.delete(CHANNEL(id))
|
|
|
|
}
|
2020-11-02 12:08:38 +00:00
|
|
|
|
|
|
|
async array(): Promise<GuildChannel[]> {
|
2020-11-03 09:21:29 +00:00
|
|
|
const arr = await this.parent.array() as Channel[]
|
|
|
|
return arr.filter((c: any) => c.guild !== undefined && c.guild.id === this.guild.id) as any
|
2020-11-02 12:08:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async flush(): Promise<boolean> {
|
|
|
|
const arr = await this.array()
|
|
|
|
for (const elem of arr) {
|
2020-11-02 12:08:38 +00:00
|
|
|
this.parent.delete(elem.id)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|