Skip to content

Commit

Permalink
Add /me slaps <nick> support
Browse files Browse the repository at this point in the history
Comes with bonus extra refactoring I can't be bothered to `git commit
--amend` into my earlier prep work. Besides, `formatting.plain()` *was*
only called once, so it wasn't redundant yet. :P
  • Loading branch information
dgw committed Aug 17, 2024
1 parent bfce152 commit 763b16d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 14 additions & 3 deletions sopel_slap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
from __future__ import annotations

from sopel import formatting, plugin
from sopel import plugin

from .util import slap

Expand All @@ -22,7 +22,18 @@ def slap_command(bot, trigger):

if target is None:
target = trigger.nick
else:
target = formatting.plain(target)

return slap(bot, trigger, target)


@plugin.ctcp('ACTION')
@plugin.rule(r'^slaps (\w+)$')
def slap_action(bot, trigger):
"""Slap someone using the power of CTCP ACTION."""
target = trigger.group(1)

if target is None:
# no self-slaps via /me; just fail silently
return plugin.NOLIMIT

return slap(bot, trigger, target)
5 changes: 4 additions & 1 deletion sopel_slap/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import random
from typing import TYPE_CHECKING

from sopel import tools
from sopel import formatting, tools

if TYPE_CHECKING:
from sopel.bot import SopelWrapper
Expand All @@ -31,6 +31,9 @@

def slap(bot: SopelWrapper, trigger: Trigger, target: str):
"""Do the slapping."""
# the target could contain formatting control codes, so strip those
target = formatting.plain(target)

# ensure target is an Identifier to increase reliability of "is nick" check
if not isinstance(target, tools.Identifier):
if hasattr(bot, 'make_identifier'):
Expand Down

0 comments on commit 763b16d

Please sign in to comment.