From a8e431e806d4a9a3d79d4cf4e6a5a8f4f0a04a03 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 13 Sep 2015 00:40:16 -0500 Subject: [PATCH] Support reply-nick syntax for all commands; support unspaced form. --- earwigbot/commands/link.py | 4 ---- earwigbot/irc/connection.py | 2 +- earwigbot/irc/data.py | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/earwigbot/commands/link.py b/earwigbot/commands/link.py index 438e732..a54ea51 100644 --- a/earwigbot/commands/link.py +++ b/earwigbot/commands/link.py @@ -44,10 +44,6 @@ class Link(Command): self.reply(data, links.encode("utf8")) elif data.command == "link": - if data.args and data.args[0].startswith(">"): - nick = data.args.pop(0)[1:] - data._nick = nick # XXX: hack - should be generally supported - if not data.args: if data.chan in self.last: links = u" , ".join(self.parse_line(self.last[data.chan])) diff --git a/earwigbot/irc/connection.py b/earwigbot/irc/connection.py index 14164ea..5fe15b0 100644 --- a/earwigbot/irc/connection.py +++ b/earwigbot/irc/connection.py @@ -172,7 +172,7 @@ class IRCConnection(object): if data.is_private: self.say(data.chan, msg, hidelog) else: - msg = "\x02{0}\x0F: {1}".format(data.nick, msg) + msg = "\x02{0}\x0F: {1}".format(data.reply_nick, msg) self.say(data.chan, msg, hidelog) def action(self, target, msg, hidelog=False): diff --git a/earwigbot/irc/data.py b/earwigbot/irc/data.py index 71f5f36..1947dba 100644 --- a/earwigbot/irc/data.py +++ b/earwigbot/irc/data.py @@ -52,6 +52,7 @@ class Data(object): """Parse a line from IRC into its components as instance attributes.""" sender = re.findall(r":(.*?)!(.*?)@(.*?)\Z", self.line[0])[0] self._nick, self._ident, self._host = sender + self._reply_nick = self._nick self._chan = self.line[2] if msgtype == "PRIVMSG": @@ -103,6 +104,14 @@ class Data(object): except IndexError: pass + # e.g. "!command>user arg1 arg2" + if ">" in self.command: + self._command, self._reply_nick = self.command.split(">", 1) + + # e.g. "!command >user arg1 arg2" + if self.args and self.args[0].startswith(">"): + self._reply_nick = self.args.pop(0)[1:] + def _parse_kwargs(self): """Parse keyword arguments embedded in self.args. @@ -152,6 +161,11 @@ class Data(object): return self._host @property + def reply_nick(self): + """Nickname of the person to reply to. Sender by default.""" + return self._reply_nick + + @property def msg(self): """Text of the sent message, if it is a message, else ``None``.""" return self._msg