feat(events): add messageUpdate

This commit is contained in:
DjDeveloperr 2020-11-15 14:53:24 +05:30
parent 5dbd4a84f5
commit 943b946e5b
3 changed files with 37 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import { messageCreate } from './messageCreate.ts'
import { resume } from './resume.ts'
import { reconnect } from './reconnect.ts'
import { messageDelete } from "./messageDelete.ts"
import { messageUpdate } from "./messageUpdate.ts"
export const gatewayHandlers: {
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
@ -42,7 +43,7 @@ export const gatewayHandlers: {
INVITE_CREATE: undefined,
INVITE_DELETE: undefined,
MESSAGE_CREATE: messageCreate,
MESSAGE_UPDATE: undefined,
MESSAGE_UPDATE: messageUpdate,
MESSAGE_DELETE: messageDelete,
MESSAGE_DELETE_BULK: undefined,
MESSAGE_REACTION_ADD: undefined,

View file

@ -0,0 +1,25 @@
import { Message } from "../../structures/message.ts"
import { TextChannel } from '../../structures/textChannel.ts'
import { User } from "../../structures/user.ts"
import { Gateway, GatewayEventHandler } from '../index.ts'
export const messageUpdate: GatewayEventHandler = async (
gateway: Gateway,
d: any
) => {
let channel = await gateway.client.channels.get<TextChannel>(d.channel_id)
// Fetch the channel if not cached
if (channel === undefined)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
channel = (await gateway.client.channels.fetch(d.channel_id)) as TextChannel
const message = await channel.messages.get(d.id)
const author = new User(gateway.client, d.author)
const newMsg = new Message(gateway.client, d, channel, author)
if (message === undefined) {
await channel.messages.set(d.id, d)
return gateway.client.emit('messageUpdateUncached', newMsg)
}
await channel.messages.set(d.id, d)
gateway.client.emit('messageUpdate', message, newMsg)
}

View file

@ -26,6 +26,16 @@ client.on('messageDeleteUncached', (d: MessageDeletePayload) => {
console.log(`Uncached Message Deleted: ${d.id} in ${d.channel_id}`)
})
client.on('messageUpdate', (before: Message, after: Message) => {
console.log('Message Update')
console.log(`Before: ${before.author.tag}: ${before.content}`)
console.log(`After: ${after.author.tag}: ${after.content}`)
})
client.on('messageUpdateUncached', (msg: Message) => {
console.log(`Message: ${msg.author.tag}: ${msg.content}`)
})
// client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`))
client.on("commandError", console.error)