]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/spell.rb
plugin(points): new message parser, see #34
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / spell.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: Spell plugin
5
6 class SpellPlugin < Plugin
7   Config.register Config::StringValue.new('spell.path',
8      :default => 'ispell',
9      :desc => _('Path to the program to use to check spelling'))
10   Config.register Config::StringValue.new('spell.command_line',
11      :default => '%s -a -S',
12      :desc => _('Command line used to call the spell.path. Use %s as a placeholder for the executable name'))
13
14   def help(plugin, topic="")
15     _("spell <word> => check spelling of <word>, suggest alternatives")
16   end
17   def privmsg(m)
18     unless(m.params && m.params =~ /^\S+$/)
19       m.reply _("incorrect usage: ") + help(m.plugin)
20       return
21     end
22
23     begin
24       IO.popen(@bot.config['spell.command_line'] % @bot.config['spell.path'], "w+") { |p|
25         p.puts m.params
26         p.close_write
27         p.each_line { |l|
28           case l
29           when /^\*/
30             m.reply(_("%{word} may be spelled correctly") % {:word => m.params})
31           when /^\s*&.*: (.*)$/
32             m.reply "#{m.params}: #$1"
33           when /^\s*\+ (.*)$/
34             m.reply((_("%{word} is presumably derived from ") % {:word => m.params}) + $1.downcase)
35           when /^\s*#/
36             m.reply(_("%{word}: no suggestions") % {:word => m.params})
37           end
38           return if m.replied?
39         }
40       }
41     rescue
42       m.reply(_("couldn't exec %{prog} :(") % {:prog => @bot.config['spell.path']})
43       return
44     end
45     m.reply(_("something odd happened while checking %{word} with %{prog}") % {
46       :word => m.params, :prog => @bot.config['spell.path']
47     })
48   end
49 end
50 plugin = SpellPlugin.new
51 plugin.register("spell")