summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/markov.rb36
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'