2020-10-30 14:51:40 +00:00
|
|
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
|
|
|
import getChannelByType from '../../utils/getChannelByType.ts'
|
2020-11-25 11:53:40 +00:00
|
|
|
import { ChannelPayload, GuildChannelPayload } from '../../types/channel.ts'
|
|
|
|
import { Guild } from '../../structures/guild.ts'
|
2020-10-30 14:51:40 +00:00
|
|
|
|
2020-11-01 11:22:09 +00:00
|
|
|
export const channelCreate: GatewayEventHandler = async (
|
2020-10-30 14:51:40 +00:00
|
|
|
gateway: Gateway,
|
2020-11-02 06:58:23 +00:00
|
|
|
d: ChannelPayload
|
2020-10-30 14:51:40 +00:00
|
|
|
) => {
|
2020-11-25 11:53:40 +00:00
|
|
|
const guild: undefined | Guild =
|
|
|
|
'guild_id' in d
|
|
|
|
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
|
|
await gateway.client.guilds.get((d as GuildChannelPayload).guild_id)
|
|
|
|
: undefined
|
2020-11-11 09:04:49 +00:00
|
|
|
const channel = getChannelByType(gateway.client, d, guild)
|
2020-10-30 14:51:40 +00:00
|
|
|
if (channel !== undefined) {
|
2020-11-01 11:22:09 +00:00
|
|
|
await gateway.client.channels.set(d.id, d)
|
2020-10-30 14:51:40 +00:00
|
|
|
gateway.client.emit('channelCreate', channel)
|
|
|
|
}
|
|
|
|
}
|