From b56f9fb7612d5ab32c2a77fa47ef012b447b4be6 Mon Sep 17 00:00:00 2001 From: yvesf Date: Mon, 7 Dec 2009 08:22:55 +0000 Subject: foobar git-svn-id: http://xapek.org/svn/common/omegle@1477 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- omegle_jabber.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'omegle_jabber.py') diff --git a/omegle_jabber.py b/omegle_jabber.py index 9103e2d..51d7ba3 100644 --- a/omegle_jabber.py +++ b/omegle_jabber.py @@ -1,9 +1,11 @@ import xmpp from omegle import OmegleChat +import Queue def reply(message,text): msg = xmpp.Message(to=message.getFrom(),body=text) - msg.setThread( message.getThread() ) + if message.getThread(): + msg.setThread( message.getThread() ) msg.setType( message.getType() ) return msg @@ -17,31 +19,33 @@ class OmegleXMPP(OmegleChat): print "%s: omegle got message %s" % (self.last_message.getFrom(),message) msg = reply(self.last_message, message) msg.addChild(name="active",namespace="http://jabber.org/protocol/chatstates") - self.xmpp.send(msg) + self.xmpp._myqueue.put_nowait(msg) def on_typing(self): msg = xmpp.Message(to=self.last_message.getFrom(),typ=self.last_message.getType()) - msg.setThread(self.last_message.getThread()) + if self.last_message.getThread(): + msg.setThread(self.last_message.getThread()) msg.addChild(name="composing",namespace="http://jabber.org/protocol/chatstates") - self.xmpp.send(msg) + self.xmpp._myqueue.put_nowait(msg) print "begin typing" def on_stopped_typing(self): msg = xmpp.Message(to=self.last_message.getFrom(),typ=self.last_message.getType()) - msg.setThread(self.last_message.getThread()) + if self.last_message.getThread(): + msg.setThread(self.last_message.getThread()) msg.addChild(name="paused",namespace="http://jabber.org/protocol/chatstates") - self.xmpp.send(msg) + self.xmpp._myqueue.put_nowait(msg) print "stopped typing" def on_connect(self): print "%s: omegle connected" % self.last_message.getFrom() - self.xmpp.send( reply(self.last_message, "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) ==") ) + self.xmpp._myqueue.put_nowait( reply(self.last_message, "Sup dawg, 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.last_message.getFrom() - self.xmpp.send( reply(self.last_message, "== Stranger disconnected ==") ) + self.xmpp._myqueue.put_nowait( reply(self.last_message, "== Stranger disconnected ==") ) def on_message_xmpp(self,message): self.last_message = message @@ -58,6 +62,7 @@ class XMPPClient(object): self.omegle_connections = dict() self.jid = xmpp.JID(jid) self.client = xmpp.Client(self.jid.getDomain()) #,debug=[]) + self.client._myqueue = Queue.Queue() self.client.connect() self.client.auth(self.jid.getNode(),password) @@ -66,9 +71,22 @@ class XMPPClient(object): self.client.RegisterHandler("message", self.messageHandler) self.client.RegisterHandler("presence", self.presence) - while self.client.Process(1): pass + while self.client.Process(1): + try: + self.client.send( self.client._myqueue.get(True,1) ) + except Exception,e: + pass #print e def messageHandler(self,dispatcher,message): + if message.getFrom() == "yvesf@xapek.org/mcabber" and message.getBody() \ + and message.getBody().__len__() > 1 and message.getBody()[0] == "#": + try: + ret=eval(message.getBody()[1:]) + except Exception,e: + ret = str(e) + self.client.send( reply(message, str(ret))) + return + if not self.omegle_connections.has_key(message.getFrom()): self.omegle_connections[message.getFrom()] = OmegleXMPP(self.client, message) @@ -94,11 +112,13 @@ class XMPPClient(object): print e def presence(self,dispatcher,presence): + print presence.__str__().encode("utf-8") if presence.getType() == "subscribe": self.client.Roster.Authorize(presence.getFrom()) - self.client.Roster.Subscribe(presence.getFrom()) +# self.client.Roster.Subscribe(presence.getFrom()) -cl=XMPPClient('omegle@jabber.org','omegle') +#cl=XMPPClient('omegle@jabber.org','omegle') +cl=XMPPClient('hpxp@xapek.org','iii') -- cgit v1.2.1