diff --git a/DrBotIRC.py b/DrBotIRC.py index 5303001..8fef15b 100644 --- a/DrBotIRC.py +++ b/DrBotIRC.py @@ -111,7 +111,7 @@ class DrBotServerConnection(irclib.ServerConnection): nickmask = None - def __init__(self, irclibobj): + def __init__(self, irclibobj, nickname=None, username=None): """Instantiate the server connection. Also start guessing at the nickmask and get ready to do on_welcome @@ -119,13 +119,20 @@ class DrBotServerConnection(irclib.ServerConnection): Args: irclibobj the irclib instance to connect with + nickname the nickname to use in nickmask guess + username the username to use in nickmask guess """ irclib.ServerConnection.__init__(self, irclibobj) - # temporary. hopefully on_welcome() will set this - self.nickmask = socket.getfqdn() + # temporary. hopefully on_welcome() will set this, but this should be + # a pretty good guess if not + nick = nickname + user = username if username is not None else nick + host = socket.getfqdn() + self.nickmask = "{0:s}!~{1:s}@{2:s}".format(nick, user, host) + log.debug("guessing at nickmask '{0:s}'".format(self.nickmask)) self.add_global_handler('welcome', self.on_welcome, 1) @@ -145,7 +152,7 @@ class DrBotServerConnection(irclib.ServerConnection): match = re.search('(\S+!\S+@\S+)', what) if match: self.nickmask = match.group(1) - log.debug("nickmask: {0:s}".format(self.nickmask)) + log.debug("setting nickmask: {0:s}".format(self.nickmask)) def privmsg(self, target, text): """Send a PRIVMSG command. @@ -232,7 +239,17 @@ class DrBotIRC(irclib.IRC): """ - self.server = DrBotServerConnection(self) + # get the nick and user name so we can provide it to + # DrBotServerConnection as a hint for the nickmask + user = None + nick = None + try: + if self.config.has_section('dr.botzo'): + user = self.config.get('dr.botzo', 'user') + nick = self.config.get('dr.botzo', 'nick') + except NoOptionError: pass + + self.server = DrBotServerConnection(self, user, nick) self.connections.append(self.server) return self.server