lastfm plugin: added now playing info to the help
[rbot] / 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(_("%{word} may be spelled correctly") % {:word => m.params})
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((_("%{word} is presumably derived from ") % {:word => m.params}) + $1.downcase)
25           p.close
26           return
27         elsif(l =~ /^\s*#/)
28           m.reply(_("%{word}: no suggestions") % {:word => m.params})
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")