feat(bot): 🎉 Create a redis client from scratch.
This commit is contained in:
+60
-54
@@ -103,8 +103,8 @@ class Calls(base.Cog):
|
||||
if last_calls_rss_channels_map[call_rs.call_id] != call_rs.channel_id:
|
||||
last_calls_other_channels_ids.add(call_rs.channel_id)
|
||||
|
||||
other_channel_id: int = await self.bot.redis.spop(
|
||||
constants.CHANNELS_SEARCH_QUEUE
|
||||
other_channel_id: int = next(
|
||||
iter(await self.bot.redis.spop(constants.CHANNELS_SEARCH_QUEUE)), None
|
||||
)
|
||||
i = 0
|
||||
|
||||
@@ -127,8 +127,9 @@ class Calls(base.Cog):
|
||||
constants.CHANNELS_SEARCH_QUEUE, str(other_channel_id)
|
||||
)
|
||||
|
||||
other_channel_id = await self.bot.redis.spop(
|
||||
constants.CHANNELS_SEARCH_QUEUE
|
||||
other_channel_id = next(
|
||||
iter(await self.bot.redis.spop(constants.CHANNELS_SEARCH_QUEUE)),
|
||||
None,
|
||||
)
|
||||
|
||||
if other_channel_id is None:
|
||||
@@ -293,8 +294,8 @@ class Calls(base.Cog):
|
||||
if last_calls_rss_channels_map[call_rs.call_id] != call_rs.channel_id:
|
||||
last_calls_other_channels_ids.add(call_rs.channel_id)
|
||||
|
||||
other_channel_id: int = await self.bot.redis.spop(
|
||||
constants.CHANNELS_SEARCH_QUEUE
|
||||
other_channel_id: int = next(
|
||||
iter(await self.bot.redis.spop(constants.CHANNELS_SEARCH_QUEUE)), None
|
||||
)
|
||||
i = 0
|
||||
|
||||
@@ -317,8 +318,9 @@ class Calls(base.Cog):
|
||||
constants.CHANNELS_SEARCH_QUEUE, str(other_channel_id)
|
||||
)
|
||||
|
||||
other_channel_id = await self.bot.redis.spop(
|
||||
constants.CHANNELS_SEARCH_QUEUE
|
||||
other_channel_id = next(
|
||||
iter(await self.bot.redis.spop(constants.CHANNELS_SEARCH_QUEUE)),
|
||||
None,
|
||||
)
|
||||
|
||||
if other_channel_id is None:
|
||||
@@ -762,45 +764,50 @@ class Calls(base.Cog):
|
||||
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGES_TEMPLATE % call.id,
|
||||
message.id,
|
||||
orjson.dumps(
|
||||
{
|
||||
"id": message.id,
|
||||
"call_id": call.id,
|
||||
"channel_id": channel.id,
|
||||
"user_id": user.id,
|
||||
"profile_id": profile.id,
|
||||
"mask": call_rs.mask if call_rs.is_masked else None,
|
||||
"propagation_id": webhook_message.id if webhook_message else None,
|
||||
"propagation_channel_id": (
|
||||
other_channel.id if webhook_message else None
|
||||
),
|
||||
"replying_to_id": replying_to_id,
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
}
|
||||
).decode(),
|
||||
{
|
||||
message.id: orjson.dumps(
|
||||
{
|
||||
"id": message.id,
|
||||
"call_id": call.id,
|
||||
"channel_id": channel.id,
|
||||
"user_id": user.id,
|
||||
"profile_id": profile.id,
|
||||
"mask": call_rs.mask if call_rs.is_masked else None,
|
||||
"propagation_id": (
|
||||
webhook_message.id if webhook_message else None
|
||||
),
|
||||
"propagation_channel_id": (
|
||||
other_channel.id if webhook_message else None
|
||||
),
|
||||
"replying_to_id": replying_to_id,
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
}
|
||||
).decode()
|
||||
},
|
||||
)
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_CONTENTS_TEMPLATE % call.id,
|
||||
constants.CALL_MESSAGE_CONTENTS_HASH_TEMPLATE % (message.id, 1),
|
||||
orjson.dumps(
|
||||
{
|
||||
"message_id": message.id,
|
||||
"content": cleaned_content,
|
||||
"was_propagated": not bool(blocked_word),
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
}
|
||||
).decode(),
|
||||
{
|
||||
constants.CALL_MESSAGE_CONTENTS_HASH_TEMPLATE
|
||||
% (message.id, 1): orjson.dumps(
|
||||
{
|
||||
"message_id": message.id,
|
||||
"content": cleaned_content,
|
||||
"was_propagated": not bool(blocked_word),
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
}
|
||||
).decode()
|
||||
},
|
||||
)
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_CONTENT_ITERATIONS_TEMPLATE % call.id, message.id, 1
|
||||
constants.CALL_MESSAGE_CONTENT_ITERATIONS_TEMPLATE % call.id,
|
||||
{message.id: 1},
|
||||
)
|
||||
|
||||
if webhook_message is not None:
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_FROM_PROPAGATION_TEMPLATE % call.id,
|
||||
webhook_message.id,
|
||||
message.id,
|
||||
{webhook_message.id: message.id},
|
||||
)
|
||||
|
||||
if replying_to_id is not None:
|
||||
@@ -811,18 +818,16 @@ class Calls(base.Cog):
|
||||
if other_replies is None:
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_REPLIES_TEMPLATE % call.id,
|
||||
replying_to_id,
|
||||
message.id,
|
||||
{replying_to_id: message.id},
|
||||
)
|
||||
|
||||
else:
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_REPLIES_TEMPLATE % call.id,
|
||||
replying_to_id,
|
||||
other_replies + f",{message.id}",
|
||||
{replying_to_id: other_replies + f",{message.id}"},
|
||||
)
|
||||
|
||||
await pipe.exec()
|
||||
await pipe.execute()
|
||||
|
||||
@commands.Cog.listener()
|
||||
@commands.guild_only()
|
||||
@@ -862,8 +867,7 @@ class Calls(base.Cog):
|
||||
|
||||
await self.bot.redis.hset(
|
||||
constants.CALL_MESSAGES_TEMPLATE % channel.call_id,
|
||||
message.id,
|
||||
orjson.dumps(message_dict).decode(),
|
||||
{message.id: orjson.dumps(message_dict).decode()},
|
||||
)
|
||||
|
||||
other_channel = await models.Channel.get_or_none(
|
||||
@@ -975,18 +979,20 @@ class Calls(base.Cog):
|
||||
)
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_CONTENTS_TEMPLATE % channel.call_id,
|
||||
constants.CALL_MESSAGE_CONTENTS_HASH_TEMPLATE % (message.id, iteration + 1),
|
||||
orjson.dumps(
|
||||
{
|
||||
"message_id": message.id,
|
||||
"content": cleaned_content,
|
||||
"was_propagated": not bool(blocked_word),
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
}
|
||||
).decode(),
|
||||
{
|
||||
constants.CALL_MESSAGE_CONTENTS_HASH_TEMPLATE
|
||||
% (message.id, iteration + 1): orjson.dumps(
|
||||
{
|
||||
"message_id": message.id,
|
||||
"content": cleaned_content,
|
||||
"was_propagated": not bool(blocked_word),
|
||||
"created_at": datetime.now(timezone.utc),
|
||||
}
|
||||
).decode()
|
||||
},
|
||||
)
|
||||
|
||||
await pipe.exec()
|
||||
await pipe.execute()
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
webhook = other_channel.webhook(session)
|
||||
|
||||
Reference in New Issue
Block a user