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

module: add action_commands decorator #1660

Merged
merged 5 commits into from
Oct 15, 2019

Conversation

deathbybandaid
Copy link
Contributor

As per my idea in Issue #1658, this is my attempt to integrate an action_commands command structure to Sopel.

There are still things to work out here, I'm sure. I copied elements I saw in intents, commands, and nickname_commands. I am very well aware the docstrings will definitely need work, as well as tests added.

I'm also not happy with the import line adjusted, and will likely fix that with () later.

This is more/less a draft PR, but my brief tests were very successful.

@deathbybandaid
Copy link
Contributor Author

Test file used:

# coding=utf-8

from __future__ import unicode_literals, absolute_import, division, print_function

import sopel.module


@sopel.module.commands('dbbtest')
def bot_command_dbbtest(bot, trigger):
    bot.say(str(trigger))
    bot.say(str(trigger.args))



@sopel.module.action_commands('rolls')
def bot_command_dbbtestb(bot, trigger):
    bot.say(str(trigger))
    bot.say(str(trigger.args))

Output:

<deathbybandaid> .dbbtest this out
<dbbbot> .dbbtest this out
<dbbbot> ['#deathbybandaid', '.dbbtest this out']


* deathbybandaid rolls dice
<dbbbot> rolls dice
<dbbbot> ['#deathbybandaid', 'rolls dice']

@dgw dgw added the Feature label Aug 20, 2019
@dgw
Copy link
Member

dgw commented Aug 20, 2019

Looking at this led me to the discovery that inspired #1683. Specifically, the implementation here made me wonder "what other intents are there?", which led to finding out that the intent spec no longer exists. This decorator is a pretty good idea, actually, especially because we'll want to replace the internal references to "intents" on callables and triggers with something else that isn't obsolete. Could be as simple as trigger.is_action and a callable.on_actions Boolean (default False). Further discussion and ideas very much welcome in #1683!

@deathbybandaid
Copy link
Contributor Author

deathbybandaid commented Oct 3, 2019

Forced Pushed to rebase with current master.

I could use some help writing the tests for test_module.py.

A thorough review would also be nice to clean/tidy it up. However, I feel fairly positive about what is accomplished here.

As discussed via IRC, this can be implemented, with the current intents code, with the intention (not a pun) of other PRs being opened later, such as:

  • Re-evaluating how CTCP is handled
  • Based on ^ how we want to handle something like trigger.is_action
  • Deprecating @intents, maybe in favor of a replacement @ctcp, since we may still want to allow @rule pattern matching.
  • Removal of the ability to run @commands via a CTCP ACTION

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Right, so it looks like this should do what is expected/desired. We do have to think about future-proofing and decorator interactions, though.

For example, if a function has both @commands and @nickname_commands, they'll both work, because normal PRIVMSGs are acceptable for both of those. Mix @action_commands in, though, and the other decorator types stop working as expected because of the added ACTION intent. This should, at minimum, be explicitly called out in the documentation. Ideally we'd make it so all of the command types can be mixed on a single callable, but I think that would require a rework of some internals. Definitely out of scope for this PR, but worth keeping in mind as we continue refining 7.x.

Thing is, having @action_commands is definitely more useful than not having it, even if there are some potential conflicts with the other decorators. I can personally streamline, at a quick estimate, three or four of my own plugins using this new feature. If my crappy old code from four years ago can use this—so can the Sopel ecosystem at large.

PS: The rebase introduced some whitespace oddities, most (all?) of which I marked with line notes.

sopel/module.py Outdated Show resolved Hide resolved
sopel/tools/__init__.py Show resolved Hide resolved
sopel/tools/__init__.py Show resolved Hide resolved
sopel/tools/__init__.py Outdated Show resolved Hide resolved
sopel/module.py Outdated Show resolved Hide resolved
sopel/module.py Show resolved Hide resolved
sopel/module.py Show resolved Hide resolved
sopel/module.py Show resolved Hide resolved
sopel/module.py Show resolved Hide resolved
@dgw dgw added this to the 7.0.0 milestone Oct 3, 2019
@deathbybandaid
Copy link
Contributor Author

That was really odd with the whitespace disappearing from my push. Looked normal in my editor.

Added all the requested changes though.

@dgw
Copy link
Member

dgw commented Oct 5, 2019

Hmm, that force-push undid all the changes. You should try rebasing/squashing again from 44cd95d.

@deathbybandaid
Copy link
Contributor Author

@dgw, something is screwy on my end, and everytime I squash, those whitespaces change.
I'll look at it more when I get the chance.

@deathbybandaid
Copy link
Contributor Author

I deleted the cloned directory, recloned, squashed, and it looks like the problem went away.

Not sure what was happening before, but it looks like everything is there.

sopel/module.py Show resolved Hide resolved
@dgw dgw requested a review from Exirel October 9, 2019 13:12
@dgw
Copy link
Member

dgw commented Oct 9, 2019

If I'm touching tests, I like @Exirel to look at it. 😁

@dgw dgw force-pushed the action_commands branch from 27777c2 to 2da3e16 Compare October 9, 2019 13:21
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.

Yeah, the tests are good @dgw

@dgw dgw force-pushed the action_commands branch from 2da3e16 to 21a4ddd Compare October 11, 2019 08:54
@dgw
Copy link
Member

dgw commented Oct 11, 2019

Had to rebase on master for that last tweak (getting logging & docstrings squared away in bot.py). I didn't want to rebase, but the alternative was making a separate PR, and that seemed silly.

@dgw dgw force-pushed the action_commands branch from 21a4ddd to 08cf7bb Compare October 11, 2019 12:42
@dgw
Copy link
Member

dgw commented Oct 11, 2019

And rebased again due to conflicting changes in #1708. 😦

sopel/loader.py Outdated Show resolved Hide resolved
@dgw dgw merged commit 5b047d1 into sopel-irc:master Oct 15, 2019
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.

3 participants