From aac060923bb64774d4a54a1dd8e5c1dfc2a70a4f Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 24 Jun 2008 01:20:17 +0200 Subject: [PATCH] spell plugin: use case instead of if/elsif/.../end and wrap in rescue --- data/rbot/plugins/spell.rb | 46 ++++++++++++++++++-------------------- 1 file 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 -- 2.39.5