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 :')
This commit is contained in:
Grey Himmel 2019-05-03 02:10:46 -04:00 committed by Astrid
parent 5590cfc90f
commit 07eeb3085b
2 changed files with 10 additions and 6 deletions

View File

@ -112,7 +112,7 @@ def run(config: Config):
await proxy.try_delete_by_reaction(conn, client, payload.message_id, payload.user_id, logger) await proxy.try_delete_by_reaction(conn, client, payload.message_id, payload.user_id, logger)
if payload.emoji.name in "\u2753\u2754": # Question mark if payload.emoji.name in "\u2753\u2754": # Question mark
async with pool.acquire() as conn: 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 @client.event
async def on_error(event_name, *args, **kwargs): async def on_error(event_name, *args, **kwargs):

View File

@ -233,21 +233,25 @@ 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) 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 # 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: if not msg:
return False return False
# Then DM the queryer the message embed # Then DM the queryer the message embed
card = await embeds.message_card(client, msg, include_pronouns=True) 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: if not user:
# We couldn't find this user in the cache - bail # We couldn't find this user in the cache - bail
return False return False
# Send the card to the user # Remove reaction and send the card to the user
try: 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) await user.send(embed=card)
except discord.Forbidden: except discord.Forbidden:
# User doesn't have DMs enabled, not much we can do about that # User doesn't have DMs enabled, not much we can do about that