-
-
Notifications
You must be signed in to change notification settings - Fork 409
bot: Support multiple handlers for a URL pattern #1805
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
Conversation
e3cffe6 to
5fd9823
Compare
5fd9823 to
ad1530c
Compare
|
I like the idea, and the code is quite good. Yet, I'd like to point out that we planned on removing
For that, I think you can add a new attribute to |
ad1530c to
d1d5c2a
Compare
778bbb0 to
77a4ada
Compare
|
Thanks. Yeah, this was originally aimed for 7.0 which needs to keep manual management. Mostly redone now to be fully compatible with no API changes at all, so this maintains exact compatibility with the manual |
77a4ada to
3704686
Compare
Exirel
left a comment
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 like it. Few nitpicks to consider.
|
I'm in favor of doing this for 7.1. Where are we on addressing Exi's feedback? |
3704686 to
844745f
Compare
| if 'url_callbacks' not in self.memory: | ||
| # nothing to search | ||
| return | ||
|
|
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 we keep the line here? I like the code with a bit of space, for readability.
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 think it was to make clear that the whole block should be removed in 8.0 per the above comment. I'm fine with or without the blank line here, but I understand the (suspected) reasoning behind deleting it.
| self.memory['url_callbacks'][pattern] = callback | ||
| if pattern not in self._url_callbacks: | ||
| self._url_callbacks[pattern] = [] | ||
| self._url_callbacks[pattern].append(callback) |
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.
You should check if callback is not yet registered for that pattern.
| del self.memory['url_callbacks'][pattern] | ||
| except KeyError: | ||
| self._url_callbacks[pattern].remove(callback) | ||
| except ValueError: |
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.
You might want to catch a KeyError here too.
Description
Implements #1804
This introduces
Sopel._url_callbacks, changes the *_url_callback functions to use it, and returns both Sopel._url_callbacks and bot.memory["url_callbacks"] results in a search, maintaining the legacy functionality.Because Sopel doesn't have a SopelMemory-type object for lists, this may have minor concurrency issues, but url_callbacks updates are infrequent enough I don't think it's deadly.
Checklist
make qa