-
Notifications
You must be signed in to change notification settings - Fork 0
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: implement simple plugins #3
Open
Sharp-Eyes
wants to merge
7
commits into
master
Choose a base branch
from
feat/plugins
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fa4c41
feat(plugins): implement simple plugins
Sharp-Eyes 07c2932
Merge branch 'master' into feat/plugins
Sharp-Eyes 25cfa9d
feat(plugin): implement simple reloading
Sharp-Eyes fd9e199
fix: improve Plugin.entrypoints docstring
Sharp-Eyes 8239f72
fix(plugin): make remove_command actually work
Sharp-Eyes c5d2b41
chore: yeet logging from example
Sharp-Eyes 41023e8
feat(plugins): try to get package if none provided
Sharp-Eyes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import asyncio | ||
import logging | ||
|
||
import velum | ||
|
||
import sail | ||
|
||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
|
||
|
||
client = velum.GatewayClient() | ||
manager = sail.CommandManager.with_prefix("!") | ||
manager.bind_to_app(client) | ||
|
||
|
||
async def main(): | ||
await sail.load_extension( | ||
".test_plugin", "examples.plugins", client=client, command_manager=manager | ||
) | ||
|
||
await client.start() | ||
|
||
|
||
@manager.command() | ||
async def reload(ctx: sail.Context): | ||
await sail.reload_extension(".test_plugin", client=client, command_manager=manager) | ||
await client.rest.send_message("Sail", "Done deal.") | ||
|
||
|
||
asyncio.run(main()) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sail | ||
|
||
plugin = sail.Plugin() | ||
|
||
|
||
@plugin.command() | ||
async def plugin_command(ctx: sail.Context): | ||
await plugin.rest.send_message("Sail", f"Sent from plugin {plugin.name!r}!") | ||
|
||
|
||
load, unload = plugin.entrypoints |
This file contains 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
Oops, something went wrong.
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.
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.
Can't you set the level directly in the
basicConfig
function?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.
I may not remember this correctly but I'm pretty sure setting it in
basicConfig
is global and for all loggers as opposed to just the logger in this file.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.
That's the point? This is an example, not a module part of the library.
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.
getLogger()
without an arg also uses the global logger, so that doesn't change the behaviour either.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.
Yup, though I'm probably leaving out the log setup altogether when I finish up this example (note how there's no comments explaining anything yet), as it's only there as I needed it to debug stuff.
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.
sorry
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.
Yeeted this in c5d2b41. I'll add a bit of logging explanation later when I get around to properly documenting this example, as plugins do actually support setting per-instance loggers.