Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 80 lines (63 sloc) 2.14 KB
#!/usr/bin/env python
from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor
from AIMLBot import AIMLBot
import sys
import re
class GrokItBot(irc.IRCClient):
An AIM bot that uses both PyAIML and Reverend Bayes
parser to learn and respond to messages.
Duncan Gough 13/03/04
- Updated to switch form TocTalk/AIM to Twisted/IRC
Duncan Gough 11/01/09
Reverend Bayes:
def _get_nickname(self):
return self.factory.nickname
nickname = property(_get_nickname)
def signedOn(self):
self.join(, self.factory.password)
print "Signed on as %s." % (self.nickname,)
def joined(self, channel):
print "Joined %s." % (channel,)
def privmsg(self, user, channel, msg):
if msg.startswith('*** '):
print msg
elif not user:
elif self.nickname in msg:
msg = re.compile(self.nickname + "[:,]* ?", re.I).sub('', msg)
prefix = "%s: " % (user.split('!', 1)[0], )
prefix = ''
sentence = self.factory.aiml.on_MSG_IN(user.split('!', 1)[0],msg)
self.msg(, prefix + sentence)
class GrokItBotFactory(protocol.ClientFactory):
protocol = GrokItBot
def __init__(self, channel, nickname, password=''): = channel
self.nickname = nickname
self.password = password
self.aiml = AIMLBot(self.nickname)
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s), reconnecting." % (reason,)
def clientConnectionFailed(self, connector, reason):
print "Could not connect: %s" % (reason,)
if __name__ == "__main__":
if len(sys.argv) > 1:
nickname = sys.argv[1]
channel = sys.argv[2]
password = sys.argv[3]
nickname = 'GrokItBot'
channel = ''
password = ''
reactor.connectTCP('', 6667, GrokItBotFactory('#' + channel, nickname, password))