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

plugin: require_bot_privilege() implies require_chanmsg() #2580

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions sopel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,16 +1716,18 @@ def require_bot_privilege(
<.bot.Sopel.say>`, but when ``reply`` is ``True`` it uses :meth:`bot.reply()
<.bot.Sopel.reply>` instead.

Privilege requirements are ignored in private messages.
Use of ``require_bot_privilege()`` implies :func:`require_chanmsg`.

.. versionadded:: 7.1
.. versionchanged:: 8.0
Decorated callables no longer run in response to private messages.
"""
def actual_decorator(function):
@functools.wraps(function)
def guarded(bot, trigger, *args, **kwargs):
# If this is a privmsg, ignore privilege requirements
# If this is a privmsg, do not trigger
if trigger.is_privmsg:
return function(bot, trigger, *args, **kwargs)
return
dgw marked this conversation as resolved.
Show resolved Hide resolved

if not bot.has_channel_privilege(trigger.sender, level):
if message and not callable(message):
Expand Down
10 changes: 6 additions & 4 deletions test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,19 +511,21 @@ def test_require_bot_privilege_private_message(configfactory,
def mock(bot, trigger):
return True

assert mock(bot, bot._trigger) is True
assert mock(bot, bot._trigger) is not True, (
'Callable requiring bot channel privilege must be ignored in private.')

@plugin.command('ban')
@plugin.require_bot_privilege(plugin.OP)
def mock(bot, trigger):
return True

assert mock(bot, bot._trigger) is True
assert mock(bot, bot._trigger) is not True, (
'Callable requiring bot channel privilege must be ignored in private.')

@plugin.command('ban')
@plugin.require_bot_privilege(plugin.OWNER)
def mock(bot, trigger):
return True

assert mock(bot, bot._trigger) is True, (
'There must not be privilege check for a private message.')
assert mock(bot, bot._trigger) is not True, (
'Callable requiring bot channel privilege must be ignored in private.')