diff options
-rw-r--r-- | omegle.py | 11 | ||||
-rw-r--r-- | proxy.py | 17 |
2 files changed, 17 insertions, 11 deletions
@@ -40,6 +40,7 @@ class OmegleChat(object): self.timer = Timer(self.events, poll_interval) self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__) + self.is_connected = False def start(self): self.conn_lock.acquire() @@ -68,7 +69,9 @@ class OmegleChat(object): r = self.conn.getresponse() self.conn_lock.release() body = r.read() - if body != "win": + if body == "win": + self.is_connected = False + else: raise Exception("/disconnect; Bad response: %s" % body) def events(self): @@ -136,14 +139,16 @@ class OmegleChat(object): elif data[0] == "gotMessage" and data.__len__() == 2: self.on_message(data[1]) elif data[0] == "connected": + self.is_connected = True self.on_connect() elif data[0] == "strangerDisconnected": + self.is_connected = False self.timer.stop() self.on_disconnect() elif data[0] == "stoppedTyping": self.on_stopped_typing() elif data[0] == "waiting": - pass #unhandled + self.on_wait() else: self.logger.error("Unknown JSON Data: %s" % body) except json.ReadException: @@ -159,6 +164,8 @@ class OmegleChat(object): self.logger.info("Stranger stopped typing") def on_disconnect(self): self.logger.info("Stranger Disconnectet") + def on_wait(self): + self.logger.info("Server sent [\"waiting\"]") if __name__ == "__main__": @@ -1,5 +1,5 @@ from omegle import OmegleChat -import sys, logging +import sys, logging, time colors = {"default":0, "black":30, "red":31, "green":32, "yellow":33, "blue":34,"magenta":35, "cyan":36, "white":37, "black":38, @@ -21,19 +21,18 @@ class OmegleProxyChat(OmegleChat): self.partner = partner def on_message(self,message): - print self.c("[MSG] %s: %s" %(self.name, message),bold=True) + print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, message),bold=True) self.partner.send(message) def on_connect(self): - print self.c("[EVT] %s Connection confirmed" % self.name) + print self.c("%s [EVT] %s Connection confirmed" % (time.strftime("%H:%M:%S"), self.name)) def on_typing(self): - print self.c("[EVT] %s is typing" % self.name) + print self.c("%s [EVT] %s is typing" % (time.strftime("%H:%M:%S"), self.name)) self.partner.typing() def on_stopped_typing(self): - print self.c("[EVT] %s stopped typing" % self.name) + print self.c("%s [EVT] %s stopped typing" % (time.strftime("%H:%M:%S"), self.name)) self.partner.stopped_typing() def on_disconnect(self): - print self.c("[EVT] %s disconnect" % self.name) - self.partner.disconnect() + print self.c("%s [EVT] %s disconnect" % (time.strftime("%H:%M:%S"), self.name)) logging.basicConfig(level=logging.DEBUG) @@ -52,8 +51,8 @@ try: except KeyboardInterrupt: pass -A.disconnect() -B.disconnect() +if A.is_connected: A.disconnect() +if B.is_connected: B.disconnect() |