1 class FortunePlugin < Plugin
2 BotConfig.register BotConfigStringValue.new('fortune.path',
4 :desc => "Full path to the fortune executable")
6 def help(plugin, topic="")
7 "fortune [<module>] => get a (short) fortune, optionally specifying fortune db"
11 fortune = @bot.config['fortune.path']
13 ["/usr/share/games/fortune",
14 "/usr/share/bin/fortune",
17 "/usr/local/games/fortune",
18 "/usr/local/bin/fortune"].each {|f|
19 if FileTest.executable? f
22 # Try setting the config entry
23 config_par = {:key => 'fortune.path', :value => [f], :silent => true }
24 debug "Setting fortune.path to #{f}"
25 set_path = @bot.plugins['config'].handle_set(m, config_par)
27 debug "fortune.path set to #{@bot.config['fortune.path']}"
29 debug "couldn't set fortune.path"
36 m.reply "fortune binary not found" unless fortune
38 ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
40 ret = "failed to execute fortune"
41 # TODO reset fortune.path when execution fails
43 m.reply ret.gsub(/\t/, " ").split(/\n/).join(" ")
47 plugin = FortunePlugin.new
48 plugin.map 'fortune :db', :defaults => {:db => 'fortunes'},
49 :requirements => {:db => /^[^-][\w-]+$/}