-
-
Notifications
You must be signed in to change notification settings - Fork 41
Improve the run command by adding extra languages and fixing longstanding issues. #880
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
Conversation
…, add a close button, simplify the embed, fix Haskell.
Reviewer's GuideThis PR overhauls the Sequence Diagram of the Refactored $run CommandsequenceDiagram
actor User
participant Bot as "Tux Bot (Discord)"
participant RunCog as "Run Cog"
participant GodboltAPI as "Godbolt API"
participant WandboxAPI as "Wandbox API"
User->>Bot: $run `lang\ncode` (or reply)
Bot->>RunCog: process_run_command(context, code)
activate RunCog
RunCog->>RunCog: Add reaction to user's message
RunCog->>RunCog: language = __get_language(code)
RunCog->>RunCog: cleaned_code = __clean_code(code)
alt Language not supported by Godbolt or Wandbox
RunCog->>Bot: Send error embed ("No compiler found")
Bot-->>User: Error Embed
else Language supported
%% Call self.execute to determine backend and run code
RunCog->>RunCog: output = self.execute(map, language, cleaned_code, is_wandbox, options)
activate RunCog
alt is_wandbox (language in compiler_map_wandbox)
RunCog->>WandboxAPI: HTTP POST (code, compiler, options)
activate WandboxAPI
WandboxAPI-->>RunCog: JSON Response (program_output, compiler_error)
deactivate WandboxAPI
RunCog->>RunCog: Process Wandbox response to get output string
else Use Godbolt (language in compiler_map_godbolt)
RunCog->>GodboltAPI: HTTP POST (code, compiler_id, options)
activate GodboltAPI
GodboltAPI-->>RunCog: Text Response
deactivate GodboltAPI
RunCog->>RunCog: Process Godbolt response to get output string
end
RunCog-->>RunCog: Return formatted_output or None
deactivate RunCog
alt Execution failed (output is None or error string)
RunCog->>Bot: Send error embed ("Failed to get output from compiler")
Bot-->>User: Error Embed
else Execution successful
RunCog->>RunCog: Clear reaction from user's message
RunCog->>Bot: send_embedded_reply(context, output, language, is_wandbox)
Bot-->>User: Success Embed (with output and Close button)
end
end
deactivate RunCog
Updated Class Diagram for Run Cog and Execution WrappersclassDiagram
direction LR
class Run {
<<Cog>>
-bot: Tux
-compiler_map_godbolt: dict
-compiler_map_wandbox: dict
+__init__(bot: Tux)
-__remove_ansi(ansi: str) str
-__remove_backticks(st: str) str
-__clean_code(st: str) str
-__get_language(st: str) str
+execute(compiler_map: dict, lang: str, code: str, is_wandbox: bool, opts: str|None) str|None
+send_embedded_reply(ctx: Context, output: str, lang: str, is_wandbox: bool) None
+run(ctx: Context, code: str|None) None
+languages(ctx: Context) None
}
class Wandbox {
<<Wrapper Module>>
-client: httpx.Client
-url: str
+getoutput(code: str, compiler: str, options: str|None) dict|None
}
class Godbolt {
<<Wrapper Module>>
+getoutput(code: str, compiler_id: str, options: str|None) str|None
}
class EmbedCreator {
<<Utility>>
+create_embed(...)
}
Run ..> Wandbox : uses
Run ..> Godbolt : uses
Run ..> EmbedCreator : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @HikariNee - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Context has no
fetch_messagemethod (link)
General comments:
- In tux/wrappers/wandbox.py the payload dict mistakenly uses the
optionsvariable as a key instead of the literal string "options"; it should be{ 'compiler': compiler, 'code': code, 'options': copt }. - The hack in execute() that prepends dummy "Padding word" lines and then slices with
lines[5:]is very fragile—refactor to parse the Wandbox JSON response properly rather than relying on magic line offsets. - The nested f-string in
send_embedded_replyfor the service attribution is syntactically invalid; simplify the quoting or split it into separate strings to avoid malformed f-string interpolation.
Here's what I looked at during the review
- 🔴 General issues: 1 blocking issue, 8 other issues
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
396894b to
c938ea7
Compare
… invoked in an interaction and add a space in the handling of opts in GodboltService._execute(), remove an escape in the code for __remove_backticks().
…hen an error happens, and update the version of the C# compiler for an alias.
…the need for padded words in Wandbox.
|
looks good to me! run command definitely could use the attention. |
Description
This PR fixes a typo in the godbolt.py file, adds a minimal wrapper on top of Wandbox's API and fixes some longstanding issues with the
$runcommand while upgrading compilers and adding new languages.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
[Y] I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
NA
Screenshots (if applicable)
NA
Additional Information
NA
Summary by Sourcery
Enhance the run command by integrating Wandbox support for additional languages, upgrading compiler mappings, refactoring execution logic, and improving UI feedback and error handling.
New Features:
Bug Fixes:
Enhancements: