2020-12-15 01:44:28 +00:00
|
|
|
import Event from "../core/event";
|
|
|
|
import {Permissions} from "discord.js";
|
|
|
|
import {botHasPermission} from "../core/lib";
|
2020-07-25 11:01:24 +00:00
|
|
|
|
|
|
|
// A list of message ID and callback pairs. You get the emote name and ID of the user reacting.
|
2020-12-15 07:56:09 +00:00
|
|
|
export const eventListeners: Map<string, (emote: string, id: string) => void> = new Map();
|
2020-07-25 11:01:24 +00:00
|
|
|
|
|
|
|
// Attached to the client, there can be one event listener attached to a message ID which is executed if present.
|
2020-12-15 01:44:28 +00:00
|
|
|
export default new Event<"messageReactionRemove">({
|
|
|
|
on(reaction, user) {
|
2020-12-15 07:56:09 +00:00
|
|
|
const canDeleteEmotes = botHasPermission(reaction.message.guild, Permissions.FLAGS.MANAGE_MESSAGES);
|
2020-10-15 09:23:24 +00:00
|
|
|
|
2020-12-15 01:44:28 +00:00
|
|
|
if (!canDeleteEmotes) {
|
|
|
|
const callback = eventListeners.get(reaction.message.id);
|
|
|
|
callback && callback(reaction.emoji.name, user.id);
|
|
|
|
}
|
2020-10-15 09:23:24 +00:00
|
|
|
}
|
|
|
|
});
|