X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fspell.rb;h=5c98430bdea9c3ab6e76fa70a797fe66b5d89a9d;hb=6b8cca66628db3634296e5cb7e065f84555cf7cd;hp=bb33a8642996dd451157b96d6e59ce8a371c7362;hpb=08d2ed9279e97e08028b810e2a11a62a7f270e28;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/spell.rb b/data/rbot/plugins/spell.rb index bb33a864..5c98430b 100644 --- a/data/rbot/plugins/spell.rb +++ b/data/rbot/plugins/spell.rb @@ -4,9 +4,12 @@ # :title: Spell plugin class SpellPlugin < Plugin - Config.register Config::StringValue.new('spell.program', + Config.register Config::StringValue.new('spell.path', :default => 'ispell', - :desc => _('Program to use to check spelling')) + :desc => _('Path to the program to use to check spelling')) + Config.register Config::StringValue.new('spell.command_line', + :default => '%s -a -S', + :desc => _('Command line used to call the spell.program. Use %s as a placeholder for the executable name')) def help(plugin, topic="") _("spell => check spelling of , suggest alternatives") @@ -16,34 +19,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(@bot.config['spell.command_line'] % @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