refactor(bot): ♻️ Move heartbeat update task to Utility cog.
This commit is contained in:
@@ -80,8 +80,6 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
|
|
||||||
await self.redis.ping()
|
await self.redis.ping()
|
||||||
|
|
||||||
self.update_heartbeat.start()
|
|
||||||
|
|
||||||
print(f"Ready! Logged in as {self.user.display_name}.")
|
print(f"Ready! Logged in as {self.user.display_name}.")
|
||||||
|
|
||||||
async def on_shard_ready(self, shard_id: int) -> None:
|
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
|
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()
|
bot = Payphone()
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands, tasks
|
||||||
|
|
||||||
from payphone import bot
|
from payphone import bot
|
||||||
from payphone.cogs import base
|
from payphone.cogs import base
|
||||||
@@ -12,6 +12,17 @@ class Utility(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.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.command()
|
||||||
@commands.cooldown(1, 60, commands.BucketType.user)
|
@commands.cooldown(1, 60, commands.BucketType.user)
|
||||||
@checks.is_unbanned()
|
@checks.is_unbanned()
|
||||||
|
|||||||
Reference in New Issue
Block a user