From 3e97a4cad516725e27655145ed166b428ac8dc10 Mon Sep 17 00:00:00 2001 From: cherryl1k <102343489+cherryl1k@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:25:42 -0500 Subject: [PATCH 1/2] feat: added uptime and current branch to status --- tux/bot.py | 1 + tux/cogs/utility/ping.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tux/bot.py b/tux/bot.py index 2e2f49491..0d367b534 100644 --- a/tux/bot.py +++ b/tux/bot.py @@ -62,6 +62,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.emoji_manager = EmojiManager(self) self.console = Console(stderr=True, force_terminal=True) + self.uptime = discord.utils.utcnow().timestamp() logger.debug("Creating bot setup task") self.setup_task = asyncio.create_task(self.setup(), name="bot_setup") diff --git a/tux/cogs/utility/ping.py b/tux/cogs/utility/ping.py index c52342acb..2d9e169cc 100644 --- a/tux/cogs/utility/ping.py +++ b/tux/cogs/utility/ping.py @@ -1,8 +1,11 @@ +from datetime import UTC, datetime + import psutil from discord.ext import commands from tux.bot import Tux from tux.ui.embeds import EmbedCreator +from tux.utils.env import get_current_env from tux.utils.functions import generate_usage @@ -13,6 +16,7 @@ def __init__(self, bot: Tux) -> None: @commands.hybrid_command( name="ping", + aliases=["status"], ) async def ping(self, ctx: commands.Context[Tux]) -> None: """ @@ -27,6 +31,23 @@ async def ping(self, ctx: commands.Context[Tux]) -> None: # Get the latency of the bot in milliseconds discord_ping = round(self.bot.latency * 1000) + environment = get_current_env() + + # Handles Time (turning POSIX time datetime) + bot_start_time = datetime.fromtimestamp(self.bot.uptime, UTC) + current_time = datetime.now(UTC) # Get current time + uptime_delta = current_time - bot_start_time + + # Convert it into Human comprehensible times + days = uptime_delta.days + hours, remainder = divmod(uptime_delta.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + + # Format it for the command + bot_uptime_readable = " ".join( + [f"{days}d" if days else "", f"{hours}h" if hours else "", f"{minutes}m" if minutes else "", f"{seconds}s"], + ).strip() + # Get the CPU usage and RAM usage of the bot cpu_usage = psutil.Process().cpu_percent() # Get the amount of RAM used by the bot @@ -49,8 +70,10 @@ async def ping(self, ctx: commands.Context[Tux]) -> None: ) embed.add_field(name="API Latency", value=f"{discord_ping}ms", inline=True) + embed.add_field(name="Uptime", value=f"{bot_uptime_readable}", inline=True) embed.add_field(name="CPU Usage", value=f"{cpu_usage}%", inline=True) embed.add_field(name="RAM Usage", value=f"{ram_amount_formatted}", inline=True) + embed.add_field(name="Prod/Dev", value=f"`{environment}`", inline=True) await ctx.send(embed=embed) From 239ee7db8cf67b39becd79caf6eb3562d00a7d70 Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Sat, 2 Aug 2025 19:31:30 -0500 Subject: [PATCH 2/2] refactor: improve bot uptime formatting in ping command --- tux/cogs/utility/ping.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tux/cogs/utility/ping.py b/tux/cogs/utility/ping.py index 2d9e169cc..2a603d157 100644 --- a/tux/cogs/utility/ping.py +++ b/tux/cogs/utility/ping.py @@ -44,9 +44,13 @@ async def ping(self, ctx: commands.Context[Tux]) -> None: minutes, seconds = divmod(remainder, 60) # Format it for the command - bot_uptime_readable = " ".join( - [f"{days}d" if days else "", f"{hours}h" if hours else "", f"{minutes}m" if minutes else "", f"{seconds}s"], - ).strip() + bot_uptime_parts = [ + f"{days}d" if days else "", + f"{hours}h" if hours else "", + f"{minutes}m" if minutes else "", + f"{seconds}s", + ] + bot_uptime_readable = " ".join(part for part in bot_uptime_parts if part).strip() # Get the CPU usage and RAM usage of the bot cpu_usage = psutil.Process().cpu_percent()