harmony/src/gateway/handlers/messageReactionRemoveEmoji.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-04-04 05:42:15 +00:00
import type { Gateway, GatewayEventHandler } from '../mod.ts'
2021-04-04 09:29:56 +00:00
import type { MessageReactionRemoveEmojiPayload } from '../../types/gateway.ts'
import type { TextChannel } from '../../structures/textChannel.ts'
2020-12-02 12:29:52 +00:00
export const messageReactionRemoveEmoji: GatewayEventHandler = async (
gateway: Gateway,
d: MessageReactionRemoveEmojiPayload
) => {
let channel = await gateway.client.channels.get<TextChannel>(d.channel_id)
if (channel === undefined)
channel = await gateway.client.channels.fetch<TextChannel>(d.channel_id)
if (channel === undefined) return
let message = await channel.messages.get(d.message_id)
if (message === undefined) {
if (gateway.client.fetchUncachedReactions === true) {
message = await channel.messages.fetch(d.message_id)
if (message === undefined) return
} else return
}
2020-12-26 06:49:52 +00:00
const emojiID = (d.emoji.id !== null ? d.emoji.id : d.emoji.name) as string
2020-12-24 00:59:32 +00:00
const reaction = await message.reactions.get(emojiID)
2020-12-02 12:29:52 +00:00
if (reaction === undefined) return
await reaction.users.flush()
gateway.client.emit('messageReactionRemoveEmoji', message, reaction.emoji)
}