X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/c8d451e84b52bff57d38c9c6bcfcb4ab21281db6..68b3e2ee0983e0827d5d2600bffa00f47bb12959:/twitter/ircbot.py diff --git a/twitter/ircbot.py b/twitter/ircbot.py index fb14c11..53e4ede 100644 --- a/twitter/ircbot.py +++ b/twitter/ircbot.py @@ -17,16 +17,18 @@ CONFIG_FILE server: port: nick: -channel: +channel: [twitter] email: password: If no config file is given "twitterbot.ini" will be used by default. + + The channel argument can accept multiple channels separated by commas. """ -BOT_VERSION = "TwitterBot 0.5.1 (http://mike.verdone.ca/twitter)" +BOT_VERSION = "TwitterBot 1.1 (http://mike.verdone.ca/twitter)" IRC_BOLD = chr(0x02) IRC_ITALIC = chr(0x16) @@ -131,7 +133,7 @@ class TwitterBot(object): # TODO This would be better if we only ignored messages # to people who are not on our following list. if not text.startswith("@"): - self.privmsg_channel( + self.privmsg_channels( u"=^_^= %s%s%s %s" %( IRC_BOLD, update['user']['screen_name'], IRC_BOLD, text.decode('utf-8'))) @@ -179,6 +181,11 @@ class TwitterBot(object): return self.ircServer.privmsg( self.config.get('irc', 'channel'), msg.encode('utf-8')) + def privmsg_channels(self, msg): + return_response=True + channels=self.config.get('irc','channel').split(',') + return self.ircServer.privmsg_many(channels, msg.encode('utf-8')) + def follow(self, conn, evt, name): userNick = evt.source().split('!')[0] friends = [x['name'] for x in self.twitter.statuses.friends()] @@ -198,7 +205,7 @@ class TwitterBot(object): conn.privmsg( userNick, "=^_^= Okay! I'm now following %s." %(name)) - self.privmsg_channel( + self.privmsg_channels( "=o_o= %s has asked me to start following %s" %( userNick, name)) @@ -215,7 +222,7 @@ class TwitterBot(object): conn.privmsg( userNick, "=^_^= Okay! I've stopped following %s." %(name)) - self.privmsg_channel( + self.privmsg_channels( "=o_o= %s has asked me to stop following %s" %( userNick, name)) @@ -224,7 +231,9 @@ class TwitterBot(object): self.config.get('irc', 'server'), self.config.getint('irc', 'port'), self.config.get('irc', 'nick')) - self.ircServer.join(self.config.get('irc', 'channel')) + channels=self.config.get('irc', 'channel').split(',') + for channel in channels: + self.ircServer.join(channel) while True: try: @@ -241,24 +250,24 @@ def load_config(filename): cp.read((filename,)) # attempt to read these properties-- they are required - self.config.get('twitter', 'email'), - self.config.get('twitter', 'password') - self.config.get('irc', 'server') - self.config.getint('irc', 'port') - self.config.get('irc', 'nick') + cp.get('twitter', 'email'), + cp.get('twitter', 'password') + cp.get('irc', 'server') + cp.getint('irc', 'port') + cp.get('irc', 'nick') + cp.get('irc', 'channel') return cp - -# Howdy, hacker!! You've found the secret Twitter business model!! +# So there was a joke here about the twitter business model +# but I got rid of it. Not because I want this codebase to +# be "professional" in any way, but because someone forked +# this and deleted the comment because they couldn't take +# a joke. Hi guy! # -# 1. provide awesome status-update service -# 2. buy a lot of new hardware to keep it running -# 3. ??? -# 4. profit! -# -# I'm just kidding... :3 - +# Fact: The number one use of Google Code is to look for that +# comment in the Linux kernel that goes "FUCK me gently with +# a chainsaw." Pretty sure Linus himself wrote it. def main(): configFilename = "twitterbot.ini" @@ -269,10 +278,11 @@ def main(): if not os.path.exists(configFilename): raise Exception() load_config(configFilename) - except: + except Exception, e: print >> sys.stderr, "Error while loading ini file %s" %( configFilename) - print __doc__ + print >> sys.stderr, e + print >> sys.stderr, __doc__ sys.exit(1) bot = TwitterBot(configFilename)