2020-11-25 11:53:40 +00:00
|
|
|
import { Message } from '../../structures/message.ts'
|
2020-11-15 09:23:24 +00:00
|
|
|
import { TextChannel } from '../../structures/textChannel.ts'
|
2020-11-25 11:53:40 +00:00
|
|
|
import { MessagePayload } from '../../types/channel.ts'
|
2020-11-15 09:23:24 +00:00
|
|
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|