TravBot-v3/src/events/messageReactionRemove.ts

25 lines
841 B
TypeScript
Raw Normal View History

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-10-15 09:23:24 +00:00
export const eventListeners: Map<
2020-12-15 01:44:28 +00:00
string,
(emote: string, id: string) => void
2020-10-15 09:23:24 +00:00
> = 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) {
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
}
});