harmony/src/structures/channel.ts
Helloyunho c846bd6f61 Try to make Base class useful
Co-Authored-By: Aki <71239005+AkiaCode@users.noreply.github.com>
Co-Authored-By: Y <8479056+yky4589@users.noreply.github.com>
Co-Authored-By: Lee Hyun <ink0416@naver.com>
Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com>
2020-10-25 00:00:42 +09:00

65 lines
1.9 KiB
TypeScript

import { Client } from '../models/client.ts'
import {
ChannelPayload,
GuildChannelCategoryPayload,
GuildNewsChannelPayload,
GuildTextChannelPayload,
GuildVoiceChannelPayload,
DMChannelPayload,
GroupDMChannelPayload,
ChannelTypes
} from '../types/channelTypes.ts'
import { Base } from './base.ts'
import { CategoryChannel } from './guildCategoryChannel.ts'
import { VoiceChannel } from './guildVoiceChannel.ts'
import { NewsChannel } from './guildnewsChannel.ts'
import { DMChannel } from './dmChannel.ts'
import { GroupDMChannel } from './groupChannel.ts'
import { TextChannel } from './textChannel.ts'
export class Channel extends Base {
type: ChannelTypes
id: string
static cacheName = 'channel'
static cacheArgIndex = 0
constructor (client: Client, data: ChannelPayload) {
super(client)
this.type = data.type
this.id = data.id
}
get mention () {
return `<#${this.id}>`
}
static async autoInit (client: Client, channelID: string) {
return super.autoInit(client, channelID)
}
static from (
data:
| GuildChannelCategoryPayload
| GuildNewsChannelPayload
| GuildTextChannelPayload
| GuildVoiceChannelPayload
| DMChannelPayload
| GroupDMChannelPayload,
client: Client
) {
switch (data.type) {
case ChannelTypes.GUILD_CATEGORY:
return new CategoryChannel(client, data as GuildChannelCategoryPayload)
case ChannelTypes.GUILD_NEWS:
return new NewsChannel(client, data as GuildNewsChannelPayload)
case ChannelTypes.GUILD_TEXT:
return new TextChannel(client, data as GuildTextChannelPayload)
case ChannelTypes.GUILD_VOICE:
return new VoiceChannel(client, data as GuildVoiceChannelPayload)
case ChannelTypes.DM:
return new DMChannel(client, data as DMChannelPayload)
case ChannelTypes.GROUP_DM:
return new GroupDMChannel(client, data as GroupDMChannelPayload)
}
}
}