65 lines
1.8 KiB
Ruby
65 lines
1.8 KiB
Ruby
=begin
|
|
run.rb
|
|
Copyright (c) 2004 by Jesse van den Kieboom <jesse@icecrew.nl>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
Defines:
|
|
run - open a world
|
|
crun - send all connected worlds the same text
|
|
=end
|
|
|
|
def register_functions
|
|
$scripts.register("run", "use: /run <command>\nruns <command> in a subshell and sends output to the world")
|
|
$scripts.register("crun", "use: /crun <channel> <command>\nsame as /run except it sends output to a channel")
|
|
end
|
|
|
|
def run(argstr)
|
|
io = IO.popen(argstr)
|
|
|
|
if (io)
|
|
$world.sendln(":LINUXes `" + argstr + "`")
|
|
|
|
while ((l = io.gets))
|
|
$world.sendln("emote | " + l[0..-2])
|
|
end
|
|
|
|
io.close
|
|
else
|
|
$world.writeln("Script error: can not execute #{argstr}!")
|
|
end
|
|
end
|
|
|
|
def crun(argstr)
|
|
ar = argstr.split(" ", 2)
|
|
|
|
if (ar.length != 2)
|
|
$world.writeln("Script error: use /crun <chanalias> <command>")
|
|
else
|
|
io = IO.popen(ar[1])
|
|
|
|
if (io)
|
|
$world.sendln(ar[0] + " :LINUXes `" + ar[1] + "`")
|
|
|
|
while ((l = io.gets))
|
|
$world.sendln(ar[0] + " :| " + l[0..-2])
|
|
end
|
|
|
|
io.close
|
|
else
|
|
$world.writeln("Script error: can not execute #{ar[1]}!")
|
|
end
|
|
end
|
|
end
|