DrBotIRC: use config nick/user to guess nickhost
we still override the nickhost guess with what comes out of the ircd's welcome message, if it is a full nick!user@host (although now i'm doubting if we should expect such a thing or if it was just unrealircd being nice), but this produces more accurate guesses for the cases where we don't do that override. this was affecting splitting
This commit is contained in:
parent
a10e54bcc8
commit
582328973e
27
DrBotIRC.py
27
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
|
||||
|
Loading…
Reference in New Issue
Block a user