Skip to content

Commit

Permalink
⚡️ add false reaction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gitaalekhyapaul committed Feb 13, 2021
1 parent d32401c commit 7a1c219
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/helper/polls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export const createPoll = async (
serverLogger("internal-error", "Internal Error", err);
incomingMessage.channel.send(
`<@${messageType.incomingUser.id}>`,
createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
createBasicEmbed(
ERRORS.INTERNAL_ERROR(messageType.channelType),
"ERROR"
)
);
}
} else {
Expand All @@ -113,7 +116,9 @@ const addPoll = async (incomingMessage: Message, poll: pollSchema) => {
await pollMessage.react(option.emoji);
})
);
const pollCollector = pollMessage.createReactionCollector(pollEmojiFilter);
const pollCollector = pollMessage.createReactionCollector(pollEmojiFilter, {
dispose: true,
});
pollCollector.on("collect", async (reaction: MessageReaction, user: User) => {
const { result } = await db.updateOne(
{ pollID: poll.pollID, "options.emoji": reaction.emoji.name },
Expand All @@ -125,12 +130,27 @@ const addPoll = async (incomingMessage: Message, poll: pollSchema) => {
);
if (!(result.ok == 1)) throw "MongoDB Query Error: Failed to Add Reaction";
});
pollCollector.on("remove", async (reaction: MessageReaction, user: User) => {
const { result } = await db.updateOne(
{ pollID: poll.pollID, "options.emoji": reaction.emoji.name },
{
$pull: {
"options.$.reactions": `${user.username}#${user.discriminator}`,
},
}
);
if (!(result.ok == 1)) throw "MongoDB Query Error: Failed to Add Reaction";
});
incomingMessage.channel.send(
createBasicEmbed(
{
title: "**New Poll Created! :white_check_mark:**",
message:
"**Poll ID:** `" +
"**Check Results:** `" +
COMMANDS.prefix +
" " +
COMMANDS.createPoll +
" result " +
poll.pollID +
"`\n**Time of Creation:** " +
poll.timestamp,
Expand Down Expand Up @@ -184,7 +204,10 @@ export const getResult = async (
serverLogger("internal-error", "Internal Error", err);
incomingMessage.channel.send(
`<@${messageType.incomingUser.id}>`,
createBasicEmbed(ERRORS.INTERNAL_ERROR(messageType.channelType), "ERROR")
createBasicEmbed(
ERRORS.INTERNAL_ERROR(messageType.channelType),
"ERROR"
)
);
}
} else {
Expand Down

0 comments on commit 7a1c219

Please sign in to comment.