summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/fortune.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-01-30 14:21:11 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-01-30 14:21:11 +0000
commit72c8aadb6e251a8d956259a572261781c1a45289 (patch)
tree1175ad1da1240806d235990fa792131e0897ae2e /data/rbot/plugins/fortune.rb
parent4d6ba25863f52c4ecbbbb6cb6ff1dcb8acc49da3 (diff)
The path to the fortune executable can now be configured (fortune.path). When empty, the bot will try to autodetect it. If autodetection is successfull, the path found will be stored in fortune.path
Diffstat (limited to 'data/rbot/plugins/fortune.rb')
-rw-r--r--data/rbot/plugins/fortune.rb43
1 files changed, 35 insertions, 8 deletions
diff --git a/data/rbot/plugins/fortune.rb b/data/rbot/plugins/fortune.rb
index 184b6b13..e530ae3e 100644
--- a/data/rbot/plugins/fortune.rb
+++ b/data/rbot/plugins/fortune.rb
@@ -1,18 +1,45 @@
class FortunePlugin < Plugin
+ BotConfig.register BotConfigStringValue.new('fortune.path',
+ :default => '',
+ :desc => "Full path to the fortune executable")
+
def help(plugin, topic="")
"fortune [<module>] => get a (short) fortune, optionally specifying fortune db"
end
def fortune(m, params)
db = params[:db]
- fortune = nil
- ["/usr/games/fortune", "/usr/bin/fortune", "/usr/local/bin/fortune"].each {|f|
- if FileTest.executable? f
- fortune = f
- break
- end
- }
+ fortune = @bot.config['fortune.path']
+ if fortune.empty?
+ ["/usr/share/games/fortune",
+ "/usr/share/bin/fortune",
+ "/usr/games/fortune",
+ "/usr/bin/fortune",
+ "/usr/local/games/fortune",
+ "/usr/local/bin/fortune"].each {|f|
+ if FileTest.executable? f
+ fortune = f
+
+ # Try setting the config entry
+ config_par = {:key => 'fortune.path', :value => [f], :silent => true }
+ debug "Setting fortune.path to #{f}"
+ set_path = @bot.plugins['config'].handle_set(m, config_par)
+ if set_path
+ debug "fortune.path set to #{@bot.config['fortune.path']}"
+ else
+ debug "couldn't set fortune.path"
+ end
+
+ break
+ end
+ }
+ end
m.reply "fortune binary not found" unless fortune
- ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
+ begin
+ ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
+ rescue
+ ret = "failed to execute fortune"
+ # TODO reset fortune.path when execution fails
+ end
m.reply ret.gsub(/\t/, " ").split(/\n/).join(" ")
return
end