From bf7074b76eaac19203bb05a77c860560215fc713 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 7 Jan 2011 23:56:51 -0600 Subject: [PATCH] use a welcome handler to capture the bot's nickmask. we do this deep in the server in order to have the split functionality use it properly. i still don't know if it handles server privacy masks properly (which would only be noticed if that cloak is sent when you connect). actually, on that note, this only works if the ircd sends the nickmask in 001. but hey, it works on one server at least --- BUGS | 4 +--- DrBotIRC.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) 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: