Merge pull request #40 from Payphone-Bot/39-discorduserid-reply-converter-not-working-on-propagated-messages-during-call

fix(bot): 🐛 `DiscordUserID` replies not working on unflushed propagated messages.
This commit is contained in:
Rafael Bradley
2024-10-22 15:41:36 -03:00
committed by GitHub
2 changed files with 33 additions and 4 deletions
+31 -4
View File
@@ -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:
+2
View File
@@ -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)
]