]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - rbot/plugins/fortune.rb
that wasn't ideal
[user/henk/code/ruby/rbot.git] / rbot / plugins / fortune.rb
1 class FortunePlugin < Plugin
2   def help(plugin, topic="")
3     "fortune [<module>] => get a (short) fortune, optionally specifying fortune db"
4   end
5   def privmsg(m)
6     case m.params
7     when (/\B-/)
8       m.reply "incorrect usage: " + help(m.plugin)
9       return
10     when (/^([\w-]+)$/)
11       db = $1
12     when nil
13       db = "fortunes"
14     else
15       m.reply "incorrect usage: " + help(m.plugin)
16       return
17     end
18     fortune = nil
19     ["/usr/games/fortune", "/usr/bin/fortune", "/usr/local/bin/fortune"].each {|f|
20       if FileTest.executable? f
21         fortune = f
22         break
23       end
24     }
25     m.reply "fortune not found" unless fortune
26     ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
27     m.reply ret.gsub(/\t/, "  ").split(/\n/).join(" ")
28     return
29   end
30 end
31 plugin = FortunePlugin.new
32 plugin.register("fortune")