harmony/src/gateway/handlers/channelUpdate.ts

23 lines
1 KiB
TypeScript
Raw Normal View History

import { Channel } from '../../structures/channel.ts'
2020-11-30 11:11:49 +00:00
import { ChannelPayload } from '../../types/channel.ts'
import { Gateway, GatewayEventHandler } from '../index.ts'
export const channelUpdate: GatewayEventHandler = async (
gateway: Gateway,
d: ChannelPayload
) => {
2020-11-30 11:11:49 +00:00
const oldChannel = await gateway.client.channels.get(d.id)
await gateway.client.channels.set(d.id, d)
2020-11-30 11:11:49 +00:00
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const newChannel = (await gateway.client.channels.get(d.id)) as Channel
if (oldChannel !== undefined) {
// (DjDeveloperr): Already done by ChannelsManager. I'll recheck later
// if ('guild_id' in d) {
// // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
// (newChannel as GuildChannel).guild = await gateway.client.guilds.get((d as GuildChannelPayload).guild_id) as Guild
// }
gateway.client.emit('channelUpdate', oldChannel, newChannel)
} else gateway.client.emit('channelUpdateUncached', newChannel)
}