From 269578213cc727d757c8645eebc41304d01e87ce Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Tue, 26 Jul 2005 22:19:21 +0000 Subject: [PATCH] switch fortune to use new maps --- rbot/plugins/fortune.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/rbot/plugins/fortune.rb b/rbot/plugins/fortune.rb index 6d077c85..184b6b13 100644 --- a/rbot/plugins/fortune.rb +++ b/rbot/plugins/fortune.rb @@ -2,19 +2,8 @@ class FortunePlugin < Plugin def help(plugin, topic="") "fortune [] => get a (short) fortune, optionally specifying fortune db" end - def privmsg(m) - case m.params - when (/\B-/) - m.reply "incorrect usage: " + help(m.plugin) - return - when (/^([\w-]+)$/) - db = $1 - when nil - db = "fortunes" - else - m.reply "incorrect usage: " + help(m.plugin) - return - 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 @@ -22,11 +11,12 @@ class FortunePlugin < Plugin break end } - m.reply "fortune not found" unless fortune + m.reply "fortune binary not found" unless fortune ret = Utils.safe_exec(fortune, "-n", "255", "-s", db) m.reply ret.gsub(/\t/, " ").split(/\n/).join(" ") return end end plugin = FortunePlugin.new -plugin.register("fortune") +plugin.map 'fortune :db', :defaults => {:db => 'fortunes'}, + :requirements => {:db => /^[^-][\w-]+$/} -- 2.39.5