summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-14 12:26:49 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-14 12:26:49 +0000
commitc1f4fae559645487fed3c413b401b3005d960bc5 (patch)
tree3dc1ef6425bb787080d00f03b7d69e1c4bf7eb5a /lib/rbot
parent7b634184a27d3be3d6a664b6622e6d446f54f18d (diff)
Fix for #102
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/keywords.rb65
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/rbot/keywords.rb b/lib/rbot/keywords.rb
index 83185d9f..29eadaac 100644
--- a/lib/rbot/keywords.rb
+++ b/lib/rbot/keywords.rb
@@ -383,38 +383,45 @@ module Irc
full = false
full = true if str.gsub!(/--full\s+/, "")
- re = Regexp.new(str, Regexp::IGNORECASE)
- if(@bot.auth.allow?("keyword", m.source, m.replyto))
- matches = Array.new
- @keywords.each {|k,v|
- kw = Keyword.restore(v)
- if re.match(k) || (full && re.match(kw.desc))
- matches << [k,kw]
+ begin
+ re = Regexp.new(str, Regexp::IGNORECASE)
+ if(@bot.auth.allow?("keyword", m.source, m.replyto))
+ matches = Array.new
+ @keywords.each {|k,v|
+ kw = Keyword.restore(v)
+ if re.match(k) || (full && re.match(kw.desc))
+ matches << [k,kw]
+ end
+ }
+ if all
+ @statickeywords.each {|k,v|
+ v.each {|kk,vv|
+ kw = Keyword.restore(vv)
+ if re.match(kk) || (full && re.match(kw.desc))
+ matches << [kk,kw]
+ end
+ }
+ }
end
- }
- if all
- @statickeywords.each {|k,v|
- v.each {|kk,vv|
- kw = Keyword.restore(vv)
- if re.match(kk) || (full && re.match(kw.desc))
- matches << [kk,kw]
- end
+ if matches.length == 1
+ rkw = matches[0]
+ m.reply "#{rkw[0]} #{rkw[1].type} #{rkw[1].desc}"
+ elsif matches.length > 0
+ i = 0
+ matches.each {|rkw|
+ m.reply "[#{i+1}/#{matches.length}] #{rkw[0]} #{rkw[1].type} #{rkw[1].desc}"
+ i += 1
+ break if i == 3
}
- }
- end
- if matches.length == 1
- rkw = matches[0]
- m.reply "#{rkw[0]} #{rkw[1].type} #{rkw[1].desc}"
- elsif matches.length > 0
- i = 0
- matches.each {|rkw|
- m.reply "[#{i+1}/#{matches.length}] #{rkw[0]} #{rkw[1].type} #{rkw[1].desc}"
- i += 1
- break if i == 3
- }
- else
- m.reply "no keywords match #{str}"
+ else
+ m.reply "no keywords match #{str}"
+ end
end
+ rescue RegexpError => e
+ m.reply "no keywords match #{str}: #{e}"
+ rescue
+ debug e.inspect
+ m.reply "no keywords match #{str}: an error occurred"
end
end
else