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