Comandi Script da BOT

This commit is contained in:
paoloar77
2022-03-12 21:38:19 +01:00
parent 5872a11a15
commit d91aeadb5c
3 changed files with 203 additions and 84 deletions

View File

@@ -2711,6 +2711,7 @@ module.exports = {
convertSpecialTags(user, msg) {
try {
if (!!user) {
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
msg = msg.replace('{username}', user.username);
msg = msg.replace('{name}', user.name ? user.name : user.username);
msg = msg.replace('{surname}', user.surname ? user.surname : '');
@@ -2774,4 +2775,31 @@ module.exports = {
return strlinkreg;
},
execScript: function(idapp, msg, script, testo) {
const { exec } = require("child_process");
const telegrambot = require('../telegram/telegrambot');
const idchat = msg.chat.id;
console.log(testo + ' (' + script + ')');
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, testo);
exec(script, (error, stdout, stderr) => {
if (error) {
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, 'ERROR: ' + error.message);
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, 'ERROR: ' + stderr);
console.log(`stderr: ${stderr}`);
return;
}
// console.log(` ... stdout: ${stdout}`);
telegrambot.local_sendMsgTelegramByIdTelegram(idapp, idchat, stdout);
});
}
};