]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - rbot/plugins/fortune.rb
fd90f69bfb5e0f054d0d5d50eaee0b86d6aebc19
[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       fortune = f if FileTest.executable? f
21     }
22     m.reply "fortune not found" unless fortune
23     ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
24     m.reply ret.gsub(/\t/, "  ").split(/\n/).join(" ")
25     return
26   end
27 end
28 plugin = FortunePlugin.new
29 plugin.register("fortune")