#-- vim:sw=2:et #++ # # :title: Shell Plugin for RBot # # Author:: Yaohan Chen # Copyright:: (C) 2008 Yaohan Chen # License:: GPLv2 require 'treetop' Treetop.load_from_string < params[:command].to_s}) else result = tree.execute do |cmd| replies = [] # FIXME currently all the interpolated commands are created with :from => m, # so they are considered depth 1. maybe we should calculate the depth using # the command parse tree, but having the parse tree implies finite depth new_m = fake_message(cmd, :from => m, :delegate => false) class << new_m self end.send(:define_method, :reply) do |r| replies << r end @bot.plugins.irc_delegate('privmsg', new_m) debug "command #{cmd} returned #{replies.join(' ')}" replies.join(' ') end m.reply result end end def help(plugin, topic=nil) _(%{The "shell" command enables interpolation of commands. For example, "shell say #channel $(ping)" will say the response of the ping command, "pong", in #channel. Note that not all output of commands are considered response, only those using m.reply. It's recommended to interpolate only commands that respond quickly.}) end end plugin = ShellPlugin.new plugin.map 'shell *command'