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 require account feature #1733

Merged
merged 4 commits into from
Nov 18, 2019
Merged

module: add require account feature #1733

merged 4 commits into from
Nov 18, 2019

Conversation

dgw
Copy link
Member

@dgw dgw commented Nov 3, 2019

Fresh from my well-rested (not really) keyboard* comes this: a new plugin decorator. It lets you require that a user be authenticated to network services (NickServ or whatever) to use a given function.

I added a test for the new decorator, fixed a mistake in require_chanmsg's test, and made all the require_* decorators consistent in terms of code structure. A couple of them were using a silly trick to get the bot and trigger args by name. Someone please take a good look at those changes too, to make sure I didn't forget something dumb (like how I almost forgot to pass bot and trigger to the actual function after checking the conditions and had to amend the commit).

Here's a rendered preview of the documentation for @module.require_account:

Documentation preview for 'require_account' decorator

This idea was inspired by an account-related question from @RhinosF1 on IRC, and encouraged by @deathbybandaid. (But honestly, dbb gets excited about every idea. 😝)


* — I said I'd do "less than last year" for Hacktoberfest (when I made a PR every day), and technically I kept that promise. I made one PR less than last year.

dgw added 4 commits November 3, 2019 15:07
Functions decorated with this will be blocked if a user tries to use
them without logging in to network services first. Obviously, this only
works on networks that support the capabilities Sopel needs to determine
whether a user is logged in.
The privmsg/chanmsg decorators were using a silly trick to get `bot` and
`trigger` out of the passed `*args` by array indexes. It works, and it's
elegant (quite Pythonic, in fact), but most of the decorators explicitly
define those as arguments to the guard function and avoid the hacky way.
The second set of assertions was testing the first `mock` function again
instead of the second `mock_` with a decorator sans parentheses.
@dgw dgw added this to the 7.0.0 milestone Nov 3, 2019
@dgw dgw requested a review from a team November 3, 2019 21:57
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.

Looks good to me. 👍

@dgw dgw merged commit 61c729b into master Nov 18, 2019
@dgw dgw deleted the module.require_account branch November 18, 2019 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants