From 73be154bcffb5039995fdf66a2ff71be6c4e25d6 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 5 Jan 2007 15:51:33 +0000 Subject: More keywords fixes --- data/rbot/plugins/keywords.rb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/data/rbot/plugins/keywords.rb b/data/rbot/plugins/keywords.rb index 7aa5b974..0c1b3526 100644 --- a/data/rbot/plugins/keywords.rb +++ b/data/rbot/plugins/keywords.rb @@ -285,20 +285,27 @@ class Keywords < Plugin debug "got keyword command #{lhs}, #{mhs}, #{rhs}" return if lhs.strip.empty? + overwrite = false + overwrite = true if(lhs.gsub!(/^no,\s*/, "")) + also = false also = true if(rhs.gsub!(/^also\s+/, "")) values = rhs.split(/\s+\|\s+/) lhs = Keyword.unescape lhs - if(also && has_key?(lhs)) + if(overwrite || also || !has_key?(lhs)) + if(also && has_key?(lhs)) + kw = self[lhs] + kw << values + @keywords[lhs] = kw.dump + else + @keywords[lhs] = Keyword.new(mhs, values).dump + end + m.okay if !quiet + elsif(has_key?(lhs)) kw = self[lhs] - kw << values - @keywords[lhs] = kw.dump - else - @keywords[lhs] = Keyword.new(mhs, values).dump + m.reply "but #{lhs} #{kw.type} #{kw.desc}" if kw && !quiet end - - @bot.okay m.target if !quiet end # return help string for Keywords with option topic +topic+ @@ -335,6 +342,8 @@ class Keywords < Plugin 'forget => forget a keyword' when "tell" 'tell about => tell somebody about a keyword' + when "learn" + 'learn that is/are => define a keyword, definition can contain "|" to separate multiple randomly chosen replies' else 'keyword module (fact learning and regurgitation) topics: lookup, set, forget, tell, search, listen, address, , , , ' end @@ -471,6 +480,12 @@ class Keywords < Plugin else m.reply "wrong 'tell' syntax" end + when "learn" + if m.params =~ /^that\s+(.+?)\s+(is|are)\s+(.+)$/ + keyword_command(m, $1, $2, $3) if @bot.auth.allow?('keycmd', m.source, m.replyto) + else + m.reply "wrong 'learn' syntax" + end end end @@ -492,4 +507,5 @@ plugin = Keywords.new plugin.register 'keyword' plugin.register 'forget' plugin.register 'tell' +plugin.register 'learn' -- cgit v1.2.3