2020-11-28 05:14:37 +00:00
|
|
|
import { Channel } from '../../structures/channel.ts'
|
2020-11-30 11:11:49 +00:00
|
|
|
import { ChannelPayload } from '../../types/channel.ts'
|
2020-11-28 05:14:37 +00:00
|
|
|
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)
|
2020-11-28 05:14:37 +00:00
|
|
|
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
|
2020-11-28 05:14:37 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|