1 |
rakin |
51 |
import BaseEvent from '../../utils/structures/BaseEvent'; |
2 |
|
|
import DiscordClient from '../../client/Client'; |
3 |
|
|
import { TextChannel } from 'discord.js'; |
4 |
|
|
|
5 |
|
|
export default class RawEvent extends BaseEvent { |
6 |
|
|
events = { |
7 |
|
|
MESSAGE_REACTION_ADD: 'messageReactionAdd', |
8 |
|
|
}; |
9 |
|
|
|
10 |
|
|
constructor() { |
11 |
|
|
super('raw'); |
12 |
|
|
} |
13 |
|
|
|
14 |
|
|
async run(client: DiscordClient, event: { d: any, t: keyof RawEvent['events'] }) { |
15 |
|
|
if (!this.events.hasOwnProperty(event.t)) |
16 |
|
|
return; |
17 |
|
|
|
18 |
|
|
const { d: data } = event; |
19 |
|
|
// const user = client.users.cache.find(i => i.id === data.user_id); |
20 |
|
|
const channel = <TextChannel> client.channels.cache.find(i => i.id === data.channel_id); |
21 |
|
|
|
22 |
|
|
if (channel) { |
23 |
|
|
if (channel.messages.cache.has(data.message_id)) |
24 |
|
|
return; |
25 |
|
|
|
26 |
|
|
const message = await channel.messages.fetch(data.message_id); |
27 |
|
|
|
28 |
|
|
const emojiKey = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name; |
29 |
|
|
const reaction = message.reactions.cache.get(emojiKey); |
30 |
|
|
|
31 |
|
|
client.emit(this.events[event.t], reaction, message); |
32 |
|
|
} |
33 |
|
|
} |
34 |
|
|
} |