mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
feat(uptime): add uptime monitor with refreshes
Introduces an uptime command and view to show how long the bot has been running. Adds a method to calculate uptime in bot.py, registers the command in help.py, and implements the command logic in a new uptime.py cog with a refresh button.
This commit is contained in:
18
bot.py
18
bot.py
@@ -4,6 +4,7 @@ import os
|
||||
import platform
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
import aiosqlite
|
||||
import discord
|
||||
@@ -125,6 +126,7 @@ class DiscordBot(commands.Bot):
|
||||
self.database = None
|
||||
self.bot_prefix = os.getenv("PREFIX")
|
||||
self.invite_link = os.getenv("INVITE_LINK")
|
||||
self.start_time = time.time()
|
||||
|
||||
async def init_db(self) -> None:
|
||||
async with aiosqlite.connect(
|
||||
@@ -225,6 +227,22 @@ class DiscordBot(commands.Bot):
|
||||
)
|
||||
)
|
||||
|
||||
def get_uptime(self) -> str:
|
||||
uptime_seconds = int(time.time() - self.start_time)
|
||||
days = uptime_seconds // 86400
|
||||
hours = (uptime_seconds % 86400) // 3600
|
||||
minutes = (uptime_seconds % 3600) // 60
|
||||
seconds = uptime_seconds % 60
|
||||
|
||||
if days > 0:
|
||||
return f"{days}d {hours}h {minutes}m {seconds}s"
|
||||
elif hours > 0:
|
||||
return f"{hours}h {minutes}m {seconds}s"
|
||||
elif minutes > 0:
|
||||
return f"{minutes}m {seconds}s"
|
||||
else:
|
||||
return f"{seconds}s"
|
||||
|
||||
async def on_message(self, message: discord.Message) -> None:
|
||||
"""
|
||||
The code in this event is executed every time someone sends a message, with or without the prefix
|
||||
|
||||
Reference in New Issue
Block a user