2020-07-25 11:01:24 +00:00
|
|
|
import Event from "../core/event";
|
2020-08-14 12:50:24 +00:00
|
|
|
import {Permissions} from "discord.js";
|
2020-08-30 21:26:18 +00:00
|
|
|
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.
|
|
|
|
export const eventListeners: Map<string, (emote: string, id: string) => void> = new Map();
|
|
|
|
|
|
|
|
// Attached to the client, there can be one event listener attached to a message ID which is executed if present.
|
2020-08-14 12:50:24 +00:00
|
|
|
export default new Event<"messageReactionRemove">({
|
|
|
|
on(reaction, user)
|
2020-07-25 11:01:24 +00:00
|
|
|
{
|
2020-08-14 12:50:24 +00:00
|
|
|
const canDeleteEmotes = botHasPermission(reaction.message.guild, Permissions.FLAGS.MANAGE_MESSAGES);
|
2020-08-14 10:21:19 +00:00
|
|
|
|
|
|
|
if(!canDeleteEmotes)
|
|
|
|
{
|
|
|
|
const callback = eventListeners.get(reaction.message.id);
|
|
|
|
callback && callback(reaction.emoji.name, user.id);
|
|
|
|
}
|
2020-07-25 11:01:24 +00:00
|
|
|
}
|
|
|
|
});
|