public
Description: An extensible bot for the Campfire web-based chat system #crc
Homepage:
Clone URL: git://github.com/timriley/campfire-bot.git
properly strip out the 'view paste' lines when priming markov chains; split 
multi-line messages into individual lines and ignore the blank ones
timriley (author)
Fri Oct 31 17:15:19 -0700 2008
commit  1b6de4d3325e4502c73a44d33eada21f1791d6c6
tree    0562d42806e255a82b73247fef58d6cf24762e8c
parent  9077b5a2d50e21ce2fe2f55a7e0eeff2ae52af04
0
...
1
 
 
 
 
 
 
 
2
3
4
...
 
1
2
3
4
5
6
7
8
9
10
0
@@ -1,4 +1,10 @@
0
-- plugins need callbacks, like on_join, etc.
0
+- need to catch timeout errors and do something sensible, like wait and retry the connection
0
+
0
+- need to catch no-network errors and return a sensible error message:
0
+
0
+/opt/local/lib/ruby/1.8/net/http.rb:560:in `initialize': Network is unreachable - connect(2) (Errno::ENETUNREACH)
0
+
0
+- plugins need callbacks, like on_join, bot_loaded, etc.
0
 
0
 - multi-room support
0
 
...
1
2
3
4
 
5
6
7
...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
25
26
27
...
49
50
51
52
53
54
 
 
 
55
56
57
...
115
116
117
118
 
 
 
119
120
121
...
1
2
3
 
4
5
6
7
...
11
12
13
 
 
14
15
16
17
 
 
 
 
 
18
19
20
21
...
43
44
45
 
46
 
47
48
49
50
51
52
...
110
111
112
 
113
114
115
116
117
118
0
@@ -1,7 +1,7 @@
0
 # TODO
0
 #
0
 # - convert/filter out HTML entities like "
0
-# - do the right thing when a paste occurs (remove the 'view paste' but keep the content)
0
+# - add a callback to prime the chains when the bot is ready, and do this in a thread.
0
 
0
 class Boop < CampfireBot::Plugin
0
   
0
@@ -11,17 +11,11 @@ class Boop < CampfireBot::Plugin
0
   on_command 'speak',             :random_chatter
0
   on_command 'prime_chains',      :load_transcripts
0
   
0
-  on_command 'test',              :debug
0
-  
0
   def initialize
0
     @phrases    = Hash.new { |hash, key| hash[key] = [] } # phrase => next-word possibilities
0
     @word_count = 0
0
   end
0
-  
0
-  def debug
0
-    p @phrases
0
-  end
0
-  
0
+
0
   def listen(msg)
0
     add_line(msg[:message])
0
   end
0
@@ -49,9 +43,10 @@ class Boop < CampfireBot::Plugin
0
         puts "message: #{message[:message]}"
0
         
0
         filtered_text = strip_message(message)
0
-        add_line(filtered_text.gsub(/([^\.])$/, '\1.')) unless filtered_text.blank?
0
         
0
-        puts "ACCEPTED: " + filtered_text.gsub(/([^\.])$/, '\1.') unless filtered_text.blank?
0
+        filtered_text.split("\n").each { |line| add_line(line) unless line.blank? }
0
+        filtered_text.split("\n").each { |line| puts "ACCEPTED: " + line unless line.blank? }
0
+        
0
       end
0
     end
0
     
0
@@ -115,7 +110,9 @@ class Boop < CampfireBot::Plugin
0
     
0
     # and get rid of the messages that are generated by the campfire system itself
0
     return '' if str =~ /has (entered|left) the room/
0
-    return '' if str =~ /^View paste/
0
+    
0
+    # keep the contents of the pastes, but strip out the 'view paste' link.
0
+    str.gsub!(/<a href=.*?>View paste<\/a>/, '')
0
     
0
     # also get rid of the stuff spoken by the bot
0
     return '' if msg[:person] == bot.config['nickname']

Comments