From 602f35cb700c3d366751473f4e71c272ea9c2a75 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 9 Jan 2017 21:02:56 -0800 Subject: [PATCH] clientbot: fix message recognition treating nick prefixes without ident@host as servers --- protocols/clientbot.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/protocols/clientbot.py b/protocols/clientbot.py index c69b862..54fa9f0 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -320,7 +320,7 @@ class ClientbotWrapperProtocol(Protocol): else: return # Nothing changed - def _getUid(self, nick, ident='unknown', host='unknown.host'): + def _getUid(self, nick, ident=None, host=None): """ Fetches the UID for the given nick, creating one if it does not already exist. @@ -337,7 +337,8 @@ class ClientbotWrapperProtocol(Protocol): log.debug('(%s) Nick-colliding virtual client %s/%s', self.irc.name, idsource, nick) self.irc.callHooks([self.irc.sid, 'CLIENTBOT_NICKCOLLIDE', {'target': idsource, 'parse_as': 'SAVE'}]) - idsource = self.spawnClient(nick, ident, host, server=self.irc.uplink, realname=FALLBACK_REALNAME).uid + idsource = self.spawnClient(nick, ident or 'unknown', host or 'unknown', + server=self.irc.uplink, realname=FALLBACK_REALNAME).uid return idsource @@ -387,14 +388,18 @@ class ClientbotWrapperProtocol(Protocol): # PyLink as a services framework expects UIDs and SIDs for everything. Since we connect # as a bot here, there's no explicit user introduction, so we're going to generate # pseudo-uids and pseudo-sids as we see prefixes. - if '!' not in sender: - # Sender is a server name. + if ('!' not in sender) and '.' in sender: + # Sender is a server name. XXX: make this check more foolproof idsource = self._getSid(sender) if idsource not in self.irc.servers: idsource = self.spawnServer(sender, internal=False) else: - # Sender is a nick!user@host prefix. Split it into its relevant parts. - nick, ident, host = utils.splitHostmask(sender) + # Sender is a either a nick or a nick!user@host prefix. Split it into its relevant parts. + try: + nick, ident, host = utils.splitHostmask(sender) + except ValueError: + ident = host = None # Set ident and host as null for now. + nick = sender # Treat the sender prefix we received as a nick. idsource = self._getUid(nick, ident, host) try: