]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/plugins/spell.rb
move rbot into lib - still rearranging for packaging/installation
[user/henk/code/ruby/rbot.git] / lib / rbot / plugins / spell.rb
1 class SpellPlugin < Plugin
2   def help(plugin, topic="")
3     "spell <word> => check spelling of <word>, suggest alternatives"
4   end
5   def privmsg(m)
6     unless(m.params && m.params =~ /^\S+$/)
7       m.reply "incorrect usage: " + help(m.plugin)
8       return
9     end
10     p = IO.popen("ispell -a -S", "w+")
11     if(p)
12       p.puts m.params
13       p.close_write
14       p.each_line {|l|
15         if(l =~ /^\*/)
16           m.reply "#{m.params} may be spelled correctly"
17           return
18         elsif(l =~ /^\s*&.*: (.*)$/)
19           m.reply "#{m.params}: #$1"
20           return
21         elsif(l =~ /^\s*\+ (.*)$/)
22           m.reply "#{m.params} is presumably derived from " + $1.downcase
23           return
24         elsif(l =~ /^\s*#/)
25           m.reply "#{m.params}: no suggestions"
26           return
27         end
28       }
29     else
30       m.reply "couldn't exec ispell :("
31       return
32     end
33   end
34 end
35 plugin = SpellPlugin.new
36 plugin.register("spell")