Skip to content

Adding Internal Eval to Sir Lancebot#673

Merged
Akarys42 merged 16 commits into
python-discord:mainfrom
janine9vn:int-eval
Apr 17, 2021
Merged

Adding Internal Eval to Sir Lancebot#673
Akarys42 merged 16 commits into
python-discord:mainfrom
janine9vn:int-eval

Conversation

@janine9vn
Copy link
Copy Markdown
Contributor

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 stolen used for more robust code markdown usage. The image below shows it quite nicely.
image

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

image
image

Additional Details

Thanks Sebastiaan for doing all the real work!

Did you:

  • Join the Python Discord Community?
  • If dependencies have been added or updated, run pipenv lock?
  • Lint your code (pipenv run lint)?
  • Set the PR to allow edits from contributors?

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.
Copy link
Copy Markdown
Contributor

@Akarys42 Akarys42 left a comment

Choose a reason for hiding this comment

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

The PR looks pretty good overall, thanks! Just a few comments.

Comment thread bot/exts/internal_eval/_helpers.py Outdated
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
Comment thread bot/exts/internal_eval/_helpers.py Outdated
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
Copy link
Copy Markdown
Contributor

@Shivansh-007 Shivansh-007 left a comment

Choose a reason for hiding this comment

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

Quick review, need to look into ast and mess around with it, before I can do a full review.

Comment thread bot/exts/internal_eval/__init__.py
Comment thread bot/exts/internal_eval/_helpers.py Outdated
Comment thread bot/exts/internal_eval/_helpers.py Outdated
Comment thread bot/exts/internal_eval/_helpers.py
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
Comment thread bot/exts/internal_eval/_internal_eval.py
Comment thread bot/exts/internal_eval/_internal_eval.py
janine9vn and others added 2 commits April 11, 2021 11:18
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.
Copy link
Copy Markdown
Contributor

@ToxicKidz ToxicKidz left a comment

Choose a reason for hiding this comment

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

Great PR, just one change.

Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
@Xithrius Xithrius added area: backend Related to internal functionality and utilities status: waiting for author Waiting for author to address a review or respond to a comment type: feature Relating to the functionality of the application. labels Apr 11, 2021
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.
Comment thread bot/exts/internal_eval/_internal_eval.py Outdated
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.
@janine9vn janine9vn requested a review from Akarys42 April 12, 2021 22:49
Copy link
Copy Markdown
Member

@ChrisLovering ChrisLovering left a comment

Choose a reason for hiding this comment

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

Looks good, tested locally too :D

@janine9vn janine9vn added status: needs review Author is waiting for someone to review and approve and removed status: waiting for author Waiting for author to address a review or respond to a comment labels Apr 13, 2021
Copy link
Copy Markdown
Contributor

@Akarys42 Akarys42 left a comment

Choose a reason for hiding this comment

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

Works like a charm, thanks a lot!

Copy link
Copy Markdown
Contributor

@Akarys42 Akarys42 left a comment

Choose a reason for hiding this comment

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

You can do it review bot

@Akarys42 Akarys42 merged commit 7c12cbd into python-discord:main Apr 17, 2021
@janine9vn janine9vn deleted the int-eval branch April 17, 2021 16:00
@Xithrius Xithrius removed the status: needs review Author is waiting for someone to review and approve label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Related to internal functionality and utilities type: feature Relating to the functionality of the application.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add internal evaluation to sir-lancebot

7 participants