diff options
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/spell.rb | 46 |
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 |