harmony/src/gateway/handlers/channelCreate.ts

24 lines
793 B
TypeScript
Raw Normal View History

2021-04-04 05:42:15 +00:00
import type { Gateway, GatewayEventHandler } from '../mod.ts'
2021-04-04 11:27:02 +00:00
import getChannelByType from '../../utils/channel.ts'
2021-04-04 09:29:56 +00:00
import type {
ChannelPayload,
GuildChannelPayload
} from '../../types/channel.ts'
import type { Guild } from '../../structures/guild.ts'
export const channelCreate: GatewayEventHandler = async (
gateway: Gateway,
d: ChannelPayload
) => {
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)
if (channel !== undefined) {
await gateway.client.channels.set(d.id, d)
gateway.client.emit('channelCreate', channel)
}
}