harmony/src/managers/guildChannels.ts

45 lines
1.7 KiB
TypeScript
Raw Normal View History

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";
import { GuildChannelCategoryPayload, GuildTextChannelPayload, GuildVoiceChannelPayload } from "../types/channel.ts";
import { CHANNEL } from "../types/endpoint.ts";
2020-11-04 12:38:00 +00:00
import { BaseChildManager } from "./baseChild.ts";
import { ChannelsManager } from "./channels.ts";
2020-11-03 09:21:29 +00:00
export type GuildChannelPayloads = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload
export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel
2020-11-03 09:21:29 +00:00
export class GuildChannelsManager extends BaseChildManager<GuildChannelPayloads, GuildChannel> {
guild: Guild
constructor(client: Client, parent: ChannelsManager, guild: Guild) {
super(client, parent as any)
this.guild = guild
}
2020-11-03 09:21:29 +00:00
async get(id: string): Promise<GuildChannel | undefined> {
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-03 09:21:29 +00:00
async delete(id: string): Promise<boolean> {
return this.client.rest.delete(CHANNEL(id))
}
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-03 09:21:29 +00:00
async flush(): Promise<boolean> {
const arr = await this.array()
for (const elem of arr) {
this.parent.delete(elem.id)
}
return true
}
}