Skip to content
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

feat(fun): Added cowsay cog #803

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat(fun): Added cowsay cog #803

wants to merge 5 commits into from

Conversation

thanosengine
Copy link
Contributor

@thanosengine thanosengine commented Apr 5, 2025

Description

Added a new cog, cowsay.py, under the fun category.
This cog implements a new command, cowsay <message> [creature], which will take the provided message, place it in a textbox, and add the specified creature underneath it, similarly to the well-known cowsay program

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)

command has been tested in as many conditions as possible using my test instance

Screenshots (if applicable)

image

Additional Information

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

Summary by Sourcery

Add a new cowsay command to the bot's fun category, allowing users to generate ASCII art messages with various creatures

New Features:

  • Implement a cowsay command that generates ASCII art messages with customizable creatures like cow, tux, and puffy

Enhancements:

  • Create a flexible text wrapping mechanism for generating message boxes
  • Support multiple creature options for the cowsay command

Copy link
Contributor

sourcery-ai bot commented Apr 5, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new cowsay cog with a cowsay command. The command takes a message and a creature type as input and generates an ASCII art representation of the message in a text box with the selected creature below. Input validation is implemented for creature type and message length.

Class diagram for the Cowsay cog

classDiagram
    class Cowsay {
        -bot: Tux
        +__init__(bot: Tux)
        +draw_textbox(message: str) str
        +cowsay(ctx: commands.Context[Tux], message: str, creature: str) None
    }
    Cowsay -- Tux : has a
    class Tux {

    }
    note for Cowsay "This class implements the cowsay cog and its functionality"
Loading

File-Level Changes

Change Details Files
Implements a cowsay command that generates an ASCII art representation of a message in a text box with a selected creature below.
  • Added a cowsay hybrid group command with message and creature parameters.
  • Implemented draw_textbox to wrap the message and create the text box.
  • Added creature art for 'cow', 'tux', and 'puffy'.
  • Implemented input validation for creature type and message length.
  • Returns an error message if the creature is invalid.
  • Returns an error message if the message is too long.
tux/cogs/fun/cowsay.py

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. 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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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
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 @thanosengine - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a dictionary to store the creatures and their corresponding ASCII art for better organization.
  • The error message for invalid creatures could be improved by using a code block to format the list of valid creatures.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

self.bot = bot
self.cowsay.usage = generate_usage(self.cowsay)

async def draw_textbox(self, message: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Potential crash when message is empty.

If an empty string is passed to textwrap.wrap, it returns an empty list and subsequently calling max() on that list will raise a ValueError. Consider handling the empty message case explicitly.

""",
}

if creature not in creatures:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider using list slicing and join to simplify the loop for creating the list of valid creatures when an invalid creature is provided to the command.

You could simplify the manual loop by using list slicing and join. For example, replace:

if creature not in creatures:
    valid_creatures: list[str] = []
    for idx, key in enumerate(creatures.keys()):
        if idx < len(creatures) - 1:
            valid_creatures.append(f"{key}, ")
        else:
            valid_creatures.append(f" and {key}")
    await ctx.send(
        f'Error: "{creature}" is not a valid creature! valid creatures are: {"".join(valid_creatures)}',
        ephemeral=True,
    )
    return

with a more concise approach:

if creature not in creatures:
    keys = list(creatures.keys())
    if len(keys) > 1:
        valid_creatures = ", ".join(keys[:-1]) + " and " + keys[-1]
    else:
        valid_creatures = keys[0]
    await ctx.send(
        f'Error: "{creature}" is not a valid creature! Valid creatures are: {valid_creatures}',
        ephemeral=True,
    )
    return

This reduces complexity while keeping functionality intact.

Comment on lines 17 to 20
message_box_lines: list[str] = []
message_box_lines.append("/" + ("-" * (max_line_length + 2)) + "\\\n")
for line in message_lines:
box_line = "| " + line + (" " * (max_line_length - len(line))) + " |\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

return

textbox = await self.draw_textbox(message)
await ctx.send("```" + textbox + creatures[creature] + "```")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use f-string instead of string concatenation [×3] (use-fstring-for-concatenation)

Suggested change
await ctx.send("```" + textbox + creatures[creature] + "```")
await ctx.send(f"```{textbox}{creatures[creature]}```")

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