From 9e6758cda2684d8e77fa138ab81324e29a4c01d9 Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 8 Jul 2009 08:43:14 +0000 Subject: blah git-svn-id: http://xapek.org/svn/common/omegle@1196 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- omegle_jabber.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 omegle_jabber.py (limited to 'omegle_jabber.py') diff --git a/omegle_jabber.py b/omegle_jabber.py new file mode 100644 index 0000000..9103e2d --- /dev/null +++ b/omegle_jabber.py @@ -0,0 +1,105 @@ +import xmpp +from omegle import OmegleChat + +def reply(message,text): + msg = xmpp.Message(to=message.getFrom(),body=text) + msg.setThread( message.getThread() ) + msg.setType( message.getType() ) + return msg + +class OmegleXMPP(OmegleChat): + def __init__(self,xmpp,last_message): + self.xmpp = xmpp + self.last_message = last_message + OmegleChat.__init__(self,name="(%s)"%last_message.getFrom()) + + def on_message(self,message): + 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) + + + def on_typing(self): + msg = xmpp.Message(to=self.last_message.getFrom(),typ=self.last_message.getType()) + msg.setThread(self.last_message.getThread()) + msg.addChild(name="composing",namespace="http://jabber.org/protocol/chatstates") + self.xmpp.send(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()) + msg.addChild(name="paused",namespace="http://jabber.org/protocol/chatstates") + self.xmpp.send(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) ==") ) + + def on_disconnect(self): + print "%s: omegle disconnecteed" % self.last_message.getFrom() + self.xmpp.send( reply(self.last_message, "== Stranger disconnected ==") ) + + def on_message_xmpp(self,message): + self.last_message = message + if message.getBody(): + print "%s: To Omegle: %s" % (self.last_message.getFrom(), self.last_message.getBody()) + self.send(message.getBody()) + elif message.getTag("composing"): + print "composing" + self.typing() + + +class XMPPClient(object): + def __init__(self,jid,password): + self.omegle_connections = dict() + self.jid = xmpp.JID(jid) + self.client = xmpp.Client(self.jid.getDomain()) #,debug=[]) + + self.client.connect() + self.client.auth(self.jid.getNode(),password) + self.client.sendInitPresence() + + self.client.RegisterHandler("message", self.messageHandler) + self.client.RegisterHandler("presence", self.presence) + + while self.client.Process(1): pass + + def messageHandler(self,dispatcher,message): + if not self.omegle_connections.has_key(message.getFrom()): + self.omegle_connections[message.getFrom()] = OmegleXMPP(self.client, message) + + omegle = self.omegle_connections[message.getFrom()] + try: + if not omegle.is_connected: + if message.getBody() == "connect": + omegle.start() + self.client.send( reply(message,"Connecting") ) + else: + self.client.send( reply(message,"Not connected, type >connect<") ) + elif omegle.is_connected and message.getBody() == "disconnect": + self.client.send( reply(message, "Disconnecting") ) + try: + omegle.disconnect() + except Exception,e: + self.client.send( reply(message, str(e)) ) + elif omegle.is_connected and not omegle.is_confirmed: + self.client.send( reply(message, "Establish Connection...") ) + else: + omegle.on_message_xmpp(message) + except Exception,e: + print e + + def presence(self,dispatcher,presence): + if presence.getType() == "subscribe": + self.client.Roster.Authorize(presence.getFrom()) + self.client.Roster.Subscribe(presence.getFrom()) + +cl=XMPPClient('omegle@jabber.org','omegle') + + + + -- cgit v1.2.1