allthingslinux / tux

Tux is an all in one bot for the All Things Linux discord server.
https://discord.gg/linux
GNU General Public License v3.0
85 stars 25 forks source link

Limit the amount of characters /afk can use #641

Closed wlinator closed 1 week ago

wlinator commented 2 weeks ago

Fixes #639

Summary by Sourcery

Bug Fixes:

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This PR implements a character limit for AFK reasons by truncating long messages to 100 characters using Python's textwrap module. The truncated reason is then stored in the database and displayed in the response message.

Sequence diagram for AFK command with character limit

sequenceDiagram
    actor User
    participant Bot
    participant Database

    User->>Bot: /afk <reason>
    Bot->>Bot: Truncate reason to 100 characters
    Bot->>Database: Insert AFK status with truncated reason
    Database-->>Bot: Confirmation
    Bot->>User: Send confirmation message with truncated reason

Class diagram for AFK command changes

classDiagram
    class AFKCommand {
        +insert_afk(userId, displayName, reason, guildId)
    }

    AFKCommand : +afk(ctx, target, reason)
    AFKCommand : -Truncate reason to 100 characters
    AFKCommand : -Store truncated reason in database
    AFKCommand : -Send confirmation message with truncated reason

File-Level Changes

Change Details Files
Added character limit to AFK reason messages
  • Introduced text truncation using textwrap.shorten with 100-character limit
  • Updated database insertion to use shortened reason
  • Modified response message to display truncated reason
tux/cogs/utility/afk.py

Assessment against linked issues

Issue Objective Addressed Explanation
#639 Limit AFK message to 100 characters

Possibly linked issues


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. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a 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. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).