-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
webhook: integrate bot instance with Bottle #29
base: master
Are you sure you want to change the base?
Conversation
16ac9d3
to
2b93aaf
Compare
@HumorBaby Switching to use the |
c3a4409
to
ee07c8a
Compare
Done. |
Injecting the bot instance into the WSGI server environment obviates the need for passing around a bot instance or using `global`s.
Functions that have a `bot` parameter (has to be called `bot`, it is not a matter of position, but name) will receive the managing Sopel instance as an argument. This precludes the use of `global sopel_instance`.
ee07c8a
to
7864002
Compare
👍 |
More merge conflicts, oh boy! 🙁 |
I was looking at release notes because #141 came up again on IRC. Asking since it needs a rebase anyway 😅 |
This PR makes use of WSGI middleware and a Bottle plugin to ensure that the bot instance is accessible wherever the
Bottle
app is visible (bottle
isimport
'd).There are two main goals of this PR:
Obviate the need for unsightly
global
s. See:sopel-github/sopel_modules/github/webhook.py
Lines 32 to 33 in 853a6c5
@route
decorated callbacks to accept an optionalbot
parameter that corresponds to the actual bot instance, making the webhook callbacks more like normal Sopel callables. For example:bot
parameter if it is not needed would be perfectly acceptable. Thanks to Bottle plugins, no extra work is necessary to decorate webhook callbacks.Expose the bot instance through bottle
Then, each subsequent call has access to the
the_bot
global variable. Other options include getting the bot instance frombottle.request.environ...
in each function as needed, and makingthe_bot
a local variable and passing it to functions as needed.Hopefully, this can serve as a starting point for #19 since it now exposes the bot instance (so
bot.config
or the DB can be accessed for settings) informatting.py
, which in my understanding is the current limitation.Coming soon
A PR based on this one to completely remove the use of globals inEnded up adding it to this PR.webhook.py
and instead use the bot instance provided by@bottle.route
.