From d47b17d4883773fd1f91d7d87420ec751875279a Mon Sep 17 00:00:00 2001 From: yvesf Date: Mon, 16 Nov 2009 21:11:18 +0000 Subject: bla git-svn-id: http://xapek.org/svn/common/omegle@1453 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- icq_roombot.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 15 deletions(-) diff --git a/icq_roombot.py b/icq_roombot.py index c2a07fb..1cba8f9 100644 --- a/icq_roombot.py +++ b/icq_roombot.py @@ -1,12 +1,14 @@ #!/usr/bin/python -import struct +import struct,sys +from twisted.python import log from twisted.words.protocols import oscar from twisted.internet import reactor, protocol from random import randint uin = '370496181' password = 'megahal123' +host, port = ('login.oscar.aol.com', 5190) class Member(object): def __init__(self,id,name): @@ -47,6 +49,10 @@ class Room(object): CAP_TYPING = '\x56\x3f\xc8\x09\x0b\x6f\x41\xbd\x9f\x79\x42\x26\x09\xdf\xa2\xf3' class icqBot( oscar.BOSConnection ): capabilities = [oscar.CAP_CHAT,CAP_TYPING] + + def __init__(self,*args,**kwargs): + print "__INI",args,kwargs + oscar.BOSConnection.__init__(self,*args,**kwargs) def initDone( self ): self.requestSelfInfo() @@ -104,28 +110,43 @@ class icqBot( oscar.BOSConnection ): self.sendMessage(user.name, 'You left') for otherMember in self.room.members: self.sendMessage(otherMember.id, "===== %s/%s left"%(member.name,member.id) ) - elif message.strip() == "/invite": - self.sendMessage(member.id, "===== geht nicht") - elif message.strip() == "/nick": - member.name = message.strip().split("/nick")[1] - elif message.strip() == "/msg": - self.sendMessage(member.id, "===== geht nicht") + elif message.strip().startswith("/invite"): + otherUin = message.strip().split("/invite")[1].strip() + self.sendMessage(otherUin, "Youre invited by %s to join this room!, Type \" /join nickname\""%(user.name)) + self.sendMessage(member.id, "Invitation sent to %s"%otherUin) + elif message.strip().startswith("/nick"): + newNick = message.strip().split("/nick")[1] + for otherMember in self.room.members: + self.sendMessage(otherMember.id, "===== %s now known as %s" % (member.name,newNick)) + member.name = newNick + elif message.strip().startswith("/msg"): + otherNick = message.strip().split("/msg")[1].strip().split(" ")[0] + otherMember = filter(lambda m: m.name == otherNick, self.room.members) + if len(otherMember) == 0: + self.sendMessage(member.id, "===== Nick %s gibts nicht!" % otherNick) + else: + self.sendMessage(otherMember[0].id, "=== Privat von %s/%s: %s" % (member.name,member.id,message)) elif message.strip() == "/list": self.sendMessage(member.id, "===== List: %s"%", ".join(map(lambda m: "%s/%s"%(m.id,m.name),self.room.members)) ) elif message.strip().startswith("/"): self.sendMessage(member.id, "===== kennich nicht") else: + i=0 for otherMember in self.room.members: + i += 1 if otherMember.id == user.name: continue - self.sendMessage(otherMember.id, message.strip()) + reactor.callLater(i, self.sendMessage, otherMember.id, "%s: %s" %(member.name, message.strip())) else: if message.strip().startswith("/join"): - nick = "%s/%s"%(message.strip().split("/join")[1],user.name) + nick = message.strip().split("/join")[1].strip() member = Member(user.name, nick) self.room.join(member) + i=0 for otherMember in self.room.members: - self.sendMessage(otherMember.id, "===== %s/%s joined" % (member.name,member.id)) + i += 1 + reactor.callLater(i, self.sendMessage, otherMember.id, "===== %s/%s joined" % (member.name,member.id)) +# self.sendMessage(otherMember.id, "===== %s/%s joined" % (member.name,member.id)) else: if randint(0,5) == 3: self.sendMessage(user.name, "Use '/join Nickname' or ' /join Nickname'") @@ -155,13 +176,49 @@ class icqBot( oscar.BOSConnection ): print "Connection lost" oscar.BOSConnection.connectionLost(self,*args,**kwargs) - +class ReconnectingOSCARFactory(protocol.ClientFactory): + delay = 10.0 + protocol = icqBot + def __init__(self, un, cookie): + self.un = un + self.cookie = cookie -class OscarCrap( oscar.OscarAuthenticator ): - BOSClass = icqBot + def buildProtocol(self, addr): + p = self.protocol(self.un, self.cookie) + p.factory = self + return p + def clientConnectionLost(self, connector, reason): + reactor.callLater(self.delay, self._reconnect) -protocol.ClientCreator( reactor, OscarCrap, uin, password, icq=1 ).connectTCP( 'login.icq.com', 5238 ) -reactor.run() + def _reconnect(self): + f = ReconnectingOSCARLoginFactory(uin, password) + return reactor.connectTCP(host, port, f) + +class OscarCrap( oscar.OscarAuthenticator ): + BOSClass = icqBot + connectfactory = ReconnectingOSCARFactory + def connectToBOS(self, server, port): + f = self.connectfactory(self.username, self.cookie) + return reactor.connectTCP(server, int(port), f) + +class ReconnectingOSCARLoginFactory(protocol.ReconnectingClientFactory): + protocol = OscarCrap + def __init__(self, sn, pass_): + self.sn = sn + self.pass_ = pass_ + def buildProtocol(self, addr): + p = self.protocol(self.sn, self.pass_, icq=1) + p.factory = self + return p + ## only reconnect on *failures* + def clientConnectionLost(self, con, reason): + pass + +if __name__ == '__main__': + log.startLogging(sys.stdout) + f = ReconnectingOSCARLoginFactory(uin, password) + reactor.connectTCP(host, port, f) + reactor.run() -- cgit v1.2.1