X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffortune.rb;h=3e2ffdf719a7b7dbd1cfa729bc280c0d1cb3fb7e;hb=16336b4a240a4265d1f2df1e30d7b68d3a924287;hp=79a900fdd38c0ebba10d53229ade2b7f12255cc8;hpb=0d9a8ad81eac5a3b8ee704cc8b4e586d1bc62d2b;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/fortune.rb b/data/rbot/plugins/fortune.rb index 79a900fd..3e2ffdf7 100644 --- a/data/rbot/plugins/fortune.rb +++ b/data/rbot/plugins/fortune.rb @@ -7,14 +7,17 @@ class FortunePlugin < Plugin 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 [] => 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", @@ -28,7 +31,7 @@ class FortunePlugin < Plugin end return nil unless fortune - + # Try setting the config entry config_par = {:key => 'fortune.path', :value => [fortune], :silent => true } debug "Setting fortune.path to #{fortune}" @@ -44,12 +47,15 @@ class FortunePlugin < Plugin ## 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| @@ -75,7 +81,7 @@ class FortunePlugin < Plugin # 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 @@ -88,7 +94,7 @@ class FortunePlugin < Plugin ## say 'em! m.reply "Fortune categories: #{categories.join ', '}" end - + end plugin = FortunePlugin.new plugin.map 'fortune categories', :action => "categories"