refactor(bot): ♻️ Move heartbeat update task to Utility cog.

This commit is contained in:
Nyeki.py
2024-10-25 23:31:31 -03:00
parent 924528cdba
commit d257759736
2 changed files with 12 additions and 9 deletions
-8
View File
@@ -80,8 +80,6 @@ class Payphone(commands.AutoShardedBot):
await self.redis.ping()
self.update_heartbeat.start()
print(f"Ready! Logged in as {self.user.display_name}.")
async def on_shard_ready(self, shard_id: int) -> None:
@@ -452,12 +450,6 @@ class Payphone(commands.AutoShardedBot):
name=self.user.display_name, icon_url=self.user.display_avatar.url
)
@tasks.loop(seconds=1)
async def update_heartbeat(self) -> None:
"""Updates the heartbeat timestamp."""
self.heartbeat.value = int(datetime.now(timezone.utc).timestamp())
bot = Payphone()
+12 -1
View File
@@ -1,7 +1,7 @@
from datetime import datetime, timezone
import discord
from discord.ext import commands
from discord.ext import commands, tasks
from payphone import bot
from payphone.cogs import base
@@ -12,6 +12,17 @@ class Utility(base.Cog):
def __init__(self, bot_instance: bot.Payphone):
self.bot = bot_instance
self.update_heartbeat.start()
async def cog_unload(self) -> None:
self.update_heartbeat.cancel()
@tasks.loop(seconds=5)
async def update_heartbeat(self) -> None:
"""Updates the heartbeat timestamp."""
self.bot.heartbeat.value = int(datetime.now(timezone.utc).timestamp())
@commands.command()
@commands.cooldown(1, 60, commands.BucketType.user)
@checks.is_unbanned()