#!/usr/bin/python import struct import sys import thread from twisted.words.protocols import oscar from twisted.internet import reactor, protocol from twisted.python import log from omegle import OmegleChat # TEST RUN randoms = [['370496181', 'megahal123'], ['446323989','gagaga']] i=1 uin = randoms[i][0] password = randoms[i][1] class OmegleICQChat(OmegleChat): def __init__(self,icqconn,user): self.user = user self.icqconn = icqconn OmegleChat.__init__(self,name="("+user+")") def on_message(self,message): print "%s: omegle got message %s" % (self.user,message) self.send_icqconn( message ) def send_icqconn(self,message): print "%s: send to icq %s" % (self.user,message) #send stopped typing snac reactor.callFromThread(self.icqconn.sendSNAC, 0x04, 0x14, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'+chr(len(self.user))+self.user+"\x00\x00") message = message.decode("utf-8") message = message.encode("iso-8859-1") reactor.callFromThread(self.icqconn.sendMessage, self.user, message ) def on_typing(self): """ 0x02 begin 0x01 idle 0x00 finish """ reactor.callFromThread(self.icqconn.sendSNAC, 0x04, 0x14, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'+chr(len(self.user))+self.user+"\x00\x02") print "begin typing" def on_stopped_typing(self): reactor.callFromThread(self.icqconn.sendSNAC, 0x04, 0x14, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'+chr(len(self.user))+self.user+"\x00\x01") def on_connect(self): print "%s: omegle connected" % self.user self.send_icqconn( "== Sup dawg, we heard u like to meet strangers so we put a Stranger in ur chat so u can chat while u chat (until you type \"disconnect\" without quotes) ==" ) def on_disconnect(self): print "%s: omegle disconnecteed" % self.user self.send_icqconn( "==Stranger Disconnected ==" ) CAP_TYPING = '\x56\x3f\xc8\x09\x0b\x6f\x41\xbd\x9f\x79\x42\x26\x09\xdf\xa2\xf3' # [4, 20, 0, 0, 2854066430L, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02'] class icqBot( oscar.BOSConnection ): capabilities = [oscar.CAP_CHAT,CAP_TYPING] def __init__(self,s,p,factory,**kwargs): self.factory = factory oscar.BOSConnection.__init__(self, s, p,**kwargs) def oscar_04_14(self,snac): data = snac[3] if len(data) == len("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02"): user = data[11:20] state = data[20:22] if not self.omegleConns.has_key(user): self.omegleConns[user] = OmegleICQChat(self,user) if state == "\x00\x00": #finish try: self.omegleConns[user].stopped_typing() except: pass elif state == "\x00\x01": #idle pass elif state == "\x00\x02": #begin try: self.omegleConns[user].typing() except: pass else: print "Unknown state in typing snac\nuser %s\ndata %s\nsnac %s\nstate %X%X" % (user,data,snac,state[0],sate[1]) else: print "komisches tpying snac" def initDone( self ): self.requestSelfInfo() self.requestSSI().addCallback(self.gotBuddyList) self.omegleConns = {} def shutdown( self ): for conn in self.omegleConns: if conn.is_connected: conn.disconnect() def updateBuddy(self, user): print "Update buddy %s" % user def gotBuddyList( self, buddylist ): self.activateSSI() self.setProfile("Forget ICQ, MSN, Yahoo and the other shitty protocols! Use XMPP/Jabber!") self.setIdleTime( 0 ) self.clientReady() for user in buddylist[0][0].users: print "Authorize %s" % user.name self.sendAuthorizationResponse(user.name, True, '') print 'ICQ-Autoresponder-Bot aktiviert ;-)' def receiveMessage( self, user, multiparts, flags ): print "receiveMessage(%s,%s,%s)" % (user,multiparts,flags) if "auto" in flags: print "'auto' message, abort" return self.sendAuthorizationResponse(user.name, True, '') if not self.omegleConns.has_key(user.name): self.omegleConns[user.name] = OmegleICQChat(self,user.name) try: message = str(multiparts[0][0]) if not self.omegleConns[user.name].is_connected: if message == "connect": self.omegleConns[user.name].start() self.sendMessage(user.name, "Please stand by.....") else: self.sendMessage(user.name, "Not connected, type >connect<") elif self.omegleConns[user.name].is_connected and message == "disconnect": try: self.omegleConns[user.name].disconnect() except Exception,e: self.sendMessage(user.name, str(e)) self.sendMessage(user.name, "Disconnecting") elif self.omegleConns[user.name].is_connected and not self.omegleConns[user.name].is_confirmed: self.sendMessage(user.name, "Wait for connection confirm from omegle") else: if len(multiparts[0]) == 2: print "send to omegle: %s" % message.decode(multiparts[0][1]) self.omegleConns[user.name].send(message.decode(multiparts[0][1])) else: print "send to omegle: %s" % message self.omegleConns[user.name].send(message) except Exception,e: print "error: %s %s -> %s" % (user,multiparts,e) def chatReceiveMessage( self, chat, user, message ): self.receiveMessage( self, user, message, 0 ) def sendAuthorizationResponse(self, uin, success, responsString): packet = struct.pack("b", len(uin)) + uin if success: packet += struct.pack("b", 1) else: packet += struct.pack("b", 0) packet += struct.pack(">H", len(responsString)) + responsString self.sendSNACnr(0x13, 0x1a, packet) def connectionLost(self,reason): print reason class OscarCrap( oscar.OscarAuthenticator ): BOSClass = icqBot # override this to connect our factory to our clients def connectToBOS(self, server, port): c = protocol.ClientCreator(reactor, OscarCrap.BOSClass, self.username, self.cookie, self.factory) return c.connectTCP(server, port) from twisted.internet.protocol import Protocol, ReconnectingClientFactory, ClientFactory class OscarFactory(ClientFactory): OAClass=OscarCrap def __init__(self, uid,password,icq=1): self.uid = uid self.password = password self.icq = icq def buildProtocol(self, addr): p = OscarFactory.OAClass(self.uid,password,icq=self.icq) p.factory = self return p def startedConnecting(self, connector): print 'Started to connect to oscar' def connectionLost(self,reason): print "CONECTION LOST" class OscarClientFactory(ReconnectingClientFactory): def startedConnecting(self, connector): print 'Started to connect.' def buildProtocol(self, addr): print 'Connected.' print 'Resetting reconnection delay' self.resetDelay() #return protocol.ClientCreator( reactor, OscarCrap, uin, password, icq=1 ) p=OscarCrap(uin, password, icq=1 ) p.factory = self return p def clientConnectionLost(self, connector, reason): print 'Lost connection. Reason:', reason # ReconnectingClientFactory.clientConnectionLost(self, connector, reason) def clientConnectionFailed(self, connector, reason): print 'Connection failed. Reason:', reason # ReconnectingClientFactory.clientConnectionFailed(self, connector, # reason) log.startLogging(sys.stdout) #protocol.ClientCreator( reactor, OscarCrap, uin, password, icq=1 ).connectTCP( 'login.icq.com', 5238 ) reactor.connectTCP('login.icq.com', 5238, OscarFactory(uin,password,icq=1)) #.connectTCP( 'login.icq.com', 5238 ) reactor.run()