swc/bundler/tests/.cache/deno/b9ddd526d93036b220d39d9c15292e5d841db765.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

43 lines
1.7 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/handlers/messages/MESSAGE_REACTION_ADD.ts
import { botId, eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { MessageReactionAdd } from "../../types/messages/message_reaction_add.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
const payload = data.d as MessageReactionAdd;
const message = await cacheHandlers.get("messages", snowflakeToBigint(payload.messageId));
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: snowflakeToBigint(payload.userId) === botId,
emoji: { ...payload.emoji, id: payload.emoji.id || undefined },
};
message.reactions = message.reactions ? [...message.reactions, newReaction] : [newReaction];
}
await cacheHandlers.set("messages", snowflakeToBigint(payload.messageId), message);
}
if (payload.member && payload.guildId) {
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
if (guild) {
const discordenoMember = await structures.createDiscordenoMember(payload.member, guild.id);
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
}
}
eventHandlers.reactionAdd?.(payload, message);
}