diff --git a/earwigbot/irc/data.py b/earwigbot/irc/data.py index aaff822..06c8d5d 100644 --- a/earwigbot/irc/data.py +++ b/earwigbot/irc/data.py @@ -55,15 +55,16 @@ class Data(object): self._reply_nick = self._nick self._chan = self.line[2] - if self._msgtype == "PRIVMSG": + if self._msgtype in ["PRIVMSG", "NOTICE"]: if self.chan.lower() == self.my_nick: # This is a privmsg to us, so set 'chan' as the nick of the # sender instead of the 'channel', which is ourselves: self._chan = self._nick self._is_private = True self._msg = " ".join(self.line[3:])[1:] - self._parse_args() - self._parse_kwargs() + if self._msgtype == "PRIVMSG": + self._parse_args() + self._parse_kwargs() def _parse_args(self): """Parse command arguments from the message. diff --git a/earwigbot/irc/frontend.py b/earwigbot/irc/frontend.py index e92366f..a81ccc1 100644 --- a/earwigbot/irc/frontend.py +++ b/earwigbot/irc/frontend.py @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from time import sleep + from earwigbot.irc import IRCConnection, Data __all__ = ["Frontend"] @@ -36,6 +38,7 @@ class Frontend(IRCConnection): :py:mod:`earwigbot.commands` or the bot's custom command directory (explained in the :doc:`documentation `). """ + NICK_SERVICES = "NickServ" def __init__(self, bot): self.bot = bot @@ -43,6 +46,8 @@ class Frontend(IRCConnection): base = super(Frontend, self) base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"], cf["realname"], bot.logger.getChild("frontend")) + + self._auth_wait = False self._connect() def __repr__(self): @@ -56,6 +61,11 @@ class Frontend(IRCConnection): res = "" return res.format(self.nick, self.ident, self.host, self.port) + def _join_channels(self): + """Join all startup channels as specified by the config file.""" + for chan in self.bot.config.irc["frontend"]["channels"]: + self.join(chan) + def _process_message(self, line): """Process a single message from IRC.""" if line[1] == "JOIN": @@ -74,17 +84,27 @@ class Frontend(IRCConnection): self.bot.commands.call("msg_public", data) self.bot.commands.call("msg", data) + elif line[1] == "NOTICE": + data = Data(self.nick, line, msgtype="NOTICE") + if self._auth_wait and data.nick == self.NICK_SERVICES: + self._auth_wait = False + sleep(2) # Wait for hostname change to propagate + self._join_channels() + elif line[1] == "376": # On successful connection to the server # If we're supposed to auth to NickServ, do that: try: username = self.bot.config.irc["frontend"]["nickservUsername"] password = self.bot.config.irc["frontend"]["nickservPassword"] except KeyError: - pass + self._join_channels() else: msg = "IDENTIFY {0} {1}".format(username, password) - self.say("NickServ", msg, hidelog=True) + self.say(self.NICK_SERVICES, msg, hidelog=True) + self._auth_wait = True - # Join all of our startup channels: - for chan in self.bot.config.irc["frontend"]["channels"]: - self.join(chan) + elif line[1] == "401": # No such nickname + if self._auth_wait and line[3] == self.NICK_SERVICES: + # Services is down, or something...? + self._auth_wait = False + self._join_channels()