From c9a85cdaa7b7accfd8badd544bc143043e3fd57b Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sat, 23 Feb 2013 16:22:22 -0700 Subject: [PATCH] initial twisted bot --- tbot.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tbot.py diff --git a/tbot.py b/tbot.py new file mode 100644 index 0000000..022eddd --- /dev/null +++ b/tbot.py @@ -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()