diff --git a/payphone/cogs/calls/cog.py b/payphone/cogs/calls/cog.py index 5c13cc9..5b325ae 100644 --- a/payphone/cogs/calls/cog.py +++ b/payphone/cogs/calls/cog.py @@ -16,10 +16,10 @@ import aiohttp import orjson from payphone import bot -from payphone.db import utils, models +from payphone.db import utils as dbutils, models from payphone.cogs import base from payphone.cogs.calls import embeds -from payphone.core import constants, checks, censorship, formatting +from payphone.core import constants, checks, censorship, formatting, utils from payphone.core.redis import redis @@ -45,8 +45,8 @@ class Calls(base.Cog): pipe = redis.pipeline() - pipe.smembers(constants.MESSAGES_QUEUE) - pipe.smembers(constants.MESSAGE_CONTENTS_QUEUE) + pipe.hgetall(constants.MESSAGES_QUEUE) + pipe.hgetall(constants.MESSAGE_CONTENTS_QUEUE) pipe.delete( constants.MESSAGES_QUEUE, @@ -57,11 +57,14 @@ class Calls(base.Cog): messages, message_contents, _ = await pipe.execute() messages = sorted( - [models.Message(**orjson.loads(msg)) for msg in messages], + [models.Message(**orjson.loads(msg)) for msg in messages.values()], key=lambda m: m.created_at, ) message_contents = sorted( - [models.MessageContent(**orjson.loads(msg)) for msg in message_contents], + [ + models.MessageContent(**orjson.loads(msg)) + for msg in message_contents.values() + ], key=lambda m: m.created_at, ) @@ -233,7 +236,7 @@ class Calls(base.Cog): break - channel = await utils.get_channel(ctx.channel) + channel = await dbutils.get_channel(ctx.channel) if other_channel_id is not None: await redis.sadd( @@ -249,7 +252,7 @@ class Calls(base.Cog): call = await models.Call.create(is_nsfw=ctx.channel.is_nsfw()) - user, profile = await utils.get_user(ctx.author) + user, profile = await dbutils.get_user(ctx.author) await models.CallUserChannelRelationship.create( call=call, @@ -426,7 +429,7 @@ class Calls(base.Cog): call = await models.Call.create(is_nsfw=ctx.channel.is_nsfw()) - user, profile = await utils.get_user(ctx.author) + user, profile = await dbutils.get_user(ctx.author) await models.CallUserChannelRelationship.create( call=call, @@ -492,7 +495,7 @@ class Calls(base.Cog): ) if is_on_call: - channel = await utils.get_channel(ctx.channel) + channel = await dbutils.get_channel(ctx.channel) call = await models.Call.get(id=channel.call_id).prefetch_related( "channels" @@ -559,7 +562,7 @@ class Calls(base.Cog): - ``: The reason why you're reporting the call. """ - user, _ = await utils.get_user(ctx.author) + user, _ = await dbutils.get_user(ctx.author) channel_id = ctx.channel.id if call_id is None: @@ -702,7 +705,7 @@ class Calls(base.Cog): if is_banned: return - channel = await utils.get_channel(message.channel) + channel = await dbutils.get_channel(message.channel) try: call = await models.Call.get(id=channel.call_id).prefetch_related( @@ -721,7 +724,7 @@ class Calls(base.Cog): # BUG: The call wasn't properly set up. return - user, profile = await utils.get_user(message.author) + user, profile = await dbutils.get_user(message.author) call_rss = await models.CallUserChannelRelationship.filter( call=call, channel=channel @@ -795,8 +798,9 @@ class Calls(base.Cog): pipe = redis.pipeline() - pipe.sadd( + pipe.hset( constants.MESSAGES_QUEUE, + message.id, orjson.dumps( { "id": message.id, @@ -814,8 +818,9 @@ class Calls(base.Cog): } ), ) - pipe.sadd( + pipe.hset( constants.MESSAGE_CONTENTS_QUEUE, + message.id, orjson.dumps( { "message_id": message.id, diff --git a/payphone/core/utils.py b/payphone/core/utils.py index e407cea..a46f6ed 100644 --- a/payphone/core/utils.py +++ b/payphone/core/utils.py @@ -5,11 +5,11 @@ T = TypeVar("T") U = TypeVar("U") -def deduplicate(iter: Iterable[T], key: Callable[[T], U] = lambda i: i) -> list[T]: +def deduplicate(i: Iterable[T], key: Callable[[T], U] = lambda i: i) -> list[T]: """Deduplicates an Iterable. Args: - iter (Iterable[T]): The iterable with items to deduplicate. + i (Iterable[T]): The iterable with items to deduplicate. key (Callable[[T], U], optional): The key by which to deduplicate. Defaults to `lambda i: i`. Returns: @@ -20,8 +20,8 @@ def deduplicate(iter: Iterable[T], key: Callable[[T], U] = lambda i: i) -> list[ result = [] - for i in iter: - if key(i) not in found_keys: - result.append(i) + for item in i: + if key(item) not in found_keys: + result.append(item) return result