From 5c98da7b1a8e0b965451c148300c556181489b5b Mon Sep 17 00:00:00 2001 From: Matthew Harrison Date: Mon, 25 Jan 2010 22:27:26 -0500 Subject: [PATCH] newest --- modules/markov/markov.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/markov/markov.py b/modules/markov/markov.py index 0253c30..7091646 100644 --- a/modules/markov/markov.py +++ b/modules/markov/markov.py @@ -56,6 +56,7 @@ def markov_stats(c,list,bot): #loads in a previously pickled saved state def markov_load(c,list,bot): global statetab + global lock cmd = list[4].split(" ")[0] @@ -63,8 +64,10 @@ def markov_load(c,list,bot): fp = list[4].split(" ")[1] try: + lock.acquire() pkfile = open(fp,"r") statetab = pickle.load(pkfile) + lock.release() except IOError: print "Could not load db: Doesn't exist\n" @@ -90,10 +93,13 @@ def markov_dump(c,list,bot): def markov_learn(c,list,bot): """ Should not be called directly """ global lock - + + cmd = list[4].split(" ")[0] + if cmd == "talk" or cmd == "markov_stats" or cmd == "mkload" or cmd == "mkdump": + return lock.acquire() - words = [x for x in list[4].split(" ") if not x.isspace()] + words = [x.lower().strip() for x in list[4].split(" ") if not x.isspace()] global statetab global w1 @@ -151,7 +157,7 @@ def emit_chain(key): while 1: try: - newword = random.choice(statetab[(w1,w2)]) + newword = random.choice(statetab[(w1,w2)]).strip() except KeyError: return retval @@ -173,7 +179,7 @@ def markov_talk(c,list,bot): cmd = list[4].split(" ")[0] try: - key = list[4].split(" ")[1] + key = list[4].split(" ")[1].lower() except IndexError: key = " " @@ -182,7 +188,7 @@ def markov_talk(c,list,bot): if len(tmp) <= 2: return last = tmp - c.privmsg(list[5],"%s" % tmp) + c.privmsg(list[5],"%s %s" % (key, tmp)) -- 2.11.4.GIT