initial twisted bot

This commit is contained in:
Stephen McQuay 2013-02-23 16:22:22 -07:00
commit c9a85cdaa7
1 changed files with 38 additions and 0 deletions

38
tbot.py Normal file
View File

@ -0,0 +1,38 @@
import sys
from twisted.words.protocols import irc
from twisted.internet import protocol, reactor
class IDRTBot(irc.IRCClient):
@property
def nickname(self):
return self.factory.nickname
def signedOn(self):
self.join(self.factory.channel)
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))
class IDRTBotFactory(protocol.ClientFactory):
protocol = IDRTBot
def __init__(self, channel, nickname='idrt'):
self.channel = channel
self.nickname = nickname
def clientConnectionLost(self, connector, reason):
print('lost connection({}), reconnecting.'.format(reason))
def clientConnectionFailed(self, connector, reason):
print('could not connect: {}'.format(reason))
reactor.connectTCP('localhost', 6668, IDRTBotFactory('#smb'))
reactor.run()