summaryrefslogtreecommitdiff
path: root/rbot/plugins/fortune.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rbot/plugins/fortune.rb')
-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-]+$/}