X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fkeywords.rb;h=97fe4258e862d86b8001a0fa3d413df596deb212;hb=1e841175468b3e0357ab278a226a237fe4d7687e;hp=424df8749d31bc9c290abf1f0d94bc5f893b5fa8;hpb=3082ad5836b0babea7db5cde2eac1f59c3fdd667;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/keywords.rb b/data/rbot/plugins/keywords.rb index 424df874..97fe4258 100644 --- a/data/rbot/plugins/keywords.rb +++ b/data/rbot/plugins/keywords.rb @@ -33,7 +33,10 @@ class Keyword ar = Array.new @values.each { |val| debug "key #{key}, value #{val}" - ar << "%s %s %s" % [key, @type, val] + vals = val.split(" or ") + vals.each { |v| + ar << "%s %s %s" % [key, @type, v] + } } return ar end @@ -98,6 +101,9 @@ class Keywords < Plugin Config.register Config::IntegerValue.new('keyword.search_results', :default => 3, :desc => "How many search results to display at a time") + Config.register Config::ArrayValue.new('keyword.ignore_words', + :default => ["how", "that", "these", "they", "this", "what", "when", "where", "who", "why", "you"], + :desc => "A list of words that the bot should passively ignore.") # create a new KeywordPlugin instance, associated to bot +bot+ def initialize @@ -255,6 +261,11 @@ class Keywords < Plugin return false end + # is +word+ a passively ignored keyword? + def ignored_word?(word) + @bot.config["keyword.ignore_words"].include?(word) + end + # m:: PrivMessage containing message info # key:: key being queried # quiet:: optional, if false, complain if +key+ is not found @@ -440,12 +451,25 @@ class Keywords < Plugin # forget one of the dynamic keywords def keyword_forget(m, key) - if(@keywords.has_key?(key)) - @keywords.delete(key) - @bot.okay m.replyto + if @keywords.delete(key) + m.okay + else + m.reply _("couldn't find keyword %{key}" % { :key => key }) end end + # low-level keyword wipe command for when forget doesn't work + def keyword_wipe(m, key) + reg = @keywords.registry + reg.env.begin(reg) { |t, b| + b.delete_if { |k, v| + (k == key) && (m.reply "wiping keyword #{key} with stored value #{Marshal.restore(v)}") + } + t.commit + } + m.reply "done" + end + # export keywords to factoids file def keyword_factoids_export ar = Array.new @@ -485,6 +509,8 @@ class Keywords < Plugin keyword_command(m, $1, $2, $3) if @bot.auth.allow?('keycmd', m.source, m.replyto) when /^forget\s+(.+)$/ keyword_forget(m, $1) if @bot.auth.allow?('keycmd', m.source, m.replyto) + when /^wipe\s(.+)$/ # note that only one space is stripped, allowing removal of space-prefixed keywords + keyword_wipe(m, $1) if @bot.auth.allow?('keycmd', m.source, m.replyto) when /^lookup\s+(.+)$/ keyword_lookup(m, $1) if @bot.auth.allow?('keyword', m.source, m.replyto) when /^stats\s*$/ @@ -526,10 +552,10 @@ class Keywords < Plugin # TODO option to do if(m.message =~ /^(.*)$/, ie try any line as a # keyword lookup. if m.message =~ /^(.*\S)\s*\?\s*$/ and (m.address? or not @bot.config["keyword.address"]) - keyword_lookup m, $1, true if @bot.auth.allow?("keyword", m.source) + keyword_lookup m, $1, true if !ignored_word?($1) && @bot.auth.allow?("keyword", m.source) elsif @bot.config["keyword.listen"] && (m.message =~ /^(.*?)\s+(is|are)\s+(.*)$/) # TODO MUCH more selective on what's allowed here - keyword_command m, $1, $2, $3, true if @bot.auth.allow?("keycmd", m.source) + keyword_command m, $1, $2, $3, true if !ignored_word?($1) && @bot.auth.allow?("keycmd", m.source) end end end