]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - rbot/plugins/fortune.rb
version update
[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 fortune(m, params)
6     db = params[:db]
7     fortune = nil
8     ["/usr/games/fortune", "/usr/bin/fortune", "/usr/local/bin/fortune"].each {|f|
9       if FileTest.executable? f
10         fortune = f
11         break
12       end
13     }
14     m.reply "fortune binary not found" unless fortune
15     ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
16     m.reply ret.gsub(/\t/, "  ").split(/\n/).join(" ")
17     return
18   end
19 end
20 plugin = FortunePlugin.new
21 plugin.map 'fortune :db', :defaults => {:db => 'fortunes'},
22                           :requirements => {:db => /^[^-][\w-]+$/}