public
Description: An extensible bot for the Campfire web-based chat system #crc
Homepage:
Clone URL: git://github.com/timriley/campfire-bot.git
cleanups and syntax fixes to markov plugin
timriley (author)
Thu Oct 30 23:06:35 -0700 2008
commit  6fce4bfdf4fc27294caa28e9265011719e3f79fe
tree    b511eb452045e78e3a42352b53a2eeb29d8e7950
parent  372567b253437bbc8c55d547bfc143f12c602587
...
13
14
15
 
 
 
 
16
17
18
...
28
29
30
 
31
32
 
33
34
 
35
 
36
37
38
 
39
40
41
42
43
44
45
 
46
47
48
...
66
67
68
69
 
70
71
72
...
81
82
83
 
84
85
86
87
88
 
89
90
91
...
13
14
15
16
17
18
19
20
21
22
...
32
33
34
35
36
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
52
 
53
54
55
56
...
74
75
76
 
77
78
79
80
...
89
90
91
92
93
94
95
96
 
97
98
99
100
0
@@ -13,6 +13,10 @@ class Boop < CampfireBot::Plugin
0
     @word_count = 0
0
   end
0
   
0
+  def debug
0
+    p @phrases
0
+  end
0
+  
0
   def listen(msg)
0
     add_words(msg[:message])
0
   end
0
@@ -28,21 +32,25 @@ class Boop < CampfireBot::Plugin
0
   
0
   def load_transcripts(msg)
0
     speak("Filling my brain with transcripts...")
0
+    
0
     bot.room.available_transcripts.each do |date|
0
       transcript = bot.room.transcript(date)
0
+      
0
       transcript.each do |message|
0
-        filtered_text = strip_messages(message)
0
+        filtered_text = strip_message(message)
0
         add_words(filtered_text.gsub(/([^\.])$/, '\1.')) unless filtered_text.blank?
0
+        
0
         puts filtered_text.gsub(/([^\.])$/, '\1.') unless filtered_text.blank?
0
       end
0
     end
0
+    
0
     speak("Primed!")
0
   end
0
   
0
   private
0
     
0
   def add_line(line)
0
-    words        = line.scan(/\S+/))
0
+    words        = line.scan(/\S+/)
0
     @word_count += words.length
0
     
0
     words.each_with_index do |word, index|
0
@@ -66,7 +74,7 @@ class Boop < CampfireBot::Plugin
0
       output << phrase.shift
0
 
0
       # select at random and add it to our phrase
0
-      phrase.push options[rand(options.length)]
0
+      phrase.push(options.rand)
0
 
0
       # the last phrase of the input text will map to an empty array of
0
       # possibilities so exit cleanly.
0
@@ -81,11 +89,12 @@ class Boop < CampfireBot::Plugin
0
     @phrases.keys.rand.first
0
   end
0
   
0
+  # amount of state (order-k)
0
   def phrase_length
0
     1
0
   end
0
   
0
-  def strip_messages(msg)
0
+  def strip_message(msg)
0
     str = msg[:message].to_s
0
     
0
     return '' if str.blank?

Comments