summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-24 01:20:17 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-06-24 01:40:11 +0200
commitaac060923bb64774d4a54a1dd8e5c1dfc2a70a4f (patch)
treee8e045af2b9458d252e1fba09ce7ca9616360ff4
parent08d2ed9279e97e08028b810e2a11a62a7f270e28 (diff)
spell plugin: use case instead of if/elsif/.../end and wrap in rescue
-rw-r--r--data/rbot/plugins/spell.rb46
1 files changed, 22 insertions, 24 deletions
diff --git a/data/rbot/plugins/spell.rb b/data/rbot/plugins/spell.rb
index bb33a864..3d77ebb0 100644
--- a/data/rbot/plugins/spell.rb
+++ b/data/rbot/plugins/spell.rb
@@ -16,34 +16,32 @@ class SpellPlugin < Plugin
m.reply _("incorrect usage: ") + help(m.plugin)
return
end
- p = IO.popen("%{prog} -a -S" % {:prog => @bot.config['spell.program']}, "w+")
- if(p)
- p.puts m.params
- p.close_write
- p.each_line {|l|
- if(l =~ /^\*/)
- m.reply(_("%{word} may be spelled correctly") % {:word => m.params})
- p.close
- return
- elsif(l =~ /^\s*&.*: (.*)$/)
- m.reply "#{m.params}: #$1"
- p.close
- return
- elsif(l =~ /^\s*\+ (.*)$/)
- m.reply((_("%{word} is presumably derived from ") % {:word => m.params}) + $1.downcase)
- p.close
- return
- elsif(l =~ /^\s*#/)
- m.reply(_("%{word}: no suggestions") % {:word => m.params})
- p.close
- return
- end
+
+ begin
+ IO.popen("%{prog} -a -S" % {:prog => @bot.config['spell.program']}, "w+") { |p|
+ p.puts m.params
+ p.close_write
+ p.each_line { |l|
+ case l
+ when /^\*/
+ m.reply(_("%{word} may be spelled correctly") % {:word => m.params})
+ when /^\s*&.*: (.*)$/
+ m.reply "#{m.params}: #$1"
+ when /^\s*\+ (.*)$/
+ m.reply((_("%{word} is presumably derived from ") % {:word => m.params}) + $1.downcase)
+ when /^\s*#/
+ m.reply(_("%{word}: no suggestions") % {:word => m.params})
+ end
+ return if m.replied?
+ }
}
- p.close
- else
+ rescue
m.reply(_("couldn't exec %{prog} :(") % {:prog => @bot.config['spell.program']})
return
end
+ m.reply(_("something odd happened while checking %{word} with %{prog}") % {
+ :word => m.params, :prog => @bot.config['spell.program']
+ })
end
end
plugin = SpellPlugin.new