|
@@ 405-433 (lines=29) @@
|
| 402 |
|
return actual_decorator |
| 403 |
|
|
| 404 |
|
|
| 405 |
|
def require_chanmsg(message=None, reply=False): |
| 406 |
|
"""Decorate a function to only be triggerable from a channel message. |
| 407 |
|
|
| 408 |
|
:param str message: optional message said if triggered in private message |
| 409 |
|
:param bool reply: use :meth:`~.bot.Sopel.reply` instead of |
| 410 |
|
:meth:`~.bot.Sopel.say` when ``True``; defaults to |
| 411 |
|
``False`` |
| 412 |
|
|
| 413 |
|
If it is triggered in a private message, ``message`` will be said if |
| 414 |
|
given. By default, it uses :meth:`bot.say() <.bot.Sopel.say>`, but when |
| 415 |
|
``reply`` is true, then it uses :meth:`bot.reply() <.bot.Sopel.reply>` |
| 416 |
|
instead. |
| 417 |
|
|
| 418 |
|
.. versionchanged:: 7.0.0 |
| 419 |
|
Added the ``reply`` parameter. |
| 420 |
|
""" |
| 421 |
|
def actual_decorator(function): |
| 422 |
|
@functools.wraps(function) |
| 423 |
|
def _nop(*args, **kwargs): |
| 424 |
|
# Assign trigger and bot for easy access later |
| 425 |
|
bot, trigger = args[0:2] |
| 426 |
|
if not trigger.is_privmsg: |
| 427 |
|
return function(*args, **kwargs) |
| 428 |
|
else: |
| 429 |
|
if message and not callable(message): |
| 430 |
|
if reply: |
| 431 |
|
bot.reply(message) |
| 432 |
|
else: |
| 433 |
|
bot.say(message) |
| 434 |
|
return _nop |
| 435 |
|
|
| 436 |
|
# Hack to allow decorator without parens |
|
@@ 368-396 (lines=29) @@
|
| 365 |
|
return add_attribute |
| 366 |
|
|
| 367 |
|
|
| 368 |
|
def require_privmsg(message=None, reply=False): |
| 369 |
|
"""Decorate a function to only be triggerable from a private message. |
| 370 |
|
|
| 371 |
|
:param str message: optional message said if triggered in a channel |
| 372 |
|
:param bool reply: use :meth:`~sopel.bot.Sopel.reply` instead of |
| 373 |
|
:meth:`~sopel.bot.Sopel.say` when ``True``; defaults to |
| 374 |
|
``False`` |
| 375 |
|
|
| 376 |
|
If it is triggered in a channel message, ``message`` will be said if |
| 377 |
|
given. By default, it uses :meth:`bot.say() <.bot.Sopel.say>`, but when |
| 378 |
|
``reply`` is true, then it uses :meth:`bot.reply() <.bot.Sopel.reply>` |
| 379 |
|
instead. |
| 380 |
|
|
| 381 |
|
.. versionchanged:: 7.0.0 |
| 382 |
|
Added the ``reply`` parameter. |
| 383 |
|
""" |
| 384 |
|
def actual_decorator(function): |
| 385 |
|
@functools.wraps(function) |
| 386 |
|
def _nop(*args, **kwargs): |
| 387 |
|
# Assign trigger and bot for easy access later |
| 388 |
|
bot, trigger = args[0:2] |
| 389 |
|
if trigger.is_privmsg: |
| 390 |
|
return function(*args, **kwargs) |
| 391 |
|
else: |
| 392 |
|
if message and not callable(message): |
| 393 |
|
if reply: |
| 394 |
|
bot.reply(message) |
| 395 |
|
else: |
| 396 |
|
bot.say(message) |
| 397 |
|
return _nop |
| 398 |
|
|
| 399 |
|
# Hack to allow decorator without parens |