X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fspell.rb;h=ba5cfc19f09550571fb2400af0f2f874088c1b7b;hb=297c80c7632e76e5c5a55cabad57154706911b57;hp=81ee1ac6553f5b3f88e303a932a3220c551faa1a;hpb=21949774b91eaec6ecde4eaa8ad121e2c0a36b87;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/spell.rb b/data/rbot/plugins/spell.rb index 81ee1ac6..ba5cfc19 100644 --- a/data/rbot/plugins/spell.rb +++ b/data/rbot/plugins/spell.rb @@ -1,35 +1,50 @@ +#-- vim:sw=2:et +#++ +# +# :title: Spell plugin + class SpellPlugin < Plugin + Config.register Config::StringValue.new('spell.path', + :default => 'ispell', + :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.path. Use %s as a placeholder for the executable name')) + def help(plugin, topic="") - "spell => check spelling of , suggest alternatives" + _("spell => check spelling of , suggest alternatives") end def privmsg(m) unless(m.params && m.params =~ /^\S+$/) - m.reply "incorrect usage: " + help(m.plugin) + m.reply _("incorrect usage: ") + help(m.plugin) return end - p = IO.popen("ispell -a -S", "w+") - if(p) - p.puts m.params - p.close_write - p.each_line {|l| - if(l =~ /^\*/) - m.reply "#{m.params} may be spelled correctly" - return - elsif(l =~ /^\s*&.*: (.*)$/) - m.reply "#{m.params}: #$1" - return - elsif(l =~ /^\s*\+ (.*)$/) - m.reply "#{m.params} is presumably derived from " + $1.downcase - return - elsif(l =~ /^\s*#/) - m.reply "#{m.params}: no suggestions" - return - end + + begin + IO.popen(@bot.config['spell.command_line'] % @bot.config['spell.path'], "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? + } } - else - m.reply "couldn't exec ispell :(" + rescue + m.reply(_("couldn't exec %{prog} :(") % {:prog => @bot.config['spell.path']}) return end + m.reply(_("something odd happened while checking %{word} with %{prog}") % { + :word => m.params, :prog => @bot.config['spell.path'] + }) end end plugin = SpellPlugin.new