Skip to content

Conversation

@meatharvester
Copy link
Collaborator

@meatharvester meatharvester commented Jul 31, 2025

Description

Add uptime and the current environment (dev/prod) to the ping command aswell as aliasing it to status

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

tested within my discord server while monitoring my tux console

Screenshots (if applicable)

image

Summary by Sourcery

Enhance the ping command (aliased as status) to include bot uptime and current environment

New Features:

  • Alias the ping command to status
  • Display human-readable uptime in the status embed
  • Display the current environment (prod/dev) in the status embed

Enhancements:

  • Initialize and track bot start timestamp for uptime calculation

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 31, 2025

Reviewer's Guide

This PR enhances the existing ping command (now also aliased as status) by recording the bot’s start time at initialization and displaying its uptime and current environment in the response.

Class diagram for updated Tux bot and Ping command

classDiagram
    class Tux {
        +float uptime
    }
    class Ping {
        +ping(ctx)
    }
    Tux <|-- Ping: uses
    Ping : +aliases = ["status"]
    Ping : +Displays uptime
    Ping : +Displays environment
    Ping : +Displays CPU/RAM
    Ping : +Displays latency
Loading

File-Level Changes

Change Details Files
Enhance ping/status command with uptime and environment info
  • Add 'status' as an alias to the ping command
  • Retrieve the current environment using get_current_env()
  • Calculate and format uptime from bot.uptime timestamp
  • Include uptime and environment fields in the embed response
tux/cogs/utility/ping.py
Record bot start time for uptime calculation
  • Initialize self.uptime with the current UTC timestamp in bot constructor
tux/bot.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@meatharvester meatharvester force-pushed the feature/add-uptime-to-ping branch from 4ecf65c to fb28e47 Compare July 31, 2025 20:29
@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cherryl1k - I've reviewed your changes - here's some feedback:

  • Consider storing self.uptime as a datetime object rather than a timestamp to keep uptime calculations timezone-aware and simplify conversions.
  • You can clean up the uptime formatting by filtering out empty segments (e.g. [part for part in parts if part]) instead of joining empty strings and stripping.
  • Extract the uptime calculation and formatting into a small helper function to keep the ping command handler focused and more testable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider storing `self.uptime` as a datetime object rather than a timestamp to keep uptime calculations timezone-aware and simplify conversions.
- You can clean up the uptime formatting by filtering out empty segments (e.g. `[part for part in parts if part]`) instead of joining empty strings and stripping.
- Extract the uptime calculation and formatting into a small helper function to keep the `ping` command handler focused and more testable.

## Individual Comments

### Comment 1
<location> `tux/cogs/utility/ping.py:47` </location>
<code_context>
+        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
</code_context>

<issue_to_address>
The formatting may produce extra spaces if some time units are zero.

Filter out empty strings before joining to avoid extra spaces in the output.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        # 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()
=======
        # Format it for the command
        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)
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 46 to 49
# 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The formatting may produce extra spaces if some time units are zero.

Filter out empty strings before joining to avoid extra spaces in the output.

Suggested change
# 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()
# Format it for the command
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)

@codecov
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.44%. Comparing base (7ed570e) to head (239ee7d).
⚠️ Report is 8 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tux/cogs/utility/ping.py 0.00% 13 Missing ⚠️
tux/bot.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #989      +/-   ##
========================================
+ Coverage   9.26%   9.44%   +0.17%     
========================================
  Files        123     123              
  Lines      10392   10406      +14     
  Branches    1277    1277              
========================================
+ Hits         963     983      +20     
- Misses      9327    9330       +3     
+ Partials     102      93       -9     
Flag Coverage Δ *Carryforward flag
database 0.31% <ø> (ø) Carriedforward from 3e97a4c
integration 5.85% <0.00%> (-0.01%) ⬇️
unit 6.30% <0.00%> (-0.01%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Core Bot Infrastructure 16.43% <0.00%> (-0.02%) ⬇️
Database Layer 0.00% <ø> (ø)
Bot Commands & Features 0.00% <0.00%> (ø)
Event & Error Handling ∅ <ø> (∅)
Utilities & Helpers ∅ <ø> (∅)
User Interface Components 0.00% <ø> (ø)
CLI Interface ∅ <ø> (∅)
External Service Wrappers ∅ <ø> (∅)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@meatharvester meatharvester force-pushed the feature/add-uptime-to-ping branch from fb28e47 to b3000b7 Compare July 31, 2025 20:31
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 31, 2025

Deploying tux with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3e97a4c
Status: ✅  Deploy successful!
Preview URL: https://fc8b334e.tux-afh.pages.dev
Branch Preview URL: https://feature-add-uptime-to-ping.tux-afh.pages.dev

View logs

@meatharvester meatharvester force-pushed the feature/add-uptime-to-ping branch 2 times, most recently from b425ac4 to 68f30f8 Compare July 31, 2025 20:35
@meatharvester meatharvester force-pushed the feature/add-uptime-to-ping branch from 68f30f8 to 3e97a4c Compare July 31, 2025 20:53
@electron271 electron271 merged commit 784e178 into main Aug 3, 2025
11 checks passed
@electron271 electron271 deleted the feature/add-uptime-to-ping branch August 3, 2025 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants