Skip to content

Commit

Permalink
[info] Add uptime in the command /about (#488)
Browse files Browse the repository at this point in the history
* Add uptime in /about

* addressing review

* appease pyright

* appease pyright again
  • Loading branch information
imtherealF1 authored Jan 2, 2025
1 parent 0a2f51d commit 2c90d3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ballsdex/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(
self.add_check(owner_check) # Only owners are able to use text commands

self._shutdown = 0
self.startup_time: datetime | None = None
self.blacklist: set[int] = set()
self.blacklist_guild: set[int] = set()
self.catch_log: set[int] = set()
Expand Down Expand Up @@ -278,6 +279,9 @@ async def on_ready(self):
if self.cogs != {}:
return # bot is reconnecting, no need to setup again

if self.startup_time is None:
self.startup_time = datetime.now()

assert self.user
log.info(f"Successfully logged in as {self.user} ({self.user.id})!")

Expand Down
12 changes: 11 additions & 1 deletion ballsdex/packages/info/cog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import random
import sys
from datetime import datetime
from typing import TYPE_CHECKING

import discord
Expand Down Expand Up @@ -76,6 +77,13 @@ async def about(self, interaction: discord.Interaction):
players_count = await row_count_estimate("player")
balls_instances_count = await row_count_estimate("ballinstance")

days, hours, minutes, seconds = 0, 0, 0, 0
if self.bot.startup_time is not None:
uptime_duration = datetime.now() - self.bot.startup_time
days, remainder = divmod(int(uptime_duration.total_seconds()), 86400)
hours, remainder = divmod(remainder, 3600)
minutes, seconds = divmod(remainder, 60)

assert self.bot.user
assert self.bot.application
try:
Expand Down Expand Up @@ -116,7 +124,9 @@ async def about(self, interaction: discord.Interaction):
embed.description = (
f"{' '.join(str(x) for x in balls)}\n"
f"{settings.about_description}\n"
f"*Running version **[{ballsdex_version}]({settings.github_link}/releases)***\n\n"
f"*Running version **[{ballsdex_version}]({settings.github_link}/releases)***\n"
f"The bot has been online for **{days} days, {hours} hours, {minutes} minutes, "
f"and {seconds} seconds.**\n\n"
f"**{balls_count:,}** {settings.plural_collectible_name} to collect\n"
f"**{players_count:,}** players that caught "
f"**{balls_instances_count:,}** {settings.plural_collectible_name}\n"
Expand Down

0 comments on commit 2c90d3a

Please sign in to comment.