X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fmarkov.rb;h=9b83e53a56d0f6b85a1f4558431cb8045a32d331;hb=22e6cefa54de681b131ecb97fc9383ff5e990dfe;hp=bae70263b3d66d98e9ecaf30a32f2f32f5a90243;hpb=0dc4cd15c81a3ae700b23d59550f1825af989b6a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/markov.rb b/data/rbot/plugins/markov.rb index bae70263..9b83e53a 100644 --- a/data/rbot/plugins/markov.rb +++ b/data/rbot/plugins/markov.rb @@ -20,6 +20,10 @@ class MarkovPlugin < Plugin Config.register Config::ArrayValue.new('markov.ignore', :default => [], :desc => "Hostmasks and channel names markov should NOT learn from (e.g. idiot*!*@*, #privchan).") + Config.register Config::IntegerValue.new('markov.max_words', + :default => 50, + :validate => Proc.new { |v| (0..100).include? v }, + :desc => "Maximum number of words the bot should put in a sentence") def initialize super @@ -55,7 +59,7 @@ class MarkovPlugin < Plugin end def generate_string(word1, word2) - # limit to max of 50 words + # limit to max of markov.max_words words output = word1 + " " + word2 # try to avoid :nonword in the first iteration @@ -67,7 +71,7 @@ class MarkovPlugin < Plugin word1, word2 = word2, word3 end - 49.times do + (@bot.config['markov.max_words'] - 1).times do wordlist = @registry["#{word1} #{word2}"] break if wordlist.empty? word3 = wordlist[rand(wordlist.length)] @@ -179,7 +183,9 @@ class MarkovPlugin < Plugin return unless word1 and word2 line = generate_string(word1, word2) return unless line - return if line == message + # we do nothing if the line we return is just an initial substring + # of the line we received + return if message.index(line) == 0 @bot.timer.add_once(delay) { m.reply line }