summaryrefslogtreecommitdiff
path: root/proxy.py
blob: 1711198863693faaaf8698b002a77b5d567d7cc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from omegle import OmegleChat
import sys, logging, time
from threading import Lock
colors = {"default":0, "black":30, "red":31, "green":32, "yellow":33,
          "blue":34,"magenta":35, "cyan":36, "white":37, "black":38,
          "black":39} #33[%colors%m
#        color_string = "\033[%dm\033[1m" % colors[color]


chat_lock = Lock()

class OmegleProxyChat(OmegleChat):
	def __init__(self,name,color=0):
		OmegleChat.__init__(self)
		self.name = name
		self.color = color
	def c(self,str,bold=False):
		if bold:
			return "\033[1m\033[%sm%s\033[0m\033[0m" %(self.color, str)
		else:
			return "\033[%sm%s\033[0m" %(self.color, str)

	def set_partner(self,partner):
		self.partner = partner

	def on_message(self,message):
		print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, message),bold=True)
		if self.partner.is_connected:
			self.partner.send(message)
	def on_connect(self):
		print self.c("%s [EVT] %s Connection confirmed" % (time.strftime("%H:%M:%S"), self.name))
	def on_typing(self):
		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("%s [EVT] %s stopped typing" % (time.strftime("%H:%M:%S"), self.name))
		self.partner.stopped_typing()
	def on_disconnect(self):
		print self.c("%s [EVT] %s disconnect" % (time.strftime("%H:%M:%S"), self.name))
		chat_lock.release()

logging.basicConfig(level=logging.DEBUG)

print "press ctrl-c to abort"
A=OmegleProxyChat("A",colors['red'])
B=OmegleProxyChat("B",colors['blue'])

A.set_partner(B)
B.set_partner(A)

A.start()
B.start()

chat_lock.acquire()
try:
	while True:
		if chat_lock.acquire(0):
			break
		else:
			time.sleep(0.5)
except KeyboardInterrupt:
	pass

if A.is_connected: A.disconnect()
if B.is_connected: B.disconnect()