2020-11-28 05:14:37 +00:00
|
|
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
|
|
|
import { Guild } from '../../structures/guild.ts'
|
2020-12-02 08:02:00 +00:00
|
|
|
import { WebhooksUpdatePayload } from '../../types/gateway.ts'
|
|
|
|
import { GuildTextChannel } from '../../structures/textChannel.ts'
|
2020-11-28 05:14:37 +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
|
|
|
|
|
2020-12-02 08:02:00 +00:00
|
|
|
const channel: GuildTextChannel | undefined = (await guild.channels.get(
|
|
|
|
d.channel_id
|
|
|
|
)) as GuildTextChannel
|
|
|
|
if (channel === undefined)
|
|
|
|
gateway.client.emit('webhooksUpdateUncached', guild, d.channel_id)
|
2020-11-28 05:14:37 +00:00
|
|
|
else gateway.client.emit('webhooksUpdate', guild, channel)
|
2020-12-02 08:02:00 +00:00
|
|
|
}
|