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

loader: default rule for events #1693

Merged
merged 2 commits into from
Sep 18, 2019
Merged

loader: default rule for events #1693

merged 2 commits into from
Sep 18, 2019

Conversation

dgw
Copy link
Member

@dgw dgw commented Sep 17, 2019

Helped @deathbybandaid with @event decorators not working and realized that this specific problem comes up a lot, relatively speaking, when Sopel users have trouble writing custom plugins.

Obviously our documentation doesn't do a great job of making sure plugin devs know that @rule is required along with @event. But rather than fix the documentation, I decided to do the user-friendly (developer-friendly?) thing and make it so event is considered triggerable just like a command or rule, and so it will also get the default .* rule applied if necessary once registered.

An early version of this patch (pre-publication) also applied this default rule to intents, but:

  • There's only one meaningful intent value ('ACTION'), which almost always requires an explicit rule anyway.
  • We're probably going to deprecate and/or remove @intents pretty soon because it's obsolete (Message intents are dead #1683).

Other rejected ideas were applying this to @url (not needed) and to @echo (immediately determined to be the exact opposite of intuitive behavior once I gave it ten seconds of thought).

So here we are: A ±0 line patch (if we ignore tests & code formatting) to the loader that saves us almost 20 real-code lines of boilerplate. Not bad for a bit of afternoon hacking, if I do say so myself.

@dgw dgw added the Tweak label Sep 17, 2019
@dgw dgw added this to the 7.0.0 milestone Sep 17, 2019
@dgw dgw requested a review from a team September 17, 2019 19:53
dgw and others added 2 commits September 17, 2019 15:21
If a callable has an event set, but no rule, the bot will add a default
'.*' (catch-all) rule when the callable is registered.

This is a developer-friendliness change. Previously, an event-based
trigger also required a catch-all rule decorator ('.*') (but this was
not very well documented).

There should be no behavior change for event handlers that also have
explicit rule decorator(s).

Thanks to @Exirel for nudging me in the right direction when my initial
approach broke everything. :P

Co-Authored-By: Exirel <florian.strzelecki@gmail.com>
Now that events have a default catch-all rule, we don't need to
repeatedly decorate stuff with '.*' everywhere.

We can remove almost 20 rule decorators, mostly in coretasks' low-level
protocol logic, and it cost us +/- 0 lines (excluding pep8 tweaks).
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

I love how simple the code is. 👍

@dgw dgw merged commit c752b10 into master Sep 18, 2019
@dgw dgw deleted the event-default-rule branch September 18, 2019 05:01
@dgw
Copy link
Member Author

dgw commented Sep 18, 2019

@Exirel Merged so you can continue #1678, as you mentioned on IRC. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants