diff --git a/sopel/plugin.py b/sopel/plugin.py index 1b38149ca..2f47b6889 100644 --- a/sopel/plugin.py +++ b/sopel/plugin.py @@ -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 if not bot.has_channel_privilege(trigger.sender, level): if message and not callable(message): diff --git a/test/test_plugin.py b/test/test_plugin.py index 324a22389..7bbe66e90 100644 --- a/test/test_plugin.py +++ b/test/test_plugin.py @@ -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.')