Skip to content

feat: update moderation, tools, and utility cogs #960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kzndotsh
Copy link
Contributor

@kzndotsh kzndotsh commented Jul 20, 2025

  • Improve tempban functionality
  • Update wolfram integration
  • Enhance AFK and reminder utilities

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change. If this change fixes any issues please put "Fixes #XX" in the description. Please also ensure to add the appropriate labels to the PR.

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)

Please describe how you tested your code. e.g describe what commands you ran, what arguments, and any config stuff (if applicable)

Screenshots (if applicable)

Please add screenshots to help explain your changes.

Additional Information

Please add any other information that is important to this PR.

Summary by Sourcery

Consolidate task scheduling and error handling across utility and moderation cogs, switch RemindMe to use the centralized ReminderService instead of manual timers, simplify Wolfram cog loading based on configuration, and enhance TempBan and AFK loops with improved logging, error hooks, and clean shutdown.

Enhancements:

  • RemindMe now validates and schedules reminders via the ReminderService and removes legacy on_ready scheduling code
  • TempBan loop renamed and augmented with better logging, lock handling, error capturing, and Sentry integration
  • AFK expiration loop renamed, adds before_loop and error handlers, and cancels on cog unload
  • Wolfram cog loading moved to setup to skip loading when the API key is missing and initialization logging simplified

- Improve tempban functionality
- Update wolfram integration
- Enhance AFK and reminder utilities
Copy link
Contributor

sourcery-ai bot commented Jul 20, 2025

Reviewer's Guide

This PR refactors core utility and moderation cogs by replacing manual scheduling with a dedicated service, strengthening background task loops with better locking, logging, and error handling, and streamlining configuration-driven loading for the Wolfram cog.

Sequence diagram for RemindMe command scheduling with ReminderService

sequenceDiagram
    actor User
    participant Bot
    participant RemindMe
    participant ReminderService
    User->>Bot: $remindme 1h30m take a break
    Bot->>RemindMe: remindme(ctx, time, reminder)
    RemindMe->>ReminderService: schedule_reminder(reminder_obj)
    ReminderService-->>RemindMe: (reminder scheduled)
    RemindMe-->>Bot: reply with confirmation
    Bot-->>User: confirmation message
Loading

Sequence diagram for improved TempBan expiration processing

sequenceDiagram
    participant TempBan
    participant DB
    participant Logger
    participant Sentry
    loop every 1 minute
        TempBan->>TempBan: check_tempbans()
        TempBan->>DB: get_expired_tempbans()
        alt expired cases found
            TempBan->>TempBan: _process_tempban_case(case)
            TempBan->>Logger: log processed/failed
        else no expired cases
            TempBan->>Logger: log skip
        end
        alt error occurs
            TempBan->>Logger: log error
            TempBan->>Sentry: capture_exception(error)
        end
    end
Loading

Sequence diagram for AFK expiration handler with error reporting

sequenceDiagram
    participant AFK
    participant DB
    participant Logger
    participant Sentry
    loop every 120 seconds
        AFK->>AFK: handle_afk_expiration()
        AFK->>DB: get expired AFK entries
        alt expired entries found
            AFK->>DB: remove AFK entry
        end
        alt error occurs
            AFK->>Logger: log error
            AFK->>Sentry: capture_exception(error)
        end
    end
Loading

Class diagram for updated TempBan moderation cog

classDiagram
    class TempBan {
        - _processing_tempbans: bool
        + __init__(bot: Tux)
        + check_tempbans()  // renamed and improved loop
        + before_check_tempbans()
        + on_tempban_error(error)
        + cog_unload()
    }
    class ModerationCogBase
    TempBan --|> ModerationCogBase
Loading

Class diagram for updated AFK utility cog

classDiagram
    class AFK {
        + __init__(bot: Tux)
        + cog_unload()
        + handle_afk_expiration()  // renamed and improved loop
        + before_handle_afk_expiration()
        + on_handle_afk_expiration_error(error)
        + _get_expired_afk_entries(guild_id: int)
    }
Loading

Class diagram for updated RemindMe utility cog

classDiagram
    class RemindMe {
        - _initialized: bool // removed
        + __init__(bot: Tux)
        + remindme(ctx, time: str, reminder: str)
    }
    class ReminderService {
        + schedule_reminder(reminder_obj)
    }
    RemindMe ..> ReminderService : uses
Loading

Class diagram for updated Wolfram tool cog

classDiagram
    class Wolfram {
        + __init__(bot: Tux)
        + wolfram(ctx, query: str)
    }
Loading

File-Level Changes

Change Details Files
Refactor RemindMe to use ReminderService and remove legacy scheduling
  • Removed send_reminder method and on_ready listener
  • Updated remindme command usage, default delete_after, and help text
  • Added ReminderService type check before scheduling
  • Switched scheduling to reminder_service.schedule_reminder
tux/cogs/utility/remindme.py
Improve TempBan loop with clearer naming, locking, logging, and error handling
  • Renamed tempban_check to check_tempbans and gave the loop an explicit name
  • Reordered lock logic to prevent overlaps and added early return when no cases
  • Added detailed info/debug logs for processing batches
  • Implemented on_error handler to capture and report exceptions
tux/cogs/moderation/tempban.py
Streamline Wolfram cog loading based on configuration
  • Removed runtime unload task in init
  • Moved APP ID check to setup with early return if missing
  • Left simple init logging for successful loads
tux/cogs/tools/wolfram.py
Enhance AFK expiration task lifecycle and error handling
  • Added cog_unload to cancel expiration loop on unload
  • Assigned a name to the loop and added before_loop hook
  • Added error handler to log and report exceptions via sentry_manager
tux/cogs/utility/afk.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

Copy link

Deploying tux with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9be9ed9
Status: ✅  Deploy successful!
Preview URL: https://2b8bec7b.tux-afh.pages.dev
Branch Preview URL: https://04-other-cogs-split.tux-afh.pages.dev

View logs

@kzndotsh
Copy link
Contributor Author

Depends on: #957

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.

1 participant