]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
markov: unify should_talk
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 25 Jan 2010 22:11:43 +0000 (23:11 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 25 Jan 2010 22:11:43 +0000 (23:11 +0100)
Unify probability check for addressed and non-addressed case by
passing the message as a parameter to should_talk and picking the
probability accordingly.

data/rbot/plugins/markov.rb

index 282112038235b5b592548adb5d2edd5b7501c08b..ce5a35a2324f9cf93f5fb12c929af90fddafefb8 100755 (executable)
@@ -490,9 +490,9 @@ class MarkovPlugin < Plugin
     m.okay
   end
 
-  def should_talk
+  def should_talk(m)
     return false unless @bot.config['markov.enabled']
-    prob = probability?
+    prob = m.address? ? @bot.config['markov.answer_addressed'] : probability?
     return true if prob > rand(100)
     return false
   end
@@ -531,7 +531,7 @@ class MarkovPlugin < Plugin
   end
 
   def random_markov(m, message)
-    return unless (should_talk or (m.address? and  @bot.config['markov.answer_addressed'] > rand(100)))
+    return unless should_talk(m)
 
     words = clean_str(message).split(/\s+/)
     if words.length < 2