| 1 | | #!/usr/bin/env python |
| 2 | | |
| 3 | | # Copyright (c) 2009 Twisted Matrix Laboratories. |
| 4 | | # See LICENSE for details. |
| 5 | | |
| 6 | | """ |
| 7 | | AIM echo bot. |
| 8 | | """ |
| 9 | | |
| 10 | | from twisted.words.protocols import toc |
| 11 | | from twisted.internet import reactor, protocol |
| 12 | | import twisted.words.im.tocsupport as ts |
| 13 | | |
| 14 | | # account info |
| 15 | | screenname = 'username' |
| 16 | | password = 'password' |
| 17 | | |
| 18 | | class aimBot(toc.TOCClient): |
| 19 | | """AOL Instant Messenger echo bot""" |
| 20 | | |
| 21 | | def gotConfig(self, mode, buddylist, permit, deny): |
| 22 | | """called when the server sends us config info""" |
| 23 | | global screename |
| 24 | | |
| 25 | | # add someone to our deny list? |
| 26 | | self.add_deny([]) |
| 27 | | |
| 28 | | # add ourself to our buddy list |
| 29 | | self.add_buddy([screenname]) |
| 30 | | |
| 31 | | # finish up the signon procedure |
| 32 | | self.signon() |
| 33 | | |
| 34 | | def updateBuddy(self,username,online,evilness,signontime,idletime,userclass,away): |
| 35 | | """called when a buddy changes state""" |
| 36 | | print "status changed for",username |
| 37 | | |
| 38 | | def hearWarning(self, warnlvl, screenname): |
| 39 | | """called when someone warns us""" |
| 40 | | print screenname,"warned us" |
| 41 | | |
| 42 | | def hearError(self, errcode, *args): |
| 43 | | """called when server sends error""" |
| 44 | | print "recieved error:",errcode |
| 45 | | |
| 46 | | def hearMessage(self, username, message, autoreply): |
| 47 | | """called when a message is recieved""" |
| 48 | | |
| 49 | | # remove the incoming message' html |
| 50 | | msg = ts.dehtml(message) |
| 51 | | |
| 52 | | print "got message:",msg |
| 53 | | |
| 54 | | # construct the reply, and turn it into html |
| 55 | | reply = ts.html("echo: %s" % msg) |
| 56 | | |
| 57 | | self.say(username, reply) |
| 58 | | |
| 59 | | cc = protocol.ClientCreator(reactor, aimBot, screenname, password) |
| 60 | | cc.connectTCP("toc.oscar.aol.com", 9898) |
| 61 | | |
| 62 | | reactor.run() |