Comandi Script da BOT
This commit is contained in:
@@ -392,23 +392,25 @@ async function resetProcessingJob() {
|
|||||||
|
|
||||||
async function inizia() {
|
async function inizia() {
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
try {
|
||||||
await telegrambot.sendMsgTelegram(tools.FREEPLANET,
|
|
||||||
telegrambot.ADMIN_USER_SERVER,
|
|
||||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
|
|
||||||
|
|
||||||
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
|
if (process.env.NODE_ENV === 'development') {
|
||||||
telegrambot.ADMIN_IDTELEGRAM_SERVER,
|
await telegrambot.sendMsgTelegram(tools.FREEPLANET,
|
||||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
|
telegrambot.ADMIN_USER_SERVER,
|
||||||
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
|
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
|
||||||
|
|
||||||
} else {
|
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
|
||||||
|
telegrambot.ADMIN_IDTELEGRAM_SERVER,
|
||||||
|
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
|
||||||
|
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
await telegrambot.sendMsgTelegramToTheAdminAllSites(`Ciao Admin\n` + `🔅🔅🔅 Il Server col BOT di {appname} è appena ripartito!`, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
// await telegrambot.sendMsgTelegram(tools.FREEPLANET, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`);
|
|
||||||
await telegrambot.sendMsgTelegramByIdTelegram(tools.FREEPLANET,
|
|
||||||
telegrambot.ADMIN_IDTELEGRAM_SERVER,
|
|
||||||
`Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}\n` +
|
|
||||||
`🔅 Il Server ${process.env.DATABASE} è appena ripartito!`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -530,6 +532,10 @@ async function faitest() {
|
|||||||
|
|
||||||
// const $vers = tools.getVersionint('1.92.45');
|
// const $vers = tools.getVersionint('1.92.45');
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
// tools.execScript("ls -la");
|
||||||
|
}
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
const prova = tools.getConfSiteOptionEnabledByIdApp('13', shared_consts.ConfSite.Notif_Reg_Push_Admin);
|
const prova = tools.getConfSiteOptionEnabledByIdApp('13', shared_consts.ConfSite.Notif_Reg_Push_Admin);
|
||||||
console.log('prova', prova);
|
console.log('prova', prova);
|
||||||
|
|||||||
@@ -268,6 +268,10 @@ const Menu = {
|
|||||||
'Inv e NO 7 Req',
|
'Inv e NO 7 Req',
|
||||||
MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF',
|
MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF',
|
||||||
MSGPAOLO: emoji.get('incoming_envelope') + ' Invia a PAOLO',
|
MSGPAOLO: emoji.get('incoming_envelope') + ' Invia a PAOLO',
|
||||||
|
RESTART_SRV: emoji.get('incoming_envelope') + 'RestartServer',
|
||||||
|
REBOOT_SRV: emoji.get('incoming_envelope') + 'RebootServer',
|
||||||
|
EXECSH: emoji.get('incoming_envelope') + 'ExecSH',
|
||||||
|
LOG_SRV: '🖥Logserver.sh',
|
||||||
MSGATUTTI: emoji.get('incoming_envelope') + ' Invia a TUTTI',
|
MSGATUTTI: emoji.get('incoming_envelope') + ' Invia a TUTTI',
|
||||||
it: {
|
it: {
|
||||||
ACCEDI: emo.PERSON + ' Accedi',
|
ACCEDI: emo.PERSON + ' Accedi',
|
||||||
@@ -404,9 +408,8 @@ const MenuYesNo = {
|
|||||||
|
|
||||||
const MenuAdmin = {
|
const MenuAdmin = {
|
||||||
it: {
|
it: {
|
||||||
menu: [
|
menu: [[Menu.RESTART_SRV + ' 6711', Menu.LOG_SRV + ' 6711'],
|
||||||
[Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.it.INDIETRO],
|
[Menu.REBOOT_SRV+ ' 6711', Menu.it.INDIETRO]],
|
||||||
[Menu.MSGPAOLO]],
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -677,6 +680,10 @@ const MyTelegramBot = {
|
|||||||
ISCRIZIONE_CONACREIS: 2,
|
ISCRIZIONE_CONACREIS: 2,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getAppTelegram: function() {
|
||||||
|
return appTelegram;
|
||||||
|
},
|
||||||
|
|
||||||
local_sendMsgTelegramByIdTelegram: async function(idapp, idtelegram, text,
|
local_sendMsgTelegramByIdTelegram: async function(idapp, idtelegram, text,
|
||||||
message_id, chat_id, ripr_menuPrec,
|
message_id, chat_id, ripr_menuPrec,
|
||||||
MyForm = null) {
|
MyForm = null) {
|
||||||
@@ -1015,6 +1022,13 @@ const MyTelegramBot = {
|
|||||||
return {body: msg, title};
|
return {body: msg, title};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sendMsgTelegramToTheAdminAllSites: async function(text, senzaintestazione) {
|
||||||
|
for (const idapp of this.getAppTelegram()) {
|
||||||
|
text = text.replace('{appname}', tools.getNomeAppByIdApp(idapp));
|
||||||
|
await this.sendMsgTelegramToTheAdmin(idapp, text, senzaintestazione);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
sendMsgTelegramToTheAdmin: async function(idapp, text, senzaintestazione) {
|
sendMsgTelegramToTheAdmin: async function(idapp, text, senzaintestazione) {
|
||||||
const usersmanagers = await User.getusersManagers(idapp);
|
const usersmanagers = await User.getusersManagers(idapp);
|
||||||
|
|
||||||
@@ -1709,76 +1723,110 @@ class Telegram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async isMenu(rec, msg, testo, notlast) {
|
async isMenu(rec, msg, testo, notlast) {
|
||||||
if (!msg)
|
try {
|
||||||
return;
|
if (!msg)
|
||||||
|
return;
|
||||||
|
|
||||||
if (testo === undefined)
|
if (testo === undefined)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const arrtext = testo.split(' ');
|
const arrtext = testo.split(' ');
|
||||||
let cmd2 = '';
|
let cmd2 = '';
|
||||||
let cmd1 = arrtext[0];
|
let cmd1 = arrtext[0];
|
||||||
if (arrtext.length > 1)
|
if (arrtext.length > 1)
|
||||||
cmd2 = arrtext[1];
|
cmd2 = arrtext[1];
|
||||||
|
|
||||||
let oldusername = rec.msgall_username_specifico;
|
let oldusername = rec.msgall_username_specifico;
|
||||||
|
|
||||||
if ((this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) ||
|
if ((this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) ||
|
||||||
(this.isSelMenu(msg, testo, 'INDIETRO'))) {
|
(this.isSelMenu(msg, testo, 'INDIETRO'))) {
|
||||||
rec.msgall_username_specifico = '';
|
rec.msgall_username_specifico = '';
|
||||||
} else {
|
} else {
|
||||||
if (rec.msgall_username_specifico !== '') {
|
if (rec.msgall_username_specifico !== '') {
|
||||||
await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico,
|
await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico,
|
||||||
testo);
|
testo);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isSelMenu(msg, testo, 'LAVAGNA') ||
|
if (this.isSelMenu(msg, testo, 'LAVAGNA') ||
|
||||||
MsgBot.LAVAGNA.find((rec) => testo.indexOf(rec) > -1)) {
|
MsgBot.LAVAGNA.find((rec) => testo.indexOf(rec) > -1)) {
|
||||||
await this.menuLavagna(msg);
|
await this.menuLavagna(msg);
|
||||||
} else if (this.isSelMenu(msg, testo, 'ACCEDI')) {
|
} else if (this.isSelMenu(msg, testo, 'ACCEDI')) {
|
||||||
await this.menuAccedi(msg);
|
await this.menuAccedi(msg);
|
||||||
} else if (this.isSelMenu(msg, testo, 'LINK_CONDIVIDERE')) {
|
} else if (this.isSelMenu(msg, testo, 'LINK_CONDIVIDERE')) {
|
||||||
await this.menuLinkCondividere(msg);
|
await this.menuLinkCondividere(msg);
|
||||||
} else if (testo === Menu.EXIT_TELEGRAM) {
|
} else if (testo === Menu.EXIT_TELEGRAM) {
|
||||||
await this.menuExitToTelegram(msg);
|
await this.menuExitToTelegram(msg);
|
||||||
} else if (testo === Menu.ADMIN) {
|
} else if (testo === Menu.ADMIN) {
|
||||||
await this.menuAdmin(msg);
|
await this.menuAdmin(msg);
|
||||||
} else if (testo === Menu.AIUTO) {
|
} else if (testo === Menu.AIUTO) {
|
||||||
await this.menuAiuto(msg);
|
await this.menuAiuto(msg);
|
||||||
} else if (testo === Menu.LANG) {
|
} else if (testo === Menu.LANG) {
|
||||||
await this.menuLang(msg);
|
await this.menuLang(msg);
|
||||||
} else if (testo === Menu.MSGATUTTI) {
|
} else if (testo === Menu.MSGATUTTI) {
|
||||||
await this.menumsgAll(msg);
|
await this.menumsgAll(msg);
|
||||||
} else if (testo === Menu.MSGSTAFF) {
|
} else if (testo === Menu.MSGSTAFF) {
|
||||||
await this.menumsgStaff(msg);
|
await this.menumsgStaff(msg);
|
||||||
} else if (testo === Menu.MSGPAOLO) {
|
} else if (testo === Menu.MSGPAOLO) {
|
||||||
await this.menumsgPaolo(msg);
|
await this.menumsgPaolo(msg);
|
||||||
// } else if (testo === Menu.MSG_NO_7_REQ) {
|
} else if (cmd1 === Menu.EXECSH) {
|
||||||
// await this.menumsg_No_7_Req(msg);
|
if (rec.user && cmd2) {
|
||||||
// } else if (testo === Menu.MSG_NO_9_REQ) {
|
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||||
// await this.menumsg_No_9_Req(msg);
|
if (isAdmin) {
|
||||||
// } else if (testo === Menu.NESSUN_IMBARCO_7REQ) {
|
const ris = await tools.execScript(this.idapp, msg, cmd2, 'Eseguo lo script');
|
||||||
// await this.menumsgGenerico(msg, Destin.NESSUN_IMBARCO_7REQ);
|
}
|
||||||
// } else if (cmd1 === Menu.MSG_TO_NAVE) {
|
}
|
||||||
// await this.menumsg_to_Nave(msg, cmd2);
|
} else if (cmd1 === Menu.LOG_SRV) {
|
||||||
// } else if (testo === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) {
|
if (rec.user) {
|
||||||
// await this.menumsg_Si_Invitati_No_7Req(msg);
|
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||||
} else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) {
|
if (isAdmin) {
|
||||||
await this.menumsg_A_Utente(msg);
|
await this.menuLogSrv(rec, msg, cmd2);
|
||||||
} else if (testo === Menu.SETPICPROFILE) {
|
}
|
||||||
await this.setPhotoProfile(rec.user, msg.from.id);
|
}
|
||||||
} else if (testo === Menu.RESETPWD) {
|
} else if (cmd1 === Menu.REBOOT_SRV) {
|
||||||
await this.setResetPwd(rec, msg);
|
if (rec.user) {
|
||||||
} else if (this.isSelMenu(msg, testo, 'INDIETRO') ||
|
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||||
(testo === Menu.it.INDIETRO)) {
|
if (isAdmin) {
|
||||||
await this.msgScegliMenu(msg);
|
await this.menuRebootSrv(rec, msg, cmd2);
|
||||||
} else if (this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) {
|
}
|
||||||
await this.sendMsg(msg.chat.id, 'Uscito dalla Chat con ' + oldusername);
|
}
|
||||||
rec.msgall_username_specifico = '';
|
|
||||||
} else {
|
} else if (cmd1 === Menu.RESTART_SRV) {
|
||||||
await this.isMenuNotVerified(rec, msg, notlast);
|
|
||||||
|
if (rec.user) {
|
||||||
|
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||||
|
if (isAdmin) {
|
||||||
|
await this.menuRestartSrv(rec, msg, cmd2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// } else if (testo === Menu.MSG_NO_7_REQ) {
|
||||||
|
// await this.menumsg_No_7_Req(msg);
|
||||||
|
// } else if (testo === Menu.MSG_NO_9_REQ) {
|
||||||
|
// await this.menumsg_No_9_Req(msg);
|
||||||
|
// } else if (testo === Menu.NESSUN_IMBARCO_7REQ) {
|
||||||
|
// await this.menumsgGenerico(msg, Destin.NESSUN_IMBARCO_7REQ);
|
||||||
|
// } else if (cmd1 === Menu.MSG_TO_NAVE) {
|
||||||
|
// await this.menumsg_to_Nave(msg, cmd2);
|
||||||
|
// } else if (testo === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) {
|
||||||
|
// await this.menumsg_Si_Invitati_No_7Req(msg);
|
||||||
|
} else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) {
|
||||||
|
await this.menumsg_A_Utente(msg);
|
||||||
|
} else if (testo === Menu.SETPICPROFILE) {
|
||||||
|
await this.setPhotoProfile(rec.user, msg.from.id);
|
||||||
|
} else if (testo === Menu.RESETPWD) {
|
||||||
|
await this.setResetPwd(rec, msg);
|
||||||
|
} else if (this.isSelMenu(msg, testo, 'INDIETRO') ||
|
||||||
|
(testo === Menu.it.INDIETRO)) {
|
||||||
|
await this.msgScegliMenu(msg);
|
||||||
|
} else if (this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) {
|
||||||
|
await this.sendMsg(msg.chat.id, 'Uscito dalla Chat con ' + oldusername);
|
||||||
|
rec.msgall_username_specifico = '';
|
||||||
|
} else {
|
||||||
|
await this.isMenuNotVerified(rec, msg, notlast);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('isMenu', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2167,6 +2215,42 @@ class Telegram {
|
|||||||
await this.menumsgGenerico(msg, Destin.PAOLO);
|
await this.menumsgGenerico(msg, Destin.PAOLO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonAbilitato(msg) {
|
||||||
|
MyTelegramBot.local_sendMsgTelegramByIdTelegram(this.idapp, msg.chat.id, 'Utente Non abilitato o codice non valido ad eseguire questa funzione');
|
||||||
|
}
|
||||||
|
|
||||||
|
chisono(rec) {
|
||||||
|
if (rec && rec.user) {
|
||||||
|
return 'Eseguito da ' + rec.user.username + ': ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async menuRestartSrv(rec, msg, cmd2) {
|
||||||
|
if (cmd2 === '6711') {
|
||||||
|
await MyTelegramBot.sendMsgTelegramToTheAdminAllSites(this.chisono(rec) + ' ha rilanciato il Server NODE.JS...');
|
||||||
|
const ris = await tools.execScript(this.idapp, msg, '~/batch/production_restart_server.sh', this.chisono(rec) + ' Restart il Server (Node.Js)');
|
||||||
|
} else {
|
||||||
|
this.nonAbilitato(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async menuLogSrv(rec, msg, cmd2) {
|
||||||
|
if (cmd2 === '6711') {
|
||||||
|
const ris = await tools.execScript(this.idapp, msg, '~/batch/logserver.sh', this.chisono(rec) + ' Visualizzo il Log del Server...');
|
||||||
|
} else {
|
||||||
|
this.nonAbilitato(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async menuRebootSrv(rec, msg, cmd2) {
|
||||||
|
if (cmd2 === '6711') {
|
||||||
|
await MyTelegramBot.sendMsgTelegramToTheAdminAllSites(this.chisono(rec) + ' ha effettuato il Reboot del Server! ...');
|
||||||
|
const ris = await tools.execScript(this.idapp, msg, '~/batch/esegui_reboot.sh', this.chisono(rec) + ' Eseguo il Reboot del Server !...');
|
||||||
|
} else {
|
||||||
|
this.nonAbilitato(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async menumsg_No_7_Req(msg) {
|
async menumsg_No_7_Req(msg) {
|
||||||
await this.menumsgGenerico(msg, Destin.NO_7_REQ);
|
await this.menumsgGenerico(msg, Destin.NO_7_REQ);
|
||||||
}
|
}
|
||||||
@@ -2986,8 +3070,8 @@ class Telegram {
|
|||||||
|
|
||||||
// Check if you are Admin
|
// Check if you are Admin
|
||||||
const user = await User.UserByIdTelegram(idapp, id);
|
const user = await User.UserByIdTelegram(idapp, id);
|
||||||
let isAdmin = user ? user.profile.manage_telegram && user.username ===
|
// let isAdmin = user ? user.profile.manage_telegram && user.username === 'paoloar77' : false;
|
||||||
'paoloar77' : false;
|
let isAdmin = user ? user.profile.manage_telegram: false;
|
||||||
const isManager = user ? user.profile.manage_telegram : false;
|
const isManager = user ? user.profile.manage_telegram : false;
|
||||||
const isVerified = user ? user.profile.teleg_id > 0 && user.verified_by_aportador : false;
|
const isVerified = user ? user.profile.teleg_id > 0 && user.verified_by_aportador : false;
|
||||||
|
|
||||||
@@ -3196,6 +3280,7 @@ class Telegram {
|
|||||||
// text = text.replace(/<\/div>/g, '');
|
// text = text.replace(/<\/div>/g, '');
|
||||||
text = text.replace(/ /g, ' ');
|
text = text.replace(/ /g, ' ');
|
||||||
|
|
||||||
|
|
||||||
if (!form) {
|
if (!form) {
|
||||||
form = {
|
form = {
|
||||||
'parse_mode': 'HTML',
|
'parse_mode': 'HTML',
|
||||||
@@ -3248,7 +3333,7 @@ class Telegram {
|
|||||||
|
|
||||||
async sendMsg(id, text, menu, form, msg_id, chat_id, ripr_menuPrec) {
|
async sendMsg(id, text, menu, form, msg_id, chat_id, ripr_menuPrec) {
|
||||||
|
|
||||||
if (!id)
|
if (!id || !text)
|
||||||
return false;
|
return false;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|||||||
@@ -2711,6 +2711,7 @@ module.exports = {
|
|||||||
convertSpecialTags(user, msg) {
|
convertSpecialTags(user, msg) {
|
||||||
try {
|
try {
|
||||||
if (!!user) {
|
if (!!user) {
|
||||||
|
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
|
||||||
msg = msg.replace('{username}', user.username);
|
msg = msg.replace('{username}', user.username);
|
||||||
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
msg = msg.replace('{name}', user.name ? user.name : user.username);
|
||||||
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
msg = msg.replace('{surname}', user.surname ? user.surname : '');
|
||||||
@@ -2774,4 +2775,31 @@ module.exports = {
|
|||||||
return strlinkreg;
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user