2021-04-04 05:42:15 +00:00
|
|
|
import type { Gateway, GatewayEventHandler } from '../mod.ts'
|
2021-04-04 09:29:56 +00:00
|
|
|
import type { Guild } from '../../structures/guild.ts'
|
|
|
|
import type { WebhooksUpdatePayload } from '../../types/gateway.ts'
|
|
|
|
import type { GuildTextBasedChannel } from '../../structures/guildTextChannel.ts'
|
2020-12-02 12:29:52 +00:00
|
|
|
|
|
|
|
export const webhooksUpdate: GatewayEventHandler = async (
|
|
|
|
gateway: Gateway,
|
|
|
|
d: WebhooksUpdatePayload
|
|
|
|
) => {
|
|
|
|
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
|
|
|
|
if (guild === undefined) return
|
|
|
|
|
2021-03-19 15:39:14 +00:00
|
|
|
const channel: GuildTextBasedChannel | undefined = (await guild.channels.get(
|
2020-12-02 12:29:52 +00:00
|
|
|
d.channel_id
|
2021-03-19 15:39:14 +00:00
|
|
|
)) as GuildTextBasedChannel
|
2020-12-02 12:29:52 +00:00
|
|
|
if (channel === undefined)
|
|
|
|
gateway.client.emit('webhooksUpdateUncached', guild, d.channel_id)
|
|
|
|
else gateway.client.emit('webhooksUpdate', guild, channel)
|
|
|
|
}
|