diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-09-07 21:18:38 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-09-07 21:18:38 +0000 |
commit | 1ad3f697e3e68f933cad0b30d74128ed9d4946ab (patch) | |
tree | 77c64e85afe076ea4ba792f67c3dbc00e4be389f /data/rbot/plugins | |
parent | 8946b90f0efaee6f38a53c5e8db1cb29ba1b398c (diff) |
tweaking the markov plugin a little
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r-- | data/rbot/plugins/markov.rb | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/data/rbot/plugins/markov.rb b/data/rbot/plugins/markov.rb index 1155b207..fc6658d2 100644 --- a/data/rbot/plugins/markov.rb +++ b/data/rbot/plugins/markov.rb @@ -3,9 +3,10 @@ class MarkovPlugin < Plugin super @registry.set_default([]) @lastline = false + @enabled = false end - def markov(m, params) + def get_line # limit to max of 50 words return unless @lastline word1, word2 = @lastline.split(/\s+/) @@ -17,7 +18,11 @@ class MarkovPlugin < Plugin output = output + " " + word3 word1, word2 = word2, word3 end - m.reply output + return output + end + + def markov(m, params) + m.reply get_line end def help(plugin, topic="") @@ -31,6 +36,30 @@ class MarkovPlugin < Plugin return str.strip end + def enable(m, params) + @enabled = true + m.okay + end + + def disable(m, params) + @enabled = false + m.okay + end + + def should_talk + return false unless @enabled + # 50:50 + return false if rand(2) == 1 + return true + end + + def random_markov(m) + return unless should_talk + line = get_line + puts "got line #{line}" + m.reply line unless line == @lastline + end + def listen(m) return unless m.kind_of?(PrivMessage) && m.public? return if m.address? @@ -45,7 +74,10 @@ class MarkovPlugin < Plugin word1, word2 = word2, word3 end @registry["#{word1}/#{word2}"] = [:nonword] + random_markov(m) end end plugin = MarkovPlugin.new +plugin.map 'markov enable', :action => "enable" +plugin.map 'markov disable', :action => "disable" plugin.map 'markov' |