summaryrefslogtreecommitdiff
path: root/megahal_bot.py
diff options
context:
space:
mode:
authoryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-06-10 08:17:19 +0000
committeryvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd>2009-06-10 08:17:19 +0000
commitc6bb1110cbe9b2a9e9b31c5fc66e1e5c7aa5deba (patch)
tree99a4f40bd3df9c79bd23a7a2850144932bb96a24 /megahal_bot.py
parent7279c2ba6e9ad29a8e635c21d5549b21d7b8c461 (diff)
downloadomegle-c6bb1110cbe9b2a9e9b31c5fc66e1e5c7aa5deba.tar.gz
omegle-c6bb1110cbe9b2a9e9b31c5fc66e1e5c7aa5deba.zip
ibo
git-svn-id: http://xapek.org/svn/common/omegle@1098 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
Diffstat (limited to 'megahal_bot.py')
-rw-r--r--megahal_bot.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/megahal_bot.py b/megahal_bot.py
new file mode 100644
index 0000000..5bb686c
--- /dev/null
+++ b/megahal_bot.py
@@ -0,0 +1,114 @@
+import logging
+from threading import Event
+
+import mh_python
+import pyPgSQL.PgSQL
+from omegle import OmegleChat
+
+
+
+class MegahalBot(OmegleChat):
+ def __init__(self,disconnect_event,name,ma_host="omegle.com",color=0):
+ self.disconnect_event = disconnect_event
+ self.name=name
+ self.color = 0
+ OmegleChat.__init__(self,name="Megahal",host=ma_host)
+ self.idlecount = 0
+
+
+ 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 respond(self,message):
+ r=mh_python.doreply(message)
+ print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, r),bold=True)
+ self.send(r)
+
+ def on_idle(self,partner):
+ self.idlecount += 1
+ if self.idlecount > 8:
+ self.logger.info("Idle > 8. disconnect()")
+ self.disconnect()
+ else:
+ self.logger.info("Idle count %s/8" % self.idlecount)
+ def on_message(self,message):
+ self.idlecount = 0
+ print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), "Stranger", message),bold=True)
+ self.respond(message)
+
+ def on_connect(self):
+ print self.c("%s [EVT] %s Connection confirmed" % (time.strftime("%H:%M:%S"), self.name))
+
+
+ def on_disconnect(self):
+ print self.c("%s [EVT] %s disconnect" % (time.strftime("%H:%M:%S"), self.name))
+ self.disconnect_event.set()
+
+
+
+if __name__ == "__main__":
+ colors = {"default":0, "black":30, "red":31, "green":32, "yellow":33,
+ "blue":34,"magenta":35, "cyan":36, "white":37, "black":38, "black":39}
+ mh_python.initbrain()
+ conn = pyPgSQL.PgSQL.connect("")
+
+ cur = conn.cursor()
+ cur.execute("SELECT message FROM omegle_messages")
+ messages = cur.fetchall()
+ 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])
+
+ print ""
+ cur.close()
+ conn.close()
+
+ logging.basicConfig(level=logging.DEBUG)
+ print "press ctrl-c to abort"
+
+ event = Event()
+ bot=MegahalBot(event,"A",ma_host="localhost:8082",color=colors['red'])
+
+ bot.start()
+
+ try:
+ while True:
+ event.wait(0.5)
+ if event.isSet():
+ print "partner"
+ break
+ except KeyboardInterrupt:
+ print "CTRL-C pressed, exiting"
+
+ if bot.is_connected: bot.disconnect()
+
+
+
+mh_python.initbrain()
+conn = pyPgSQL.PgSQL.connect("")
+
+cur = conn.cursor()
+cur.execute("SELECT message FROM omegle_messages")
+messages = cur.fetchall()
+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])
+
+print ""
+cur.close()
+conn.close()
+import sys
+while True:
+ print ">>> ",
+ x=sys.stdin.readline().strip()
+ print "<<< %s " % mh_python.doreply(x)