diff options
author | Voker57 <voker57@gmail.com> | 2009-12-12 21:35:34 +0300 |
---|---|---|
committer | Voker57 <voker57@gmail.com> | 2010-01-26 00:15:58 +0300 |
commit | 87a5a794b0ca272c93ff7bb1770fe250d35f4121 (patch) | |
tree | d3a0106807274ae0c9e665d297c59525193b0c9a /data/rbot/plugins/markov.rb | |
parent | f244e66650f76559232cbbdc2a336c546f87e7ab (diff) |
markov: made delay an option, fixed non-replied status
Diffstat (limited to 'data/rbot/plugins/markov.rb')
-rwxr-xr-x | data/rbot/plugins/markov.rb | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/data/rbot/plugins/markov.rb b/data/rbot/plugins/markov.rb index c2ef3a96..fdaa1c45 100755 --- a/data/rbot/plugins/markov.rb +++ b/data/rbot/plugins/markov.rb @@ -28,6 +28,10 @@ class MarkovPlugin < Plugin :default => 0.5, :validate => Proc.new { |v| v >= 0 }, :desc => "Time the learning thread spends sleeping after learning a line. If set to zero, learning from files can be very CPU intensive, but also faster.") + Config.register Config::IntegerValue.new('markov.delay', + :default => true, + :validate => Proc.new { |v| v >= 0 }, + :desc => "Wait short time before contributing to conversation.") MARKER = :"\r\n" @@ -323,6 +327,8 @@ class MarkovPlugin < Plugin topic, subtopic = topic.split case topic + when "delay" + "markov delay <value> => Set message delay" when "ignore" case subtopic when "add" @@ -346,7 +352,7 @@ class MarkovPlugin < Plugin "markov chat => try to say something intelligent" end else - "markov plugin: listens to chat to build a markov chain, with which it can (perhaps) attempt to (inanely) contribute to 'discussion'. Sort of.. Will get a *lot* better after listening to a lot of chat. Usage: 'chat' to attempt to say something relevant to the last line of chat, if it can -- help topics: ignore, status, probability, chat, chat about" + "markov plugin: listens to chat to build a markov chain, with which it can (perhaps) attempt to (inanely) contribute to 'discussion'. Sort of.. Will get a *lot* better after listening to a lot of chat. Usage: 'chat' to attempt to say something relevant to the last line of chat, if it can -- help topics: ignore, readonly, delay, status, probability, chat, chat about" end end @@ -441,8 +447,27 @@ class MarkovPlugin < Plugin return false end - def delay - 1 + rand(5) + def set_delay(m, params) + if params[:delay] == "off" + @bot.config["markov.delay"] = 0 + m.okay + elsif !params[:delay] + m.reply _("Message delay is %{delay}" % { :delay => @bot.config["markov.delay"]}) + else + @bot.config["markov.delay"] = params[:delay].to_i + m.okay + end + end + + def reply_delay(m, line) + m.replied = true + if @bot.config['markov.delay'] > 0 + @bot.timer.add_once(@bot.config['markov.delay']) { + m.reply line, :nick => false, :to => :public + } + else + m.reply line, :nick => false, :to => :public + end end def random_markov(m, message) @@ -455,9 +480,7 @@ class MarkovPlugin < Plugin # 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, :nick => false, :to => :public - } + reply_delay m, line end def chat(m, params) @@ -599,6 +622,8 @@ class MarkovPlugin < Plugin end plugin = MarkovPlugin.new +plugin.map 'markov delay :delay', :action => "set_delay" +plugin.map 'markov delay', :action => "set_delay" plugin.map 'markov ignore :action :option', :action => "ignore" plugin.map 'markov ignore :action', :action => "ignore" plugin.map 'markov ignore', :action => "ignore" |