Skip to content

Conversation

cherryl1k
Copy link
Collaborator

@cherryl1k cherryl1k commented Aug 22, 2025

Description

Added Descriptions to the command options as well as replacing "cs" with "codesystem" for the entire file
also added predefined options for the codesystem flag and fixed other issues mentioned in issue #1005

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 on my own Tux instance by using the command in various ways

Screenshots (if applicable)

image image

Summary by Sourcery

Enhance encode and decode commands with clearer parameter naming, help descriptions, command aliases, and predefined encoding choices; make bot replies ephemeral by default.

Bug Fixes:

  • Set ephemeral parameter to True for send_message replies

Enhancements:

  • Rename cs parameter to codesystem across encode and decode commands
  • Add descriptive help texts for commands and parameters and predefined choices for codesystem option
  • Introduce "ec" and "dc" aliases for the encode and decode commands

Copy link
Contributor

sourcery-ai bot commented Aug 22, 2025

Reviewer's Guide

This PR refactors the encode/decode commands by renaming the “cs” parameter to “codesystem”, enriching command decorators with descriptions, aliases, and predefined choices, enforcing ephemeral responses, and updating docstrings accordingly.

Class diagram for updated encode/decode command structure

classDiagram
    class UtilityCog {
        +send_message(ctx, data)
        +encode(ctx, codesystem, text)
        +decode(ctx, codesystem, text)
    }
    UtilityCog : encode uses codesystem (str)
    UtilityCog : decode uses codesystem (str)
    UtilityCog : encode, decode decorated with descriptions, aliases, choices
    UtilityCog : send_message(ctx, data) -- ephemeral response
Loading

File-Level Changes

Change Details Files
Renamed parameter and logic from “cs” to “codesystem”
  • Updated function signatures to use “codesystem”
  • Replaced all ‘cs’ variable assignments and comparisons
tux/cogs/utility/encode_decode.py
Enhanced command decorators with metadata and choices
  • Added descriptions and aliases in @commands.hybrid_command
  • Introduced @app_commands.describe for each option
  • Defined @app_commands.choices for supported coding systems
tux/cogs/utility/encode_decode.py
Enforced ephemeral replies
  • Set ephemeral=True on reply calls for both standard and error messages
tux/cogs/utility/encode_decode.py
Updated docstrings to match new naming and descriptions
  • Revised parameter and description blocks to reference “codesystem”
tux/cogs/utility/encode_decode.py

Possibly linked issues

  • #0: PR adds descriptions to encode/decode commands and makes them ephemeral, fully resolving the reported issue.

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
Contributor

github-actions bot commented Aug 22, 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 there - I've reviewed your changes - here's some feedback:

  • Extract the repeated codesystem choice list into a shared constant to avoid duplication between the encode and decode commands.
  • Replace the repetitive if/elif chains with a mapping from codesystem values to the corresponding base64 encode/decode functions for cleaner, more maintainable code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the repeated codesystem choice list into a shared constant to avoid duplication between the encode and decode commands.
- Replace the repetitive if/elif chains with a mapping from codesystem values to the corresponding base64 encode/decode functions for cleaner, more maintainable code.

## Individual Comments

### Comment 1
<location> `tux/cogs/utility/encode_decode.py:77` </location>
<code_context>
         btext = text.encode(encoding="utf-8")

         try:
-            if cs == "base16":
+            if codesystem == "base16":
                 data = base64.b16encode(btext)
</code_context>

<issue_to_address>
Consider refactoring the encoding and decoding logic to use shared mappings and choices for code systems.

```suggestion
# At module top, define mappings and shared choices
ENCODERS = {
    "base16": base64.b16encode,
    "base32": base64.b32encode,
    "base64": base64.b64encode,
    "base85": base64.b85encode,
}

DECODERS = {
    "base16": base64.b16decode,
    "base32": base64.b32decode,
    "base64": base64.b64decode,
    "base85": base64.b85decode,
}

CODE_CHOICES = [
    app_commands.Choice(name=name, value=name)
    for name in ENCODERS.keys()
]

# Reuse CODE_CHOICES in both commands:
@commands.hybrid_command(
    name="encode", aliases=["ec"], description="Encode a message"
)
@app_commands.describe(text="Text to encode")
@app_commands.choices(codesystem=CODE_CHOICES)
async def encode(self, ctx: commands.Context[Tux], codesystem: str, *, text: str):
    btext = text.encode("utf-8")
    func = ENCODERS.get(codesystem.lower())
    if not func:
        return await ctx.reply(
            content=f"Invalid coding system. Please use: {', '.join(wrap_strings('`', ENCODERS))}",
            allowed_mentions=allowed_mentions, ephemeral=True
        )
    try:
        data = func(btext)
        await self.send_message(ctx, data.decode("utf-8"))
    except Exception as e:
        await ctx.reply(
            content=f"Unknown exception: {e.__class__.__name__}: {e}",
            allowed_mentions=allowed_mentions, ephemeral=True
        )

