Config.register Config::StringValue.new('fortune.path',
:default => '',
:desc => "Full path to the fortune executable")
+ Config.register Config::ArrayValue.new('fortune.options',
+ :default => ['-n', '350', '-s'],
+ :desc => "Options to be passed on to fortune")
def help(plugin, topic="")
"fortune [<category>] => get a (short) fortune, optionally specifying fortune category || fortune categories => show categories"
end
- def find_fortune
+ def find_fortune(m)
fortune = @bot.config['fortune.path']
- return fortune if fortune
+ return fortune if fortune and not fortune.empty?
["/usr/bin/fortune",
"/usr/share/bin/fortune",
## Pick a fortune
def fortune(m, params)
- db = params[:db]
- fortune = find_fortune
+ fortune = find_fortune(m)
m.reply "fortune executable not found (try setting the 'fortune.path' variable)" unless fortune
+ command = [fortune] + @bot.config['fortune.options']
+ command << params[:db]
+ command.compact!
+
begin
- ret = Utils.safe_exec(fortune, "-n", "350", "-s", db)
+ ret = Utils.safe_exec(*command)
## cleanup ret
ret = ret.split(/\n+/).map do |l|
# Print the fortune categories
def categories(m, params)
- fortune = find_fortune
+ fortune = find_fortune(m)
m.reply "fortune executable not found (try setting the 'fortune.path' variable)" unless fortune
## list all fortune databases