Adding Internal Eval to Sir Lancebot#673
Merged
Merged
Conversation
This is an initial cutover of the rattlesnake internal eval to Sir Lancebot. This commit by itself will not work. This is a simple drop in of rattlesnake code so there is context as to what has changed and why.
Cutting over the rattlesnake helpers specifically for internal_eval. I am mirroring the rattlesnake structure as much as I can initially to ensure basic functionality before migrating functions to fit more within Sir Lancebot's file structure.
The code for rattlesnakes's internal eval was aligned to Sir Lancebot's structure. It was mostly renaming rattlesnake to bot and changing how some of the imports were setup as. It also included changing the __init__.py to match the Sir Lancebot cog structure. Additionally, the whitelist check has been significantly simplified to only be a role check for the admin role. The rattlesnake implementation had a more robust `in_whitelist` decorator, so it may be worth investigating adding that in if we see fit. For now, it's a simple `with_role` decorator check. The name of the cog file itself was changed to include an underscore to sidestep what I think was a namespace collision that would prevent the setup function from properly running.
These were missed in a previous commit. It's a simple name change from the original files to better align with Sir Lancebot.
The snekbox implementation of the codeblock regex was incorporated. This now correctly parses the `code` and ``code`` markdown discord allows. You can also use multiple code blocks with text interrupting it and it will process the different code blocks as one continuous code block.
I'm better than this I swear. I can lint before I commit. Don't tell lemon.
Both my pre-commit and flake8 runs are telling me everything is fine and it's all passed. Github actions is saying otherwise but isn't saying *where*. So here I am with useless linting commits.
Akarys42
suggested changes
Apr 11, 2021
Contributor
Akarys42
left a comment
There was a problem hiding this comment.
The PR looks pretty good overall, thanks! Just a few comments.
Shivansh-007
suggested changes
Apr 11, 2021
Contributor
Shivansh-007
left a comment
There was a problem hiding this comment.
Quick review, need to look into ast and mess around with it, before I can do a full review.
Corrects the prefix for the a command in the docstring to use Lancebot's prefix. Co-authored-by: Matteo Bertucci <matteobertucci2004@gmail.com>
Changed the initialization of the logging to pull dynamically so it can actually log correctly.
ToxicKidz
suggested changes
Apr 11, 2021
Contributor
ToxicKidz
left a comment
There was a problem hiding this comment.
Great PR, just one change.
With the regex sufficiently stolen from snekbox and confirmed to work, the original codeblock regex has been removed.
Updated the docstring for `reset` to provide accurate information as to what the command does.
`.int` with nothing else now uses the `invoke_help_command()` utility that formats the help command much more nicely than the default version
Added in an extra `\n` at the end of the output. Sometimes discord won't properly format the codeblock in the triple ` is not on a newline. This changes ensures that it should.
onerandomusername
suggested changes
Apr 12, 2021
Added a constant for the same filenames used in several locations. Because the now-a-constant string is used in several locations this will allow for it to be updated more easily down the line.
This commit removes the `exit` check if someone were to use this: `.int e exit` to clear the context. The check would prevent `.int e exit()` from restarting the bot container. With the `.int reset` and `.int exit` ability to clear the context the check for `exit` to clear the context isn't necessary.
ChrisLovering
approved these changes
Apr 12, 2021
Member
ChrisLovering
left a comment
There was a problem hiding this comment.
Looks good, tested locally too :D
Akarys42
approved these changes
Apr 17, 2021
Contributor
Akarys42
left a comment
There was a problem hiding this comment.
Works like a charm, thanks a lot!
Akarys42
reviewed
Apr 17, 2021
Contributor
Akarys42
left a comment
There was a problem hiding this comment.
You can do it review bot
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant Issues
Closes #653
Description
This internal eval comes from rattlesnake primarily. It was ripped out of rattlesnack whole sale and subsequently modified to fit Sir Lancebot's structure. Additionaly, the codeblock regex from snekbox was

stolenused for more robust code markdown usage. The image below shows it quite nicely.Rattlesnake's internal eval implementation is quite nice and provides additional functionality compared to Python's, which is why it was used over Python's internal eval. It adds the ability to clear the context with a command and provides more information in a REPL like environment.
Reasoning
Internal eval is very useful for troubleshooting issues and temporarily applying hotfixes in a situation where something goes awry. This command is locked to the admin role due to its nature.
Screenshots
Additional Details
Thanks Sebastiaan for doing all the real work!
Did you:
pipenv lock?pipenv run lint)?