From 24123e84c9bd6f5bcc803719146e13350b3d915b Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sat, 23 Feb 2013 16:43:09 -0700 Subject: [PATCH] grew ability to connect to multiple channels --- tbot.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tbot.py b/tbot.py index 022eddd..3e0f60c 100644 --- a/tbot.py +++ b/tbot.py @@ -1,5 +1,3 @@ -import sys - from twisted.words.protocols import irc from twisted.internet import protocol, reactor @@ -10,21 +8,28 @@ class IDRTBot(irc.IRCClient): return self.factory.nickname def signedOn(self): - self.join(self.factory.channel) + for c in self.factory.channels: + self.join(c) print('signed on as {}.'.format(self.nickname)) def joined(self, channel): print('joined {}'.format(channel)) def privmsg(self, user, channel, msg): - print('{} | {} | {}'.foramt(user, channel, msg)) + print('user: {} | channel: {} | msg: {}'.format(user, channel, msg)) + username = user.split('!', 1)[0] + if channel == self.nickname: + print('got private message') + self.msg(username, "whisper back ...") + if self.nickname in msg: + self.msg(channel, 'echo: {}'.format(msg)) class IDRTBotFactory(protocol.ClientFactory): protocol = IDRTBot - def __init__(self, channel, nickname='idrt'): - self.channel = channel + def __init__(self, channels, nickname='idrt'): + self.channels = channels self.nickname = nickname def clientConnectionLost(self, connector, reason): @@ -34,5 +39,5 @@ class IDRTBotFactory(protocol.ClientFactory): print('could not connect: {}'.format(reason)) -reactor.connectTCP('localhost', 6668, IDRTBotFactory('#smb')) +reactor.connectTCP('localhost', 6667, IDRTBotFactory(['#smb', '#linux'])) reactor.run()