]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/spell.rb
make sure @commands is never nil in script.rb
[user/henk/code/ruby/rbot.git] / data / 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           p.close
18           return
19         elsif(l =~ /^\s*&.*: (.*)$/)
20           m.reply "#{m.params}: #$1"
21           p.close
22           return
23         elsif(l =~ /^\s*\+ (.*)$/)
24           m.reply "#{m.params} is presumably derived from " + $1.downcase
25           p.close
26           return
27         elsif(l =~ /^\s*#/)
28           m.reply "#{m.params}: no suggestions"
29           p.close
30           return
31         end
32       }
33       p.close
34     else
35       m.reply "couldn't exec ispell :("
36       return
37     end
38   end
39 end
40 plugin = SpellPlugin.new
41 plugin.register("spell")