From 09fa481b3181129d4acb02a969abd08ffa753025 Mon Sep 17 00:00:00 2001 From: yvesf Date: Thu, 11 Jun 2009 10:25:13 +0000 Subject: ibla git-svn-id: http://xapek.org/svn/common/omegle@1108 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- megahal_bot.py | 73 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 25 deletions(-) (limited to 'megahal_bot.py') 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" -- cgit v1.2.1