1 #markov module for scrappy
3 #the inspiration for this code comes from
4 #"The Practice of Programming", so some of the variable
5 #names and such will be similar.
14 scrap
.register_msg_event(markov_learn
)
15 scrap
.register_msg_event(markov_talk
)
19 def markov_learn(c
,list,bot
):
20 """ Should not be called directly """
21 words
= list[4].split(" ")
36 statetab
[w1
][w2
] = " "
39 statetab
[w1
][w2
] = " "
41 if random
.randint(0,10) == 0:
42 c
.privmsg(list[5], "%s: %s" % (list[0], emit_chain(" ")))
53 # for i in range(random.randint(1,4)):
54 # for i in range(int(20)):
57 suffix
= statetab
[word1
]
59 word1
= random
.choice(statetab
.keys())
65 t
= random
.choice(suffix
.keys())
67 word1
= random
.choice(statetab
.keys())
68 return "Not enough entropy."
75 retval
= retval
+ suffix
[t
] + " "
79 def markov_talk(c
,list,bot
):
80 """ Makes the markov chain talk to you """
82 cmd
= list[4].split(" ")[0]
85 key
= list[4].split(" ")[1]
89 if list[3] and cmd
== "talk":
90 c
.privmsg(list[5],"%s" % emit_chain(key
))