diff --git a/BUGS b/BUGS index 1a038ab..dc892c2 100644 --- a/BUGS +++ b/BUGS @@ -1,12 +1,10 @@ dr.botzo --- BUGS - * math in DrBotServerConnection.privmsg splitting is off. used to be a couple characters, - now is more. usermask thing? * aliases referencing the bot by name, like !join #botname, just have MegaHAL fire twice this one may be more tricky as it involves alias order of operations and whatnot. maybe it's time to finally implement an internal message bus distinct from the pubmsg handler * being in #chan and telling the bot to !part #chan is a crash if it can't message #chan after it leaves - * probably many, many more * Countdown formatting has singular nouns for negative numbers (-21 day) + * probably many, many more diff --git a/DrBotIRC.py b/DrBotIRC.py index 100ed11..009fa84 100644 --- a/DrBotIRC.py +++ b/DrBotIRC.py @@ -28,6 +28,24 @@ class DrBotServerConnection(irclib.ServerConnection): """Subclass irclib's ServerConnection, in order to expand privmsg.""" + hostname = None + + def __init__(self, irclibobj): + irclib.ServerConnection.__init__(self, irclibobj) + + # temporary. hopefully on_welcome() will set this + self.hostname = socket.getfqdn() + + self.add_global_handler('welcome', self.on_welcome, 1) + + def on_welcome(self, connection, event): + """Set the hostname that the ircd tells us is us.""" + what = event.arguments()[0] + + match = re.search('(\S+!\S+@\S+)', what) + if match: + self.hostname = match.group(1) + def privmsg(self, target, text): """Send a PRIVMSG command.""" @@ -36,7 +54,8 @@ class DrBotServerConnection(irclib.ServerConnection): # split messages that are too long. Max length is 512. # TODO: this does not properly handle when the hostname has been # masked by the ircd - space = 512 - len('\r\n') - len('PRIVMSG ') - len(' :') - len(target) - len(self.nickname) - len('!') - len(self.username) - len('@') - len(socket.getfqdn()) + # is the above still the case? + space = 512 - len('\r\n') - len('PRIVMSG ') - len(' :') - len(target) - len(self.nickname) - len('!') - len(self.username) - len('@') - len(self.hostname) splitspace = space - (len(splitter) + 1) if len(text) > space: