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 +