]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Salutation improvements when the bot isn't address
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 26 Jan 2007 14:32:47 +0000 (14:32 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 26 Jan 2007 14:32:47 +0000 (14:32 +0000)
data/rbot/plugins/salut.rb
data/rbot/templates/salut/salut-english
data/rbot/templates/salut/salut-italian

index 857c4df9fcfbec89f40a07618ec5317118d6b852..4582e5549aea4ca936253cc5427b01dc223a1d6a 100644 (file)
@@ -45,12 +45,15 @@ class SalutPlugin < Plugin
 \r
   def create_match\r
     @match = Hash.new\r
+    ar_dest = Array.new\r
     ar_in = Array.new\r
     ar_out = Array.new\r
     ar_both = Array.new\r
     @salutations.each { |lang, hash|\r
       hash.each { |situation, array|\r
         case situation.to_s\r
+        when /^generic-dest$/\r
+          ar_dest += array\r
         when /in$/\r
           ar_in += array\r
         when /out$/\r
@@ -70,23 +73,31 @@ class SalutPlugin < Plugin
       Regexp.escape(txt)\r
     }.join('|') + ")\\b", Regexp::IGNORECASE) unless ar_both.empty?\r
     debug "Matches: #{@match.inspect}"\r
+    @match[:dest] = Regexp.new("\\b(?:" + ar_dest.uniq.map { |txt|\r
+      Regexp.escape(txt)\r
+    }.join('|') + ")\\b", Regexp::IGNORECASE) unless ar_dest.empty?\r
+    @punct = /\s*[.,:!;?]?\s*/ # Punctuation\r
   end\r
 \r
   def listen(m)\r
     return unless m.kind_of?(PrivMessage)\r
+    to_me = m.address? || m.message =~ /#{Regexp.escape(@bot.nick)}/i\r
     if @bot.config['salut.address_only']\r
-      return unless m.address? or m.message =~ /#{Regexp.escape(@bot.nick)}/\r
+      return unless to_me\r
     end\r
     salut = nil\r
     [:both, :in, :out].each { |k|\r
       next unless @match[k]\r
       debug "Checking salutations #{k} (#{@match[k].inspect})"\r
-      if m.message =~ /^#{@match[k]}/\r
+      if m.message =~ @match[k]\r
         salut = k\r
         break\r
       end\r
     }\r
     return unless salut\r
+    # If the bot wasn't addressed, we continue only the match was exact\r
+    # (apart from space and punctuation) or if @match[:dest] matches too\r
+    return unless to_me or m.message =~ @match[:dest] or m.message =~ /^#{@punct}#{@match[salut]}#{@punct}$/\r
     h = Time.new.hour\r
     case h\r
     when 4...12\r
@@ -114,7 +125,7 @@ class SalutPlugin < Plugin
     rep_ar += @salutations[@main_lang].fetch("generic".to_sym, []) unless sfx.empty?\r
     debug "Choosing reply in #{rep_ar.inspect} ..."\r
     if rep_ar.empty?\r
-      if m.public? and (m.address? or m =~ /#{Regexp.escape(@bot.nick)}/)\r
+      if m.public? and (m.address? or m =~ /#{Regexp.escape(@bot.nick)}/)\r
         choice = @bot.lang.get("hello_X") % m.sourcenick\r
       else\r
         choice = @bot.lang.get("hello") % m.sourcenick\r
index 84b5afd1a4848adc0c0d9c576c8e96abd255fa57..85f7098f53c79bc44f54454c180906698dcf809b 100644 (file)
@@ -32,3 +32,9 @@
 - goodevening
 - evening
 - "'evening"
+:"generic-dest"
+- all
+- people
+- everybody
+- y'all
+- bots
index 027bb88f039c016cc97015d9f0c4e5a5a3dd1c84..9e68c602cf4d357f7d9553ea1a18d4faa064fe48 100644 (file)
@@ -2,8 +2,12 @@
 :"generic-in": 
 - salve
 - ehila'
+- ehilà
 - ola'
+- olà
 - yo
+- ue'
+- uè
 :"morning-in": 
 - "'giorno"
 - giorno
 - buonanotte
 :"generic":
 - ciao
+:"generic-dest":
+- gente
+- tutti
+- raga
+- raga'
+- ragà
+- ragazzi
+- ragazze
+- bot
+- bots