From 82db5dd562a1ff06a87ccb19ec8eaed608503d0e Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:40:15 -0300 Subject: [PATCH] fix(bot): :bug: `DiscordUserID` replies not working on unflushed propagated messages. --- payphone/core/converters.py | 35 +++++++++++++++++++++++++++++++---- run.py | 2 ++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/payphone/core/converters.py b/payphone/core/converters.py index 055dc1a..cc94a8f 100644 --- a/payphone/core/converters.py +++ b/payphone/core/converters.py @@ -5,8 +5,11 @@ from discord.ext.commands import converter from tortoise import expressions +import orjson + from payphone.db import models -from payphone.core import exceptions +from payphone.core import exceptions, constants +from payphone.core.redis import redis class Timedelta(converter.Converter): @@ -49,7 +52,7 @@ class DiscordUserID(converter.Converter): if argument.isdecimal() and len(argument) in range(17, 20): return int(argument) - + if len(argument) > 17 and argument[2:-1].isdecimal(): return int(argument[2:-1]) @@ -74,10 +77,34 @@ class DiscordUserID(converter.Converter): if row is not None: return row.user_id - raise converter.BadArgument() + channel = await models.Channel.get_or_none(id=ctx.channel.id) + + if channel is None: + raise converter.BadArgument() + + original_message_id = await redis.hget( + constants.CALL_MESSAGE_FROM_PROPAGATION_TEMPLATE + % channel.call_id, + ref.message_id, + ) + + if original_message_id is None: + raise converter.BadArgument() + + original_message_json = await redis.hget( + constants.CALL_MESSAGES_TEMPLATE % channel.call_id, + int(original_message_id), + ) + + if original_message_json is None: + raise converter.BadArgument() + + original_message_dict = orjson.loads(original_message_json) + + return original_message_dict["user_id"] return msg.author.id - + user = await models.User.get_or_none(username=argument) if user is not None: diff --git a/run.py b/run.py index 79cea41..971fe17 100644 --- a/run.py +++ b/run.py @@ -33,6 +33,8 @@ if __name__ == "__main__": shard_count = info["shards"] + print(f"Starting {shard_count} shard{"s" if shard_count != 1 else ""}.") + ps: list[mp.Process] = [ mp.Process(target=shard, args=(i, shard_count)) for i in range(shard_count) ]