aggiunta possibilità di eseguire comandi shell

This commit is contained in:
Enrico Fasoli 2015-04-27 16:59:31 +02:00
parent 833f00591c
commit cea26142e0
2 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "asjon",
"version": "1.1.2",
"version": "1.2.0",
"private": true,
"author": "Enrico Fasoli <fazius2009@gmail.com>",
"description": "Il miglior amico della 5IA",

29
scripts/shell.coffee Normal file
View File

@ -0,0 +1,29 @@
# 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