From cea26142e005d08847209de09ee12254bfc9beda Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 27 Apr 2015 16:59:31 +0200 Subject: [PATCH] =?UTF-8?q?aggiunta=20possibilit=C3=A0=20di=20eseguire=20c?= =?UTF-8?q?omandi=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- scripts/shell.coffee | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/shell.coffee diff --git a/package.json b/package.json index b81471a..6f23b99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asjon", - "version": "1.1.2", + "version": "1.2.0", "private": true, "author": "Enrico Fasoli ", "description": "Il miglior amico della 5IA", diff --git a/scripts/shell.coffee b/scripts/shell.coffee new file mode 100644 index 0000000..74b44fc --- /dev/null +++ b/scripts/shell.coffee @@ -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 +