Skip to content

Commit

Permalink
coretasks: route URL callbacks through bot.call()
Browse files Browse the repository at this point in the history
With this change, URL callbacks are no longer called outside the
enforcement area of rate-limits, per-channel configuration, etc.

Plus: Extra debug logging in `bot.call()` for future problems like this.

Thanks to @Exirel for suggesting the decorator solution here!

Co-Authored-By: Florian Strzelecki <florian.strzelecki@gmail.com>
  • Loading branch information
dgw and Exirel committed Apr 14, 2020
1 parent c5c608a commit 2db6f0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ def call(self, func, sopel, trigger):
# if channel has its own config section, check for excluded plugins/plugin methods
if trigger.sender in self.config:
channel_config = self.config[trigger.sender]
LOGGER.debug(
"Evaluating configuration for %s.%s in channel %s",
func.plugin_name, func.__name__, trigger.sender
)

# disable listed plugins completely on provided channel
if 'disable_plugins' in channel_config:
Expand Down
8 changes: 7 additions & 1 deletion sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import base64
import collections
import datetime
import functools
import logging
import re
import sys
Expand Down Expand Up @@ -1009,4 +1010,9 @@ def handle_url_callbacks(bot, trigger):
for function, match in bot.search_url_callbacks(url):
# trigger callback defined by the `@url` decorator
if hasattr(function, 'url_regex'):
function(bot, trigger, match=match)
# bake the `match` argument in before passing the callback on
@functools.wraps(function)
def decorated(bot, trigger):
return function(bot, trigger, match=match)

bot.call(decorated, bot, trigger)

0 comments on commit 2db6f0f

Please sign in to comment.