feat(events): add messageUpdate
This commit is contained in:
parent
5dbd4a84f5
commit
943b946e5b
3 changed files with 37 additions and 1 deletions
|
@ -14,6 +14,7 @@ import { messageCreate } from './messageCreate.ts'
|
||||||
import { resume } from './resume.ts'
|
import { resume } from './resume.ts'
|
||||||
import { reconnect } from './reconnect.ts'
|
import { reconnect } from './reconnect.ts'
|
||||||
import { messageDelete } from "./messageDelete.ts"
|
import { messageDelete } from "./messageDelete.ts"
|
||||||
|
import { messageUpdate } from "./messageUpdate.ts"
|
||||||
|
|
||||||
export const gatewayHandlers: {
|
export const gatewayHandlers: {
|
||||||
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
||||||
|
@ -42,7 +43,7 @@ export const gatewayHandlers: {
|
||||||
INVITE_CREATE: undefined,
|
INVITE_CREATE: undefined,
|
||||||
INVITE_DELETE: undefined,
|
INVITE_DELETE: undefined,
|
||||||
MESSAGE_CREATE: messageCreate,
|
MESSAGE_CREATE: messageCreate,
|
||||||
MESSAGE_UPDATE: undefined,
|
MESSAGE_UPDATE: messageUpdate,
|
||||||
MESSAGE_DELETE: messageDelete,
|
MESSAGE_DELETE: messageDelete,
|
||||||
MESSAGE_DELETE_BULK: undefined,
|
MESSAGE_DELETE_BULK: undefined,
|
||||||
MESSAGE_REACTION_ADD: undefined,
|
MESSAGE_REACTION_ADD: undefined,
|
||||||
|
|
25
src/gateway/handlers/messageUpdate.ts
Normal file
25
src/gateway/handlers/messageUpdate.ts
Normal 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)
|
||||||
|
}
|
|
@ -26,6 +26,16 @@ client.on('messageDeleteUncached', (d: MessageDeletePayload) => {
|
||||||
console.log(`Uncached Message Deleted: ${d.id} in ${d.channel_id}`)
|
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('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`))
|
||||||
|
|
||||||
client.on("commandError", console.error)
|
client.on("commandError", console.error)
|
||||||
|
|
Loading…
Reference in a new issue