summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-26 22:19:21 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-26 22:19:21 +0000
commit269578213cc727d757c8645eebc41304d01e87ce (patch)
treee36ce1f0e0feaec901f1f72ab5f7bf4bc9f5e368
parentb8373f3006a02084e58979bd021e8a76b5662ff6 (diff)
switch fortune to use new maps
-rw-r--r--rbot/plugins/fortune.rb20
1 files 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 [<module>] => 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-]+$/}