2020-10-22 15:50:47 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
2020-10-23 16:11:00 +00:00
|
|
|
import {
|
|
|
|
ChannelPayload,
|
|
|
|
GuildChannelCategoryPayload,
|
|
|
|
GuildNewsChannelPayload,
|
|
|
|
GuildTextChannelPayload,
|
|
|
|
GuildVoiceChannelPayload,
|
|
|
|
DMChannelPayload,
|
|
|
|
GroupDMChannelPayload,
|
|
|
|
ChannelTypes
|
|
|
|
} from '../types/channelTypes.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
import { Base } from './base.ts'
|
2020-10-23 16:11:00 +00:00
|
|
|
import { DMChannel } from './dm.ts'
|
|
|
|
import { GroupChannel } from './groupChannel.ts'
|
|
|
|
import { VoiceChannel } from './guildVoiceChannel.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
import { TextChannel } from './textChannel.ts'
|
|
|
|
|
|
|
|
export class Channel extends Base {
|
|
|
|
type: ChannelTypes
|
|
|
|
id: string
|
|
|
|
|
|
|
|
constructor (client: Client, data: ChannelPayload) {
|
|
|
|
super(client)
|
|
|
|
this.type = data.type
|
|
|
|
this.id = data.id
|
|
|
|
}
|
|
|
|
|
|
|
|
get mention () {
|
|
|
|
return `<#${this.id}>`
|
|
|
|
}
|
|
|
|
|
2020-10-23 16:11:00 +00:00
|
|
|
static from (
|
|
|
|
data:
|
|
|
|
| GuildChannelCategoryPayload
|
|
|
|
| GuildNewsChannelPayload
|
|
|
|
| GuildTextChannelPayload
|
|
|
|
| GuildVoiceChannelPayload
|
|
|
|
| DMChannelPayload
|
|
|
|
| GroupDMChannelPayload,
|
|
|
|
client: Client
|
|
|
|
) {
|
2020-10-22 15:50:47 +00:00
|
|
|
switch (data.type) {
|
2020-10-23 16:11:00 +00:00
|
|
|
case ChannelTypes.GUILD_CATEGORY:
|
|
|
|
return
|
|
|
|
case ChannelTypes.GUILD_NEWS:
|
|
|
|
return
|
2020-10-22 15:50:47 +00:00
|
|
|
case ChannelTypes.GUILD_TEXT:
|
2020-10-23 16:11:00 +00:00
|
|
|
return new TextChannel(client, data as GuildTextChannelPayload)
|
|
|
|
case ChannelTypes.GUILD_VOICE:
|
|
|
|
return new VoiceChannel(client, data as GuildVoiceChannelPayload)
|
2020-10-22 15:50:47 +00:00
|
|
|
case ChannelTypes.DM:
|
2020-10-23 16:11:00 +00:00
|
|
|
return new DMChannel(client, data as DMChannelPayload)
|
|
|
|
case ChannelTypes.GROUP_DM:
|
|
|
|
return new GroupChannel(client, data as GroupDMChannelPayload)
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|