From 07eeb3085bafe9a3f2cdc6409565ba74687fca94 Mon Sep 17 00:00:00 2001 From: Grey Himmel Date: Fri, 3 May 2019 02:10:46 -0400 Subject: [PATCH] Remove question mark reaction (#86) * Update __init__.py Setting `do_query_message` to accept full payload * Update proxy.py Adding code to remove question mark reaction after sending the message card * Update proxy.py Fixing type declaration in recent changes * Fixing message grab Getting the channel the reaction was handled in and changing the `fetch_message` call to grab from the channel * Adding back pronouns option Not sure why it was removed, honestly * Fixing issues caused by PK using an outdated version of the lib. Whoops :') --- src/pluralkit/bot/__init__.py | 2 +- src/pluralkit/bot/proxy.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pluralkit/bot/__init__.py b/src/pluralkit/bot/__init__.py index ef2d062e..c2fca0f0 100644 --- a/src/pluralkit/bot/__init__.py +++ b/src/pluralkit/bot/__init__.py @@ -112,7 +112,7 @@ def run(config: Config): await proxy.try_delete_by_reaction(conn, client, payload.message_id, payload.user_id, logger) if payload.emoji.name in "\u2753\u2754": # Question mark async with pool.acquire() as conn: - await proxy.do_query_message(conn, client, payload.user_id, payload.message_id) + await proxy.do_query_message(conn, client, payload) @client.event async def on_error(event_name, *args, **kwargs): diff --git a/src/pluralkit/bot/proxy.py b/src/pluralkit/bot/proxy.py index 6f556080..2e309786 100644 --- a/src/pluralkit/bot/proxy.py +++ b/src/pluralkit/bot/proxy.py @@ -233,22 +233,26 @@ async def try_delete_by_reaction(conn, client: discord.Client, message_id: int, await handle_deleted_message(conn, client, message_id, original_message.content, logger) -async def do_query_message(conn, client: discord.Client, queryer_id: int, message_id: int) -> bool: +async def do_query_message(conn, client: discord.Client, payload: discord.RawReactionActionEvent) -> bool: # Find the message that was queried - msg = await db.get_message(conn, message_id) + msg = await db.get_message(conn, payload.message_id) if not msg: return False # Then DM the queryer the message embed card = await embeds.message_card(client, msg, include_pronouns=True) - user = client.get_user(queryer_id) + user = client.get_user(payload.user_id) if not user: # We couldn't find this user in the cache - bail return False - # Send the card to the user + # Remove reaction and send the card to the user try: + channel = await client.get_channel(payload.channel_id) + message = await channel.get_message(payload.message_id) + if message.guild and message.channel.permissions_for(message.guild.get_member(client.user.id)).manage_messages: + await message.remove_reaction(payload.emoji, user) await user.send(embed=card) except discord.Forbidden: # User doesn't have DMs enabled, not much we can do about that - pass \ No newline at end of file + pass