From: Prashant Pawar Date: Sun, 18 Apr 2010 15:34:50 +0000 (-0400) Subject: Added the ability in IRC bot to operate on multiple channels. Config file now accepts... X-Git-Tag: twitter-1.3~8 X-Git-Url: https://jfr.im/git/z_archive/twitter.git/commitdiff_plain/c1b9acea68a44614db73ba20acac9cf15846d3ee?hp=cd7ce713e9f11559092b58ed368a47a85d1146fe Added the ability in IRC bot to operate on multiple channels. Config file now accepts multiple channel names seperated by a comma. Signed-off-by: Prashant Pawar --- diff --git a/twitter/ircbot.py b/twitter/ircbot.py index a10a5f1..afde87c 100644 --- a/twitter/ircbot.py +++ b/twitter/ircbot.py @@ -131,7 +131,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 +179,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 +203,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 +220,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 +229,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: