mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
refactor: rename controllers to handlers and handlers to helpers (#660)
* refactor: rename controllers to handlers and handlers to helpers * fmt
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { botID, eventHandlers } from "../../bot.ts";
|
||||
import { DiscordPayload, MessageReactionPayload } from "../../types/mod.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
|
||||
export async function handleMessageReactionRemove(
|
||||
data: DiscordPayload,
|
||||
) {
|
||||
const payload = data.d as MessageReactionPayload;
|
||||
const message = await cacheHandlers.get("messages", payload.message_id);
|
||||
|
||||
if (message) {
|
||||
const reactionExisted = message.reactions?.find(
|
||||
(reaction) =>
|
||||
reaction.emoji.id === payload.emoji.id &&
|
||||
reaction.emoji.name === payload.emoji.name,
|
||||
);
|
||||
|
||||
if (reactionExisted) reactionExisted.count--;
|
||||
else {
|
||||
const newReaction = {
|
||||
count: 1,
|
||||
me: payload.user_id === botID,
|
||||
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
|
||||
};
|
||||
message.reactions = message.reactions
|
||||
? [...message.reactions, newReaction]
|
||||
: [newReaction];
|
||||
}
|
||||
|
||||
await cacheHandlers.set("messages", payload.message_id, message);
|
||||
}
|
||||
|
||||
if (payload.member && payload.guild_id) {
|
||||
const guild = await cacheHandlers.get("guilds", payload.guild_id);
|
||||
if (guild) {
|
||||
const memberStruct = await structures.createMemberStruct(
|
||||
payload.member,
|
||||
guild.id,
|
||||
);
|
||||
await cacheHandlers.set("members", memberStruct.id, memberStruct);
|
||||
}
|
||||
}
|
||||
|
||||
const uncachedOptions = {
|
||||
...payload,
|
||||
id: payload.message_id,
|
||||
channelID: payload.channel_id,
|
||||
guildID: payload.guild_id,
|
||||
};
|
||||
|
||||
eventHandlers.reactionRemove?.(
|
||||
uncachedOptions,
|
||||
payload.emoji,
|
||||
payload.user_id,
|
||||
message,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user