summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--megahal_bot.py73
-rw-r--r--megahal_local.py23
-rw-r--r--omegle.py11
-rw-r--r--proxy.py28
4 files changed, 95 insertions, 40 deletions
diff --git a/megahal_bot.py b/megahal_bot.py
index 5055e45..0db602a 100644
--- a/megahal_bot.py
+++ b/megahal_bot.py
@@ -1,6 +1,7 @@
import logging
import sys
from threading import Event
+import random
import mh_python
import time
@@ -14,7 +15,7 @@ class MegahalBot(OmegleChat):
self.disconnect_event = disconnect_event
self.name=name
self.color = color
- OmegleChat.__init__(self,name="Megahal",host=host)
+ OmegleChat.__init__(self,name=" Megahal",host=host)
self.idlecount = 0
@@ -27,10 +28,14 @@ class MegahalBot(OmegleChat):
return "\033[%sm%s\033[0m" %(self.color, str)
- def respond(self,message):
+ def respond(self,message,prepend=""):
r=mh_python.doreply(message.encode("utf-8"))
- print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, r),bold=True)
- self.send(r) #.decode("utf-8"))
+ print self.c("%s%s [MSG] %s: %s" %(prepend,time.strftime("%H:%M:%S"), self.name, r),bold=True)
+ try:
+ self.send(r) #.decode("utf-8"))
+ except Exception,e:
+ print e
+ self.disconnect_event.set()
def on_idle(self):
self.idlecount += 1
@@ -39,15 +44,23 @@ class MegahalBot(OmegleChat):
self.disconnect()
else:
self.logger.info("Idle count %s/8" % self.idlecount)
+ self.respond("are you there?") #restart the conv.
+
def on_message(self,message):
- print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), "Stranger", message),bold=True,color=32)
+ print self.c("%s%s [MSG] %s: %s" %(
+ "\033[1A\033[2K\033[30D",
+ time.strftime("%H:%M:%S"), "Stranger", message),bold=True,color=32)
self.idlecount = 0
time.sleep(0.05)
- print self.c("%s [EVT] %s: typing" %(time.strftime("%H:%M:%S"), self.name),bold=True,color=32),
- self.typing()
- time.sleep(1.5)
- print "\033[E\033[2K",
- self.respond(message)
+ typestr = "%s [EVT] %s: typing" %(time.strftime("%H:%M:%S"),self.name)
+ print self.c(typestr,bold=True,color=32)
+ try:
+ self.typing()
+ except Exception,e:
+ print e
+ return
+ time.sleep(random.randint(1,3))
+ self.respond(message,prepend="\033[1A\033[2K\033[%sD"%(len(typestr))) #move up 1; delete line; move left %s
def on_connect(self):
print self.c("%s [EVT] %s Connection confirmed" % (time.strftime("%H:%M:%S"), self.name))
@@ -69,24 +82,32 @@ if __name__ == "__main__":
# OR CAST(RANDOM()*10 AS integer) < 6;""" #reduziert kurze sachen
# sql = """SELECT message FROM omegle_messages"""
-
- #Offensive
+ #hmm
sql = """SELECT message FROM omegle_messages
- WHERE ( message ILIKE '%sex%'
- OR message ILIKE '%boob%'
- OR message ILIKE '%horny %'
- OR message ILIKE '%pussy %'
- OR message ILIKE '%ass %'
- OR message ILIKE '%naked%'
- OR message ILIKE '%fuck%'
- OR LENGTH(message) < 7 AND CAST(RANDOM()*10 as integer)=1)
- AND LENGTH(message) < 35
- AND NOT ( message ILIKE '%www%'
- OR message ILIKE '%http%'
- OR message ILIKE '%@%.%')
+ WHERE LENGTH(message) < 35
+ AND NOT ( message ILIKE '%www.%'
+ OR message ILIKE '%http%'
+ OR message ILIKE '%@%.%')
;
"""
+# #Offensive
+# sql = """SELECT message FROM omegle_messages
+# WHERE ( message ILIKE '%sex%'
+# OR message ILIKE '%boob%'
+# OR message ILIKE '%horny %'
+# OR message ILIKE '%pussy %'
+# OR message ILIKE '%ass %'
+# OR message ILIKE '%naked%'
+# OR message ILIKE '%fuck%'
+# OR LENGTH(message) < 7 AND CAST(RANDOM()*10 as integer)=1)
+# AND LENGTH(message) < 35
+# AND NOT ( message ILIKE '%www.%'
+# OR message ILIKE '%http%'
+# OR message ILIKE '%@%.%')
+# ;
+# """
+
# sql = """
#SELECT message
# FROM omegle_messages
@@ -110,10 +131,12 @@ if __name__ == "__main__":
print "%s%s/%s" % ("\033[2K\033[E",c,len(messages)),
#XXX pass massage[0] to mh and end with a fucked up python
mh_python.learn("%s " % (message[0]))
+ mh_python.learn("%s " % (message[0]))
- print ""
+ print "%s%s/%s" % ("\033[2K\033[E",len(messages),len(messages))
cur.close()
conn.close()
+ del messages
logging.basicConfig(level=logging.DEBUG)
print "press ctrl-c to abort"
diff --git a/megahal_local.py b/megahal_local.py
index cb96a0f..b17316f 100644
--- a/megahal_local.py
+++ b/megahal_local.py
@@ -2,20 +2,27 @@ import mh_python
import pyPgSQL.PgSQL
mh_python.initbrain()
-print "\033[2J"
conn = pyPgSQL.PgSQL.connect("")
cur = conn.cursor()
-cur.execute("SELECT message FROM omegle_messages")
-messages = cur.fetchall()
+cur.execute("""
+SELECT message FROM omegle_messages
+WHERE NOT ( message ILIKE '%www.%'
+ OR message ILIKE '%http:%'
+ OR message ILIKE '%@%.%');
+""")
c=0
-for message in messages:
- c+=1
- if c%20==0:
- print "%s%s/%s" % ("\033[2K\033[E",c,len(messages)),
- mh_python.learn(message[0])
+while True:
+ messages = cur.fetchmany(1000)
+ if len(messages)==0:
+ break
+ for message in messages:
+ c+=1
+ if c%50==0:
+ print "%s%s" % ("\033[2K\033[E",c),
+ mh_python.learn("%s"%message[0])
print ""
cur.close()
diff --git a/omegle.py b/omegle.py
index 8aac69e..5520f3f 100644
--- a/omegle.py
+++ b/omegle.py
@@ -1,5 +1,6 @@
import sys
import httplib
+import socket
import urllib
import time
import json
@@ -139,9 +140,15 @@ class OmegleChat(RESTClient):
self.logger.error("Cant send message if not is_confirmed")
return ###XXX raise??
- params = {'ala':'gaga','id':self.id,'msg':msg,'zla2':'gaga2'}
+ params = {'id':self.id,'msg':msg}
params = urllib.urlencode(params)
- r = RESTClient.request(self,"POST","/send",params)
+ try:
+ r = RESTClient.request(self,"POST","/send",params)
+ except Exception,e:
+ self.logger.error("Error by /send request: %s" % e)
+ raise e
+ return
+
body = r.read()
if body != "win":
self.logger.error("/send; Bad response %s" % body)
diff --git a/proxy.py b/proxy.py
index 39c72a4..7faf430 100644
--- a/proxy.py
+++ b/proxy.py
@@ -40,7 +40,16 @@ class OmegleProxyChat(OmegleChat):
self.partner.idlecount = 0
print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, message.encode("utf-8")),bold=True)
if self.partner.is_connected:
- self.partner.send(message)
+ try:
+ self.partner.send(message)
+ except Exception,e:
+ print e
+ try:
+ self.disconnect()
+ except:
+ pass
+ self.disconnect_event.set()
+
def on_connect(self):
print self.c("%s [EVT] %s Connection confirmed" % (time.strftime("%H:%M:%S"), self.name))
@@ -79,8 +88,11 @@ if __name__ == "__main__":
A.set_partner(B)
B.set_partner(A)
- A.start()
- B.start()
+ try:
+ A.start()
+ B.start()
+ except:
+ sys.exit(255)
try:
while True:
@@ -90,6 +102,12 @@ if __name__ == "__main__":
break
except KeyboardInterrupt:
print "CTRL-C pressed, exiting"
+ try:
+ if A.is_connected: A.disconnect()
+ except:
+ pass
- if A.is_connected: A.disconnect()
- if B.is_connected: B.disconnect()
+ try:
+ if B.is_connected: B.disconnect()
+ except:
+ pass