From 2a96c9198c1f6e13407d0999083f6ce5e0bc06fa Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Wed, 27 Jul 2005 16:32:32 +0000 Subject: move rbot into lib - still rearranging for packaging/installation --- lib/rbot/plugins/fortune.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/rbot/plugins/fortune.rb (limited to 'lib/rbot/plugins/fortune.rb') diff --git a/lib/rbot/plugins/fortune.rb b/lib/rbot/plugins/fortune.rb new file mode 100644 index 00000000..184b6b13 --- /dev/null +++ b/lib/rbot/plugins/fortune.rb @@ -0,0 +1,22 @@ +class FortunePlugin < Plugin + def help(plugin, topic="") + "fortune [] => 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 + } + 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.map 'fortune :db', :defaults => {:db => 'fortunes'}, + :requirements => {:db => /^[^-][\w-]+$/} -- cgit v1.2.3