Skip to content
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
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added examples/plugins/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions examples/plugins/__main__.py
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)

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?

Copy link

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.

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.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link

Choose a reason for hiding this comment

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

sorry

Copy link
Collaborator Author

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.



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())
11 changes: 11 additions & 0 deletions examples/plugins/test_plugin.py
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
1 change: 1 addition & 0 deletions sail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sail.errors import *
from sail.impl.command import *
from sail.impl.command_manager import *
from sail.impl.plugin import *
from sail.internal.typing_utils import Greedy as Greedy
from sail.internal.typing_utils import JoinedStr as JoinedStr
from sail.internal.undefined import UNDEFINED as UNDEFINED
Expand Down
Loading