#!/usr/bin/python # TYPE:internet # DESC:An AOL instant messaging bot, acting as a message echoer of sorts. It holds the last 10 messages sent to it in messages[], and the name of the person who sent the message. from twisted.internet import default default.install() from twisted.protocols import oscar from twisted.internet import protocol, reactor from re import sub i = 0 messages = [] def show_messages(): global messages things = "[** see profile **]
These are the things people have said:

" for message in messages: things = things+message+"
" return things def add_message(user, message): global i global messages if len(messages) < 10: messages.append(str(message)+" [from "+str(user)+"]") else: messages[i%10] = str(message)+" [from "+str(user)+"]" i += 1 SN = "screenname" PASS = "password" hostport = ('login.oscar.aol.com', 5190) icqMode = 0 class B(oscar.BOSConnection): capabilities = [oscar.CAP_CHAT] def initDone(self): self.requestSelfInfo().addCallback(self.gotSelfInfo) self.requestSSI().addCallback(self.gotBuddyList) def gotSelfInfo(self, user): print user.__dict__ self.name = user.name def gotBuddyList(self, l): print l self.activateSSI() self.setProfile("This bot is from http://www.tinpenguin.com/python/buddybot.py .") self.setIdleTime(0) self.clientReady() def receiveMessage(self, user, multiparts, flags): message = sub("<[^>]*>","",multiparts[0][0]) print user.name, 'said: "', message,'"' if multiparts[0][0].find('away')!=-1: self.setAway(user.name+' told me to go away from my computer right now.') elif multiparts[0][0].find('back')!=-1: self.setAway(None) if self.awayMessage: self.sendMessage(user.name,''+self.awayMessage,autoResponse=1) else: self.lastUser = user.name add_message(user.name, message) things = show_messages() self.sendMessage(user.name, things, wantAck = 1, autoResponse = (self.awayMessage!=None)) class OA(oscar.OscarAuthenticator): BOSClass = B protocol.ClientCreator(reactor, OA, SN, PASS,icq=icqMode).connectTCP(*hostport) reactor.run()