fix(bot): 🐛 Attempt to fix p.hangup.

This commit is contained in:
Nyeki.py
2024-10-18 00:35:32 -03:00
parent 7fd0801d78
commit 8cd1613e3c
2 changed files with 25 additions and 10 deletions
+12 -6
View File
@@ -173,6 +173,10 @@ class Calls(base.Cog):
i += 1 i += 1
if other_channel_id in last_calls_other_channels_ids: if other_channel_id in last_calls_other_channels_ids:
await self.bot.redis.sadd(
constants.CHANNELS_SEARCH_QUEUE, str(other_channel_id)
)
other_channel_id = await self.bot.redis.spop( other_channel_id = await self.bot.redis.spop(
constants.CHANNELS_SEARCH_QUEUE constants.CHANNELS_SEARCH_QUEUE
) )
@@ -180,9 +184,6 @@ class Calls(base.Cog):
if other_channel_id is None: if other_channel_id is None:
break break
await self.bot.redis.sadd(
constants.CHANNELS_SEARCH_QUEUE, str(other_channel_id)
)
continue continue
break break
@@ -354,12 +355,17 @@ class Calls(base.Cog):
i += 1 i += 1
if other_channel_id in last_calls_other_channels_ids: if other_channel_id in last_calls_other_channels_ids:
other_channel_id = await self.bot.redis.spop(
constants.CHANNELS_SEARCH_QUEUE
)
await self.bot.redis.sadd( await self.bot.redis.sadd(
constants.CHANNELS_SEARCH_QUEUE, str(other_channel_id) constants.CHANNELS_SEARCH_QUEUE, str(other_channel_id)
) )
other_channel_id = await self.bot.redis.spop(
constants.CHANNELS_SEARCH_QUEUE
)
if other_channel_id is None:
break
continue continue
break break
+13 -4
View File
@@ -5,19 +5,28 @@ import discord
from payphone.db import models from payphone.db import models
async def get_channel(channel: discord.TextChannel) -> models.Channel: async def get_channel(
channel: discord.TextChannel, for_update: bool = False
) -> models.Channel:
"""Returns a channel from the database, creating or updating it if it already exists. """Returns a channel from the database, creating or updating it if it already exists.
Args: Args:
channel (discord.TextChannel): The channel to fetch. channel (discord.TextChannel): The channel to fetch.
for_update (bool, optional): Whether the select should be FOR UPDATE or not.
Returns: Returns:
models.Channel: The channel row. models.Channel: The channel row.
""" """
row, _ = await models.Channel.update_or_create( model = models.Channel
id=channel.id, server=channel.guild.id
) if for_update:
model = model.select_for_update()
row = await model.get_or_none(id=channel.id)
if row is None:
row = await models.Channel.create(id=channel.id, server_id=channel.guild.id)
channel_name = channel.name.replace("discord", "d").replace("wumpus", "w") channel_name = channel.name.replace("discord", "d").replace("wumpus", "w")
webhook_name = f"Payphone #{channel_name}" webhook_name = f"Payphone #{channel_name}"