Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: fix: joyboard duplicates while reacting and unreacting fast #275

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions chiya/cogs/listeners/joyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Joyboard(commands.Cog):

def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
self.cache = {"add": set(), "remove": set()}
self.cache = {"add": set()}

def generate_color(self, joy_count: int) -> int:
"""
Expand Down Expand Up @@ -188,31 +188,25 @@ async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent)
"""
Update the joy count in the embed if the joys were reacted. Delete joy embed if the joy count is below threshold
"""
cache_data = (payload.message_id, payload.channel_id)

if (
not self.check_emoji(payload.emoji, payload.guild_id)
or cache_data in self.cache["remove"]
):
return

self.cache["remove"].add(cache_data)

message = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id)

db = database.Database().get()
result = db["joyboard"].find_one(channel_id=payload.channel_id, message_id=payload.message_id)

if not result:
self.cache["remove"].remove(cache_data)
return db.close()

joyboard_channel = discord.utils.get(message.guild.channels, id=config["channels"]["joyboard"]["channel_id"])

try:
joy_embed = await joyboard_channel.fetch_message(result["joy_embed_id"])
except discord.NotFound:
self.cache["remove"].remove(cache_data)
return db.close()

joy_count = await self.get_joy_count(message)
Expand All @@ -221,7 +215,6 @@ async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent)
db["joyboard"].delete(channel_id=payload.channel_id, message_id=payload.message_id)
db.commit()
db.close()
self.cache["remove"].remove(cache_data)
return await joy_embed.delete()

embed_dict = joy_embed.embeds[0].to_dict()
Expand All @@ -233,7 +226,6 @@ async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent)
)

db.close()
self.cache["remove"].remove(cache_data)

@commands.Cog.listener()
async def on_raw_message_delete(self, payload):
Expand Down
Loading