fix(bot): 🐛 Calls not being hung up after 1 or 15 minutes.
This commit is contained in:
+13
-16
@@ -1,7 +1,5 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
import asyncio
|
||||
|
||||
import secrets
|
||||
|
||||
import discord
|
||||
@@ -26,15 +24,15 @@ class Calls(base.Cog):
|
||||
def __init__(self, bot_instance: bot.Payphone):
|
||||
self.bot = bot_instance
|
||||
|
||||
self.hangup_calls.add_exception_type(Exception)
|
||||
self.hangup_calls.start()
|
||||
|
||||
def cog_unload(self) -> None:
|
||||
self.hangup_calls.stop()
|
||||
self.hangup_calls.cancel()
|
||||
|
||||
return super().cog_unload()
|
||||
|
||||
@tasks.loop(minutes=1)
|
||||
@transactions.atomic()
|
||||
@tasks.loop(seconds=15)
|
||||
async def hangup_calls(self) -> None:
|
||||
"""Hangs up inactive calls.
|
||||
|
||||
@@ -58,11 +56,13 @@ class Calls(base.Cog):
|
||||
if (
|
||||
message is None
|
||||
and call.started_at < datetime.now(timezone.utc) - timedelta(minutes=1)
|
||||
) or message.created_at < datetime.now(timezone.utc) - timedelta(
|
||||
minutes=15
|
||||
) or (
|
||||
message is not None
|
||||
and message.created_at
|
||||
< datetime.now(timezone.utc) - timedelta(minutes=15)
|
||||
):
|
||||
for channel in call.channels:
|
||||
hung_up_channel_ids += channel.id
|
||||
hung_up_channel_ids.append(channel.id)
|
||||
|
||||
try:
|
||||
await self.bot.get_partial_messageable(channel.id).send(
|
||||
@@ -72,14 +72,11 @@ class Calls(base.Cog):
|
||||
except errors.DiscordException:
|
||||
pass
|
||||
|
||||
await self.bot.redis.srem(constants.CHANNELS_ONCALL_SET, *hung_up_channel_ids)
|
||||
|
||||
@hangup_calls.before_loop
|
||||
async def before_hangup_calls(self):
|
||||
"""Wait until the bot is ready to start looping."""
|
||||
|
||||
await self.bot.wait_until_ready()
|
||||
await asyncio.wait(5)
|
||||
if len(hung_up_channel_ids) > 0:
|
||||
await self.bot.redis.srem(
|
||||
constants.CHANNELS_ONCALL_SET, *hung_up_channel_ids
|
||||
)
|
||||
await models.Channel.filter(id__in=hung_up_channel_ids).update(call=None)
|
||||
|
||||
@commands.command(aliases=["c"])
|
||||
@commands.guild_only()
|
||||
|
||||
Reference in New Issue
Block a user