asjon/scripts/shell.coffee
2015-04-27 17:29:58 +02:00

30 lines
791 B
CoffeeScript

# Description:
# abilità di asjon di usare la shell *nix
#
# Requires:
# None
#
# Commands:
# asjon run/esegui/shell git/npm args...
#
# Author:
# Enrico Fasoli (fazo96)
cp = require 'child_process'
nope = ['BZBZ 400-BAD-REQUEST', 'BZBZ DOES-NOT-COMPUTE', 'BZBZ ADMIN-NOT-DETECTED', 'BZBZ IS-NOT-AUTHORIZED', 'BZBZ ACCESS-DENIED']
isFromAdmin = (res) ->
res.message.user.room is process.env.ADMIN_ROOM?.replace(':','#') or res.robot.adapterName is 'shell'
module.exports = (robot) ->
robot.respond /(?:run|esegui|shell) (git|npm) (.+)/i, (res) ->
q = res.match[1]+' '+res.match[2]
if isFromAdmin res then cp.exec q, (err,stdout,stderr) ->
if err
res.send 'command failed:\n'+stderr
else
res.send stdout
else res.send res.random nope