Skip to content

Commit 3e97a4c

Browse files
committed
feat: added uptime and current branch to status
1 parent 7ff88e3 commit 3e97a4c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tux/bot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
6262

6363
self.emoji_manager = EmojiManager(self)
6464
self.console = Console(stderr=True, force_terminal=True)
65+
self.uptime = discord.utils.utcnow().timestamp()
6566

6667
logger.debug("Creating bot setup task")
6768
self.setup_task = asyncio.create_task(self.setup(), name="bot_setup")

tux/cogs/utility/ping.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from datetime import UTC, datetime
2+
13
import psutil
24
from discord.ext import commands
35

46
from tux.bot import Tux
57
from tux.ui.embeds import EmbedCreator
8+
from tux.utils.env import get_current_env
69
from tux.utils.functions import generate_usage
710

811

@@ -13,6 +16,7 @@ def __init__(self, bot: Tux) -> None:
1316

1417
@commands.hybrid_command(
1518
name="ping",
19+
aliases=["status"],
1620
)
1721
async def ping(self, ctx: commands.Context[Tux]) -> None:
1822
"""
@@ -27,6 +31,23 @@ async def ping(self, ctx: commands.Context[Tux]) -> None:
2731
# Get the latency of the bot in milliseconds
2832
discord_ping = round(self.bot.latency * 1000)
2933

34+
environment = get_current_env()
35+
36+
# Handles Time (turning POSIX time datetime)
37+
bot_start_time = datetime.fromtimestamp(self.bot.uptime, UTC)
38+
current_time = datetime.now(UTC) # Get current time
39+
uptime_delta = current_time - bot_start_time
40+
41+
# Convert it into Human comprehensible times
42+
days = uptime_delta.days
43+
hours, remainder = divmod(uptime_delta.seconds, 3600)
44+
minutes, seconds = divmod(remainder, 60)
45+
46+
# Format it for the command
47+
bot_uptime_readable = " ".join(
48+
[f"{days}d" if days else "", f"{hours}h" if hours else "", f"{minutes}m" if minutes else "", f"{seconds}s"],
49+
).strip()
50+
3051
# Get the CPU usage and RAM usage of the bot
3152
cpu_usage = psutil.Process().cpu_percent()
3253
# Get the amount of RAM used by the bot
@@ -49,8 +70,10 @@ async def ping(self, ctx: commands.Context[Tux]) -> None:
4970
)
5071

5172
embed.add_field(name="API Latency", value=f"{discord_ping}ms", inline=True)
73+
embed.add_field(name="Uptime", value=f"{bot_uptime_readable}", inline=True)
5274
embed.add_field(name="CPU Usage", value=f"{cpu_usage}%", inline=True)
5375
embed.add_field(name="RAM Usage", value=f"{ram_amount_formatted}", inline=True)
76+
embed.add_field(name="Prod/Dev", value=f"`{environment}`", inline=True)
5477

5578
await ctx.send(embed=embed)
5679

0 commit comments

Comments
 (0)