@commands.hybrid_command(
    name="decode", aliases=["dc"], description="Decode a message"
)
@app_commands.describe(text="Text to decode")
@app_commands.choices(codesystem=CODE_CHOICES)
async def decode(self, ctx: commands.Context[Tux], codesystem: str, *, text: str):
    btext = text.encode("utf-8")
    func = DECODERS.get(codesystem.lower())
    if not func:
        return await ctx.reply(
            content=f"Invalid coding system. Please use: {', '.join(wrap_strings('`', DECODERS))}",
            allowed_mentions=allowed_mentions, ephemeral=True
        )
    try:
        data = func(btext)
        await self.send_message(ctx, data.decode("utf-8"))
    except Exception as e:
        await ctx.reply(
            content=f"Unknown exception: {e.__class__.__name__}: {e}",
            allowed_mentions=allowed_mentions, ephemeral=True
        )
```
</issue_to_address>

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.

btext = text.encode(encoding="utf-8")

try:
if cs == "base16":
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 refactoring the encoding and decoding logic to use shared mappings and choices for code systems.

Suggested change
if cs == "base16":
# At module top, define mappings and shared choices
ENCODERS = {
"base16": base64.b16encode,
"base32": base64.b32encode,
"base64": base64.b64encode,
"base85": base64.b85encode,
}
DECODERS = {
"base16": base64.b16decode,
"base32": base64.b32decode,
"base64": base64.b64decode,
"base85": base64.b85decode,
}
CODE_CHOICES = [
app_commands.Choice(name=name, value=name)
for name in ENCODERS.keys()
]
# Reuse CODE_CHOICES in both commands:
@commands.hybrid_command(
name="encode", aliases=["ec"], description="Encode a message"
)
@app_commands.describe(text="Text to encode")
@app_commands.choices(codesystem=CODE_CHOICES)
async def encode(self, ctx: commands.Context[Tux], codesystem: str, *, text: str):
btext = text.encode("utf-8")
func = ENCODERS.get(codesystem.lower())
if not func:
return await ctx.reply(
content=f"Invalid coding system. Please use: {', '.join(wrap_strings('`', ENCODERS))}",
allowed_mentions=allowed_mentions, ephemeral=True
)
try:
data = func(btext)
await self.send_message(ctx, data.decode("utf-8"))
except Exception as e:
await ctx.reply(
content=f"Unknown exception: {e.__class__.__name__}: {e}",
allowed_mentions=allowed_mentions, ephemeral=True
)
@commands.hybrid_command(
name="decode", aliases=["dc"], description="Decode a message"
)
@app_commands.describe(text="Text to decode")
@app_commands.choices(codesystem=CODE_CHOICES)
async def decode(self, ctx: commands.Context[Tux], codesystem: str, *, text: str):
btext = text.encode("utf-8")
func = DECODERS.get(codesystem.lower())
if not func:
return await ctx.reply(
content=f"Invalid coding system. Please use: {', '.join(wrap_strings('`', DECODERS))}",
allowed_mentions=allowed_mentions, ephemeral=True
)
try:
data = func(btext)
await self.send_message(ctx, data.decode("utf-8"))
except Exception as e:
await ctx.reply(
content=f"Unknown exception: {e.__class__.__name__}: {e}",
allowed_mentions=allowed_mentions, ephemeral=True
)

Copy link

codecov bot commented Aug 22, 2025

Codecov Report

❌ Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.65%. Comparing base (657be96) to head (f02e749).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tux/cogs/utility/encode_decode.py 0.00% 18 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1030      +/-   ##
========================================
- Coverage   9.65%   9.65%   -0.01%     
========================================
  Files        123     123              
  Lines      10427   10432       +5     
  Branches    1281    1281              
========================================
  Hits        1007    1007              
- Misses      9311    9316       +5     
  Partials     109     109              
Flag Coverage Δ *Carryforward flag
database 0.31% <ø> (ø) Carriedforward from 657be96
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% <ø> (ø)
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.

@cherryl1k cherryl1k force-pushed the encode_decode/fixes branch from 9dabfbe to 727ca84 Compare August 22, 2025 02:51
Copy link

cloudflare-workers-and-pages bot commented Aug 22, 2025

Deploying tux with  Cloudflare Pages  Cloudflare Pages

Latest commit: f02e749
Status: ✅  Deploy successful!
Preview URL: https://abc5c273.tux-afh.pages.dev
Branch Preview URL: https://encode-decode-fixes.tux-afh.pages.dev

View logs

Copy link
Contributor

@amadaluzia amadaluzia left a comment

Choose a reason for hiding this comment

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

LGTM

@cherryl1k cherryl1k force-pushed the encode_decode/fixes branch from 727ca84 to 6d2d531 Compare August 24, 2025 02:37
@cherryl1k cherryl1k force-pushed the encode_decode/fixes branch from 6d2d531 to 702bba9 Compare August 25, 2025 18:58
@cherryl1k cherryl1k changed the title fix: Made the commands more descriptive fix: Made the encode and decode commands more descriptive Aug 25, 2025
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.

2 participants