2021-04-04 09:29:56 +00:00
|
|
|
import type { Message } from '../../structures/message.ts'
|
|
|
|
import type { TextChannel } from '../../structures/textChannel.ts'
|
|
|
|
import type { MessagePayload } from '../../types/channel.ts'
|
2021-04-04 05:42:15 +00:00
|
|
|
import type { Gateway, GatewayEventHandler } from '../mod.ts'
|
2020-11-15 09:23:24 +00:00
|
|
|
|
|
|
|
export const messageUpdate: GatewayEventHandler = async (
|
|
|
|
gateway: Gateway,
|
2020-11-25 11:53:40 +00:00
|
|
|
d: MessagePayload
|
2020-11-15 09:23:24 +00:00
|
|
|
) => {
|
|
|
|
let channel = await gateway.client.channels.get<TextChannel>(d.channel_id)
|
|
|
|
// Fetch the channel if not cached
|
|
|
|
if (channel === undefined)
|
2020-12-02 08:02:00 +00:00
|
|
|
channel = await gateway.client.channels.fetch(d.channel_id)
|
|
|
|
|
|
|
|
if (channel === undefined) return
|
2020-11-15 09:23:24 +00:00
|
|
|
|
|
|
|
const message = await channel.messages.get(d.id)
|
2020-12-02 08:02:00 +00:00
|
|
|
if (message === undefined) return
|
|
|
|
const raw = await channel.messages._get(d.id)
|
|
|
|
if (raw === undefined) return
|
|
|
|
|
|
|
|
const newRaw = raw
|
|
|
|
Object.assign(newRaw, d)
|
|
|
|
await channel.messages.set(d.id, newRaw)
|
|
|
|
|
|
|
|
const newMsg = ((await channel.messages.get(d.id)) as unknown) as Message
|
2020-11-15 09:23:24 +00:00
|
|
|
gateway.client.emit('messageUpdate', message, newMsg)
|
|
|
|
}
|