grew ability to connect to multiple channels
This commit is contained in:
parent
c9a85cdaa7
commit
24123e84c9
19
tbot.py
19
tbot.py
@ -1,5 +1,3 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from twisted.words.protocols import irc
|
from twisted.words.protocols import irc
|
||||||
from twisted.internet import protocol, reactor
|
from twisted.internet import protocol, reactor
|
||||||
|
|
||||||
@ -10,21 +8,28 @@ class IDRTBot(irc.IRCClient):
|
|||||||
return self.factory.nickname
|
return self.factory.nickname
|
||||||
|
|
||||||
def signedOn(self):
|
def signedOn(self):
|
||||||
self.join(self.factory.channel)
|
for c in self.factory.channels:
|
||||||
|
self.join(c)
|
||||||
print('signed on as {}.'.format(self.nickname))
|
print('signed on as {}.'.format(self.nickname))
|
||||||
|
|
||||||
def joined(self, channel):
|
def joined(self, channel):
|
||||||
print('joined {}'.format(channel))
|
print('joined {}'.format(channel))
|
||||||
|
|
||||||
def privmsg(self, user, channel, msg):
|
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):
|
class IDRTBotFactory(protocol.ClientFactory):
|
||||||
protocol = IDRTBot
|
protocol = IDRTBot
|
||||||
|
|
||||||
def __init__(self, channel, nickname='idrt'):
|
def __init__(self, channels, nickname='idrt'):
|
||||||
self.channel = channel
|
self.channels = channels
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
|
|
||||||
def clientConnectionLost(self, connector, reason):
|
def clientConnectionLost(self, connector, reason):
|
||||||
@ -34,5 +39,5 @@ class IDRTBotFactory(protocol.ClientFactory):
|
|||||||
print('could not connect: {}'.format(reason))
|
print('could not connect: {}'.format(reason))
|
||||||
|
|
||||||
|
|
||||||
reactor.connectTCP('localhost', 6668, IDRTBotFactory('#smb'))
|
reactor.connectTCP('localhost', 6667, IDRTBotFactory(['#smb', '#linux']))
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user