Skip to content

Commit 3872427

Browse files
committed
plugin: require_bot_privilege() implies require_chanmsg()
If the bot needs a channel privilege for a given callable, it probably wants to do something related to channel operations, and triggering such a callable in response to a private message makes no sense.
1 parent 120477f commit 3872427

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

sopel/plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,16 +1716,18 @@ def require_bot_privilege(
17161716
<.bot.Sopel.say>`, but when ``reply`` is ``True`` it uses :meth:`bot.reply()
17171717
<.bot.Sopel.reply>` instead.
17181718
1719-
Privilege requirements are ignored in private messages.
1719+
Use of ``require_bot_privilege()`` implies :func:`require_chanmsg`.
17201720
17211721
.. versionadded:: 7.1
1722+
.. versionchanged:: 8.0
1723+
Decorated callables no longer run in response to private messages.
17221724
"""
17231725
def actual_decorator(function):
17241726
@functools.wraps(function)
17251727
def guarded(bot, trigger, *args, **kwargs):
1726-
# If this is a privmsg, ignore privilege requirements
1728+
# If this is a privmsg, do not trigger
17271729
if trigger.is_privmsg:
1728-
return function(bot, trigger, *args, **kwargs)
1730+
return
17291731

17301732
if not bot.has_channel_privilege(trigger.sender, level):
17311733
if message and not callable(message):

test/test_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,19 +511,19 @@ def test_require_bot_privilege_private_message(configfactory,
511511
def mock(bot, trigger):
512512
return True
513513

514-
assert mock(bot, bot._trigger) is True
514+
assert mock(bot, bot._trigger) is not True
515515

516516
@plugin.command('ban')
517517
@plugin.require_bot_privilege(plugin.OP)
518518
def mock(bot, trigger):
519519
return True
520520

521-
assert mock(bot, bot._trigger) is True
521+
assert mock(bot, bot._trigger) is not True
522522

523523
@plugin.command('ban')
524524
@plugin.require_bot_privilege(plugin.OWNER)
525525
def mock(bot, trigger):
526526
return True
527527

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

0 commit comments

Comments
 (0)