grew ability to connect to multiple channels

This commit is contained in:
Stephen McQuay 2013-02-23 16:43:09 -07:00
parent c9a85cdaa7
commit 24123e84c9
1 changed files with 12 additions and 7 deletions

19
tbot.py
View File

@ -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()