- Nuovo Sistema di Flotte per Tutor.
X - Mettere anche la email del sognatore, per chi è abituato ad inviarla in quel modo... X - Controllare che sul sito compaiano le informazioni del Sognatore...
This commit is contained in:
@@ -12,10 +12,16 @@ const { CalZoom } = require('../models/calzoom');
|
||||
const { Nave } = require('../models/nave');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { ListaIngresso } = require('../models/listaingresso');
|
||||
const { MsgTemplate } = require('../models/msg_template');
|
||||
|
||||
const emoji = require('node-emoji');
|
||||
|
||||
|
||||
const i18n = require("i18n");
|
||||
|
||||
let url = process.env.URL || 'https://<PUBLIC-URL>';
|
||||
|
||||
const Benvenuto = emoji.get('heartbeat') + emoji.get('heartbeat') + emoji.get('heartbeat') + ' Benvenuto!';
|
||||
|
||||
const emo = {
|
||||
@@ -151,8 +157,10 @@ const Menu = {
|
||||
MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
|
||||
MSG_NO_7_REQ: emoji.get('incoming_envelope') + 'No 7 Req.',
|
||||
MSG_NO_9_REQ: emoji.get('incoming_envelope') + 'No 9 Req',
|
||||
NESSUN_IMBARCO_7REQ: emoji.get('incoming_envelope') + 'No Imbarco (7 Req)',
|
||||
MSG_SI_INVITATI_NO_7REQ_INVITATI: emoji.get('incoming_envelope') + 'Inv e NO 7 Req',
|
||||
MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF',
|
||||
MSGPAOLO: emoji.get('incoming_envelope') + ' Invia a PAOLO',
|
||||
MSGATUTTI: emoji.get('incoming_envelope') + ' Invia a TUTTI',
|
||||
it: {
|
||||
ACCEDI: emo.PERSON + ' Accedi',
|
||||
@@ -231,8 +239,15 @@ const Menu = {
|
||||
|
||||
const CONTA_SOLO = 'contasolo';
|
||||
const RICEVI_EMAIL = 'riceviemail';
|
||||
const NOME_COGNOME = 'nomecognome';
|
||||
const CHEDI_SE_IMBARCARTI = 'chiedi_se_imbarcarti';
|
||||
|
||||
const SendMsgCmd = [CONTA_SOLO, RICEVI_EMAIL];
|
||||
const InlineCmd = {
|
||||
VOGLIO_IMBARCARMI: 'voglio_imbarcarmi',
|
||||
NON_VOGLIO_IMBARCARMI: 'non_voglio_imbarcarmi'
|
||||
};
|
||||
|
||||
const SendMsgCmd = [CONTA_SOLO, RICEVI_EMAIL, NOME_COGNOME, CHEDI_SE_IMBARCARTI];
|
||||
|
||||
|
||||
const MenuNoLogin = {
|
||||
@@ -276,11 +291,11 @@ const MenuYesNo = {
|
||||
};
|
||||
|
||||
const MenuAdmin = {
|
||||
it: { menu: [[Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.it.INDIETRO], [Menu.MSG_NO_7_REQ, Menu.MSG_NO_9_REQ], [Menu.MSG_TO_NAVE, Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI]] },
|
||||
it: { menu: [[Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.it.INDIETRO], [Menu.MSG_NO_7_REQ, Menu.MSG_NO_9_REQ, Menu.NESSUN_IMBARCO_7REQ], [Menu.MSGPAOLO, Menu.MSG_TO_NAVE, Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI]] },
|
||||
};
|
||||
|
||||
const MenuSend = {
|
||||
it: { menu: [[CONTA_SOLO, RICEVI_EMAIL], [Menu.it.INDIETRO]] },
|
||||
it: { menu: [[CONTA_SOLO, RICEVI_EMAIL, NOME_COGNOME], [CHEDI_SE_IMBARCARTI, Menu.it.INDIETRO]] },
|
||||
};
|
||||
|
||||
const MenuChat = {
|
||||
@@ -298,6 +313,7 @@ const Sex = {
|
||||
};
|
||||
|
||||
const Status = {
|
||||
EXIT: -5,
|
||||
NONE: 0,
|
||||
VERIFIED: 1,
|
||||
WAITFOR_USERNAME_BO: 102,
|
||||
@@ -313,6 +329,8 @@ const Destin = {
|
||||
SI_INVITATI_NO_7REQ_INVITATI: 5,
|
||||
A_UTENTE: 6,
|
||||
MSG_TO_NAVE: 7,
|
||||
NESSUN_IMBARCO_7REQ: 8,
|
||||
PAOLO: 9,
|
||||
};
|
||||
|
||||
const StatusMSGALL = {
|
||||
@@ -446,7 +464,7 @@ const TelegramBot = require('node-telegram-bot-api');
|
||||
|
||||
module.exports = {
|
||||
|
||||
ADMIN_IDTELEGRAM_SERVER: '12429864',
|
||||
ADMIN_IDTELEGRAM_SERVER: '12429864', //Paolo
|
||||
ADMIN_USER_SERVER: 'paoloar77',
|
||||
ADMIN_USER_NAME_SERVER: 'Paolo',
|
||||
|
||||
@@ -509,105 +527,239 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
getMsgByTipoMsg: function (mydata, lang, user, sonosognatore) {
|
||||
getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) {
|
||||
if (!!mydata.msgextra) {
|
||||
return mydata.msgextra;
|
||||
return { body: mydata.msgextra, title: ''} ;
|
||||
}
|
||||
|
||||
let title = '';
|
||||
let msg = '';
|
||||
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
|
||||
if (sonosognatore)
|
||||
return printf(tools.gettranslate('SEND_LINK_CHAT_SOGNATORE', lang), user.name, mydata.navemediatore.riga + '.' + mydata.navemediatore.col, mydata.msgpar1);
|
||||
msg = printf(tools.gettranslate('SEND_LINK_CHAT_SOGNATORE', lang), user.name, mydata.navemediatore.riga + '.' + mydata.navemediatore.col, mydata.msgpar1);
|
||||
else
|
||||
return printf(tools.gettranslate('SEND_LINK_CHAT_DONATORI', lang), user.name, mydata.navemediatore.riga + '.' + mydata.navemediatore.col, mydata.msgpar1);
|
||||
msg = printf(tools.gettranslate('SEND_LINK_CHAT_DONATORI', lang), user.name, mydata.navemediatore.riga + '.' + mydata.navemediatore.col, mydata.msgpar1);
|
||||
} else if (mydata.tipomsg === tools.TipoMsg.SEND_MSG || mydata.tipomsg === tools.TipoMsg.SEND_MSG_SINGOLO) {
|
||||
let mymsg = '';
|
||||
if (!!mydata.username_mitt) {
|
||||
mymsg = '[' + tools.gettranslate('MSG_SEND_FROM', lang) + ' ' + mydata.username_mitt + ']:' + tools.ACAPO;
|
||||
msg = '[' + tools.gettranslate('MSG_SEND_FROM', lang) + ' ' + mydata.username_mitt + ']:' + tools.ACAPO;
|
||||
}
|
||||
mymsg += mydata.msgpar1;
|
||||
return mymsg;
|
||||
msg += mydata.msgpar1;
|
||||
} else if (mydata.tipomsg >= 1000) {
|
||||
const ris = await MsgTemplate.getMsgByLang(user.idapp, mydata.tipomsg, lang);
|
||||
msg = ris.body;
|
||||
title = ris.title;
|
||||
}
|
||||
|
||||
if (!!user) {
|
||||
msg = msg.replace('{username}', user.username);
|
||||
msg = msg.replace('{name}', user.name);
|
||||
msg = msg.replace('{surname}', user.surname);
|
||||
if (!!user.profile.link_payment)
|
||||
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
|
||||
if (!!user.profile.email_paypal)
|
||||
msg = msg.replace('{email_paypal}', user.profile.email_paypal);
|
||||
if (!!user.profile.note_payment)
|
||||
msg = msg.replace('{note_payment}', user.profile.note_payment);
|
||||
}
|
||||
|
||||
if (!!mydata.flotta) {
|
||||
// SOSTITUISCI LE PAROLE CHIAVI
|
||||
if (!!mydata.flotta.date_start)
|
||||
msg = msg.replace('{date_start}', tools.getstrDateLong(new Date(mydata.flotta.date_start), user.lang));
|
||||
if (!!mydata.flotta.date_close)
|
||||
msg = msg.replace('{date_close}', tools.getstrDateLong(new Date(mydata.flotta.date_close), user.lang));
|
||||
if (!!mydata.flotta.link_superchat)
|
||||
msg = msg.replace('{link_superchat}', mydata.flotta.link_superchat);
|
||||
if (!!mydata.flotta.tutor1)
|
||||
msg = msg.replace('{tutor1}', mydata.flotta.tutor1);
|
||||
if (!!mydata.flotta.tutor2)
|
||||
msg = msg.replace('{tutor2}', mydata.flotta.tutor2);
|
||||
if (!!mydata.flotta.tutor3)
|
||||
msg = msg.replace('{tutor3}', mydata.flotta.tutor3);
|
||||
if (!!mydata.flotta.tutorslo)
|
||||
msg = msg.replace('{tutorslo}', mydata.flotta.tutorslo);
|
||||
if (!!mydata.flotta.sognatore_nomecognome)
|
||||
msg = msg.replace('{sognatore}', mydata.flotta.sognatore_nomecognome);
|
||||
}
|
||||
|
||||
return { body: msg, title };
|
||||
},
|
||||
|
||||
sendMsgTelegramToNave: async function (idapp, mydata) {
|
||||
let nummsgtosend = 0;
|
||||
let nummsgsent = 0;
|
||||
let strout = '';
|
||||
let flotta = mydata.flotta;
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
try {
|
||||
const arrnavi = await Nave.getusersByNave(idapp, mydata.navemediatore);
|
||||
let arrnavi = null;
|
||||
if (flotta) {
|
||||
arrnavi = await Nave.getusersByFlotta(idapp, flotta.riga, flotta.col_prima, flotta.col_ultima);
|
||||
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_A_SOGNATORE) {
|
||||
arrnavi = await User.find({ idapp, username: flotta.sognatore });
|
||||
}
|
||||
} else {
|
||||
arrnavi = await Nave.getusersByNave(idapp, mydata.navemediatore);
|
||||
}
|
||||
|
||||
|
||||
// console.log('usersmanagers', usersmanagers);
|
||||
|
||||
let mymsg = "";
|
||||
let mymsgprimo = "";
|
||||
|
||||
tipomsgorig = mydata.tipomsg;
|
||||
|
||||
if (arrnavi) {
|
||||
tools.writeManagersLog('sendMsgTelegramToNave', mydata.navemediatore.riga + '.' + mydata.navemediatore.col);
|
||||
if (!flotta)
|
||||
tools.writeManagersLog('sendMsgTelegramToNave', mydata.navemediatore.riga + '.' + mydata.navemediatore.col);
|
||||
let index = 1;
|
||||
|
||||
if (mydata.inviareale) {
|
||||
let mystrmsg = tools.getStrMsgByTipoMsg(tipomsgorig);
|
||||
if (!!mystrmsg) {
|
||||
tools.writeFlottaLog(idapp, mystrmsg, flotta.riga, flotta.col_prima);
|
||||
}
|
||||
}
|
||||
|
||||
for (const nave of arrnavi) {
|
||||
const user = await User.findByIndOrder(idapp, nave.ind_order);
|
||||
|
||||
mydata.tipomsg = tipomsgorig;
|
||||
|
||||
let user = null;
|
||||
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_A_SOGNATORE) {
|
||||
user = nave;
|
||||
} else {
|
||||
user = await User.findByIndOrder(idapp, nave.ind_order);
|
||||
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_SOLLECITO_DONATORI_NO_DONO) {
|
||||
// Solo a quelli che non hanno fatto il dono
|
||||
if (nave.made_gift)
|
||||
user = null;
|
||||
}
|
||||
|
||||
if ((nave.num_tess % 2) === 0) {
|
||||
// MEDIATORE !
|
||||
// Se l'ultimo Donatore è un Mediatore, allora NON GLI MANDO IL MESSAGGIO !
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_EFFETTUA_IL_DONO) {
|
||||
user = null;
|
||||
}
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_SOLLECITO_DONATORI_NO_DONO) {
|
||||
user = null;
|
||||
}
|
||||
} else {
|
||||
// DONATORE
|
||||
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_A_MEDIATORI) {
|
||||
user = null; // Se sto mandando msg a Mediatore, allora questo no!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//mydata.tipomsg = tools.TipoMsg.SEND_MSG_A_MEDIATORI;
|
||||
|
||||
if (!!user) {
|
||||
const lang = user.lang;
|
||||
const idteleg = user.profile.teleg_id;
|
||||
const mymsg = this.getMsgByTipoMsg(mydata, lang, user, false);
|
||||
mydata.nave = nave;
|
||||
const rismsg = await this.getMsgByTipoMsg(mydata, lang, user, false);
|
||||
|
||||
mymsg = rismsg.body;
|
||||
mytitle = rismsg.title;
|
||||
|
||||
if (mymsgprimo === '') {
|
||||
mymsgprimo = mymsg;
|
||||
}
|
||||
|
||||
if (!!idteleg) {
|
||||
strout += '\n' + user.name + ' ' + user.surname + ':';
|
||||
strout += '\n (' + index + ') ' + user.name + ' ' + user.surname + ':';
|
||||
if (mydata.inviareale) {
|
||||
await this.sendMsgTelegramByIdTelegram(idapp, idteleg, mymsg, undefined, undefined, true);
|
||||
await tools.snooze(300);
|
||||
strout += ' -> MSG INVIATO';
|
||||
strout += ' -> (MSG OK)';
|
||||
|
||||
if (mydata.inviaemail && !!user.email) {
|
||||
// user.email = 'paolo.arena77@gmail.com';
|
||||
await sendemail.sendEmail_ByText(user.lang, user.email, user, idapp, {emailbody: mymsg, emailtitle: mytitle});
|
||||
strout += ' -> (EMAIL OK)';
|
||||
}
|
||||
|
||||
nummsgsent++;
|
||||
} else {
|
||||
strout += ' (Pronto da Inviare)';
|
||||
}
|
||||
nummsgsent++;
|
||||
}
|
||||
if ((nummsgsent === 1) && (mydata.inviareale)) {
|
||||
try {
|
||||
await this.sendMsgTelegramToTheManagers(idapp, 'Inviato messaggio a tutti i Donatori della Nave ' + mydata.navemediatore.riga + '.' + mydata.navemediatore.col + '\n' + mymsg)
|
||||
} catch (e) {
|
||||
|
||||
strout += ' (Ok)';
|
||||
nummsgtosend++;
|
||||
}
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
|
||||
if (!mydata.inviareale) {
|
||||
await this.sendMsgTelegramToTheManagers(idapp, 'TEST INVIO MESSAGGIO:\n' + mymsgprimo + '\n\n(Messaggi da Inviare: ' + nummsgtosend + ')');
|
||||
}
|
||||
|
||||
const usersognatore = await Nave.getSognatoreByRigaColMediatore(idapp, mydata.navemediatore);
|
||||
|
||||
console.log('Sognatore: ', usersognatore.username);
|
||||
|
||||
if (!!usersognatore) {
|
||||
const lang = usersognatore.lang;
|
||||
const idteleg = usersognatore.profile.teleg_id;
|
||||
const mymsg = this.getMsgByTipoMsg(mydata, lang, usersognatore, true);
|
||||
|
||||
// Invia Msg al Sognatore !
|
||||
if (mydata.inviareale) {
|
||||
await this.sendMsgTelegramByIdTelegram(idapp, idteleg, mymsg, undefined, undefined, true);
|
||||
await tools.snooze(300);
|
||||
nummsgsent++;
|
||||
strout += '\n' + usersognatore.name + ' ' + usersognatore.surname + ':';
|
||||
strout += ' -> MSG INVIATO';
|
||||
} else {
|
||||
strout += ' (Pronto da Inviare)';
|
||||
}
|
||||
if ((nummsgsent > 1) && (mydata.inviareale)) {
|
||||
try {
|
||||
let msg = '';
|
||||
if (!!flotta) {
|
||||
msg = 'Inviato messaggio a tutta la FLOTTA DA ' + flotta.riga + '.' + flotta.col_prima + ' A ' + flotta.riga + '.' + flotta.col_ultima + ' \n' + mymsg;
|
||||
} else {
|
||||
msg = 'Inviato messaggio a tutti i Donatori della Nave ' + mydata.navemediatore.riga + '.' + mydata.navemediatore.col + '\n' + mymsg;
|
||||
}
|
||||
await this.sendMsgTelegramToTheManagers(idapp, msg)
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (nummsgsent > 0) {
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
|
||||
const fields_to_update = {
|
||||
sent_msg_howto_make_gift: true
|
||||
};
|
||||
await Nave.findOneAndUpdate({ _id: mydata.navemediatore.id }, { $set: fields_to_update }, { new: false });
|
||||
/*
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
|
||||
|
||||
|
||||
const usersognatore = await Nave.getSognatoreByRigaColMediatore(idapp, mydata.navemediatore);
|
||||
|
||||
console.log('Sognatore: ', usersognatore.username);
|
||||
|
||||
if (!!usersognatore) {
|
||||
const lang = usersognatore.lang;
|
||||
const idteleg = usersognatore.profile.teleg_id;
|
||||
const mymsg = this.getMsgByTipoMsg(mydata, lang, usersognatore, true);
|
||||
|
||||
// Invia Msg al Sognatore !
|
||||
if (mydata.inviareale) {
|
||||
await this.sendMsgTelegramByIdTelegram(idapp, idteleg, mymsg, undefined, undefined, true);
|
||||
await tools.snooze(300);
|
||||
nummsgsent++;
|
||||
strout += '\n' + usersognatore.name + ' ' + usersognatore.surname + ':';
|
||||
strout += ' -> MSG INVIATO';
|
||||
} else {
|
||||
strout += ' (Pronto da Inviare)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
if (nummsgsent > 0) {
|
||||
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
|
||||
const fields_to_update = {
|
||||
sent_msg_howto_make_gift: true
|
||||
};
|
||||
await Nave.findOneAndUpdate({ _id: mydata.navemediatore.id }, { $set: fields_to_update }, { new: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return { nummsgsent, strout };
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
strout = 'Error: ' + e.message + '\n' + strout;
|
||||
return { nummsgsent, strout };
|
||||
}
|
||||
},
|
||||
@@ -1137,10 +1289,14 @@ class Telegram {
|
||||
await this.menumsgAll(msg)
|
||||
} else if (msg.text === Menu.MSGSTAFF) {
|
||||
await this.menumsgStaff(msg)
|
||||
} else if (msg.text === Menu.MSGPAOLO) {
|
||||
await this.menumsgPaolo(msg)
|
||||
} else if (msg.text === Menu.MSG_NO_7_REQ) {
|
||||
await this.menumsg_No_7_Req(msg)
|
||||
} else if (msg.text === Menu.MSG_NO_9_REQ) {
|
||||
await this.menumsg_No_9_Req(msg)
|
||||
} else if (msg.text === 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 (msg.text === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) {
|
||||
@@ -1460,6 +1616,8 @@ class Telegram {
|
||||
return 'TUTTI';
|
||||
else if (destin === Destin.STAFF)
|
||||
return 'STAFF';
|
||||
else if (destin === Destin.PAOLO)
|
||||
return 'PAOLO';
|
||||
else if (destin === Destin.NO_7_REQ)
|
||||
return 'No 7 Requisiti';
|
||||
else if (destin === Destin.NO_9_REQ)
|
||||
@@ -1468,6 +1626,8 @@ class Telegram {
|
||||
return '2 Invitati ma NO Requisiti';
|
||||
else if (destin === Destin.MSG_TO_NAVE)
|
||||
return 'Nave ' + rec.extraparam;
|
||||
else if (destin === Destin.NESSUN_IMBARCO_7REQ)
|
||||
return 'No Imbarcati (7 Req) ';
|
||||
else if (destin === Destin.A_UTENTE) {
|
||||
const rec = this.getRecInMem(msg);
|
||||
return rec.msgall_username_specifico
|
||||
@@ -1483,6 +1643,10 @@ class Telegram {
|
||||
await this.menumsgGenerico(msg, Destin.STAFF);
|
||||
}
|
||||
|
||||
async menumsgPaolo(msg) {
|
||||
await this.menumsgGenerico(msg, Destin.PAOLO);
|
||||
}
|
||||
|
||||
async menumsg_No_7_Req(msg) {
|
||||
await this.menumsgGenerico(msg, Destin.NO_7_REQ);
|
||||
}
|
||||
@@ -1592,7 +1756,7 @@ class Telegram {
|
||||
}
|
||||
|
||||
getRecInMem(msg) {
|
||||
return this.arrUsers.find((rec) => rec.id === msg.from.id);
|
||||
return this.arrUsers.find((rec) => rec.id === this.getchatid(msg));
|
||||
}
|
||||
|
||||
getRecInMemById(id) {
|
||||
@@ -1608,7 +1772,7 @@ class Telegram {
|
||||
}
|
||||
|
||||
deleteRecInMem(msg) {
|
||||
this.arrUsers = this.arrUsers.filter((rec) => rec.id !== msg.from.id);
|
||||
this.arrUsers = this.arrUsers.filter((rec) => rec.id !== this.getchatid(msg));
|
||||
}
|
||||
|
||||
async getUser(msg, rec, conmsg) {
|
||||
@@ -1776,7 +1940,15 @@ class Telegram {
|
||||
|
||||
tools.writeEventsLog(this.getDestinStr(msg, destin, rec) + ':\n' + texttosend);
|
||||
|
||||
// let chiedisino = false;
|
||||
|
||||
// TEST usersall = await User.getUsersTelegALL(rec.user.idapp, 'paoloar77');
|
||||
|
||||
for (const utente of usersall) {
|
||||
|
||||
let FormDaMostrare = null;
|
||||
const lang = utente.lang;
|
||||
|
||||
if (!utente.deleted && !utente.sospeso) {
|
||||
if (this.isSelMenu(msg, texttosend === 'LAVAGNA')) {
|
||||
textdainviare = await this.getLavagnaByUser(utente, msg);
|
||||
@@ -1791,12 +1963,16 @@ class Telegram {
|
||||
invia = User.isManager(utente.perm);
|
||||
} else if (destin === Destin.TUTTI) {
|
||||
invia = true;
|
||||
} else if (destin === Destin.PAOLO) {
|
||||
invia = utente.username === 'paoloar77';
|
||||
} else if (destin === Destin.A_UTENTE) {
|
||||
invia = utente.username === rec.msgall_username_specifico;
|
||||
} else if (destin === Destin.NO_7_REQ) {
|
||||
invia = !await User.isUserQualified7(this.idapp, utente.username);
|
||||
} else if (destin === Destin.NO_9_REQ) {
|
||||
invia = !await User.isUserQualified9(this.idapp, utente.username);
|
||||
} else if (destin === Destin.NESSUN_IMBARCO_7REQ) {
|
||||
invia = await User.NessunaNavePresenteByUsername(this.idapp, utente.username);
|
||||
} else if (destin === Destin.MSG_TO_NAVE) {
|
||||
invia = !await Nave.findDonatoreByNave(this.idapp, rec.extraparam);
|
||||
} else if (destin === Destin.SI_INVITATI_NO_7REQ_INVITATI) {
|
||||
@@ -1804,21 +1980,56 @@ class Telegram {
|
||||
const numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(this.idapp, utente.username);
|
||||
invia = (numinvitati >= 2) && (numinvitatiattivi < 2);
|
||||
}
|
||||
|
||||
// TEST invia = true;
|
||||
|
||||
if (invia) {
|
||||
let inviaveramente = false;
|
||||
|
||||
if (cmd === RICEVI_EMAIL) {
|
||||
preparatesto += utente.email + ', ';
|
||||
} else if (cmd === NOME_COGNOME) {
|
||||
preparatesto += utente.name + ' ' + utente.surname + '(' + utente.username + ')' + '\n';
|
||||
} else if (cmd === CONTA_SOLO) {
|
||||
// Niente
|
||||
} else if (cmd === CHEDI_SE_IMBARCARTI) {
|
||||
textdainviare = tools.gettranslate('VUOI_IMBARCARTI', lang);
|
||||
// chiedisino = true;
|
||||
// rec.msgall_status = StatusMSGALL.CONFIRM;
|
||||
FormDaMostrare = this.getInlineKeyboard(lang, [
|
||||
{ text: Menu[lang].SI, callback_data: InlineCmd.VOGLIO_IMBARCARMI },
|
||||
{ text: Menu[lang].NO, callback_data: InlineCmd.NON_VOGLIO_IMBARCARMI },
|
||||
]);
|
||||
inviaveramente = true;
|
||||
} else {
|
||||
inviaveramente = true;
|
||||
}
|
||||
|
||||
|
||||
if (inviaveramente) {
|
||||
if (destin === Destin.A_UTENTE) {
|
||||
await this.sistemaRecDest(rec, msg);
|
||||
await this.sendMsg(utente.profile.teleg_id, '[' + rec.username_bo + ' ti scrive]:\n' + textdainviare, MenuChat);
|
||||
} else {
|
||||
await this.sendMsg(utente.profile.teleg_id, textdainviare);
|
||||
|
||||
// if (chiedisino) {
|
||||
// this.ChiediSINO(msg, textdainviare);
|
||||
// } else {
|
||||
// TEST
|
||||
|
||||
let telegid = utente.profile.teleg_id;
|
||||
// if (process.env.PROD === "0") {
|
||||
// telegid = 12429864;
|
||||
// }
|
||||
await this.sendMsg(telegid, textdainviare, null, FormDaMostrare);
|
||||
|
||||
// break;
|
||||
}
|
||||
await tools.snooze(300)
|
||||
await tools.snooze(300);
|
||||
|
||||
nummsgsent++;
|
||||
}
|
||||
nummsgsent++;
|
||||
|
||||
|
||||
if (!SendMsgCmd.includes(cmd)) {
|
||||
if ((nummsgsent % 50) === 0) {
|
||||
@@ -1834,6 +2045,10 @@ class Telegram {
|
||||
let msgris = "";
|
||||
if (cmd === CONTA_SOLO) {
|
||||
msgris = nummsgsent + ' ' + getstr(this.getlang(msg), 'MSG_MSG_TOSENT');
|
||||
} else if (cmd === NOME_COGNOME) {
|
||||
msgris = nummsgsent + ' ' + 'Utenti';
|
||||
await this.sendMsg(msg.chat.id, msgris);
|
||||
msgris = preparatesto;
|
||||
} else if (cmd === RICEVI_EMAIL) {
|
||||
msgris = nummsgsent + ' ' + 'Email';
|
||||
await this.sendMsg(msg.chat.id, msgris);
|
||||
@@ -1870,17 +2085,28 @@ class Telegram {
|
||||
|| (msg.text === Menu.LANG_FR) || (msg.text === Menu.LANG_SI) || (msg.text === Menu.LANG_PT))
|
||||
}
|
||||
|
||||
async receiveMsg(msg) {
|
||||
async setInit(msg) {
|
||||
let status = this.getstatusInMemory(msg);
|
||||
if (status === Status.NONE) {
|
||||
await this.start(msg);
|
||||
let status = this.getstatusInMemory(msg);
|
||||
if (status !== Status.VERIFIED)
|
||||
return
|
||||
return Status.EXIT;
|
||||
} else {
|
||||
await this.setUser(msg)
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
async receiveMsg(msg) {
|
||||
|
||||
let status = await this.setInit(msg);
|
||||
|
||||
if (status === Status.EXIT) {
|
||||
return
|
||||
}
|
||||
|
||||
const rec = this.getRecInMem(msg);
|
||||
|
||||
status = this.getstatus(rec);
|
||||
@@ -1912,6 +2138,8 @@ class Telegram {
|
||||
domanda = 'Confermi di vedere a quante persone arriverebbe questo messaggio, a ' + achi + ' ?\n' + rec.msgtosent;
|
||||
else if (cmd === RICEVI_EMAIL)
|
||||
domanda = 'Confermi di vedere la lista delle email di ' + achi + '?';
|
||||
else if (cmd === NOME_COGNOME)
|
||||
domanda = 'Confermi di vedere la lista di persone ' + achi + '?';
|
||||
else {
|
||||
if (rec.msgall_achi === Destin.A_UTENTE)
|
||||
domanda = 'Confermi d\'Iniziare una Chat messaggi con ' + achi + ' ?\n' + rec.msgtosent;
|
||||
@@ -1940,7 +2168,8 @@ class Telegram {
|
||||
|
||||
async askVerifiedCode(msg) {
|
||||
|
||||
const rec = this.arrUsers.find((rec) => rec.id === msg.from.id);
|
||||
const rec = this.getRecInMem(msg);
|
||||
|
||||
if (!rec) {
|
||||
await this.addUser(msg);
|
||||
|
||||
@@ -1954,9 +2183,10 @@ class Telegram {
|
||||
}
|
||||
|
||||
async setUser(msg) {
|
||||
const id = msg.from.id;
|
||||
let id = this.getchatid(msg);
|
||||
|
||||
const user = await User.UserByIdTelegram(this.idapp, id);
|
||||
let rec = this.arrUsers.find((rec) => rec.id === msg.from.id);
|
||||
let rec = this.getRecInMem(msg);
|
||||
if (user && rec) {
|
||||
rec.user = user;
|
||||
}
|
||||
@@ -1971,12 +2201,19 @@ class Telegram {
|
||||
|
||||
}
|
||||
|
||||
getchatid(msg) {
|
||||
if (msg.from.is_bot)
|
||||
return msg.chat.id;
|
||||
else
|
||||
return msg.from.id;
|
||||
}
|
||||
|
||||
async alreadyExist(msg) {
|
||||
const id = msg.from.id;
|
||||
const id = this.getchatid(msg);
|
||||
let rec = null;
|
||||
try {
|
||||
const user = await User.UserByIdTelegram(this.idapp, id);
|
||||
let rec = this.arrUsers.find((rec) => rec.id === msg.from.id);
|
||||
let rec = this.getRecInMem(msg);
|
||||
if (user && !rec) {
|
||||
rec = this.addUser(msg);
|
||||
}
|
||||
@@ -1998,7 +2235,7 @@ class Telegram {
|
||||
const code = 100000 + Math.round(Math.random() * 899999);
|
||||
|
||||
const rec = {
|
||||
id: msg.from.id,
|
||||
id: this.getchatid(msg),
|
||||
code,
|
||||
lang,
|
||||
status: Status.WAITFOR_USERNAME_BO,
|
||||
@@ -2060,7 +2297,7 @@ class Telegram {
|
||||
|
||||
}
|
||||
|
||||
async _inviaMsg(id, text, form, menu, msg_id, chat_id, ripr_menuPrec) {
|
||||
async _inviaMsg(id, text, form, menu, msg_id, chat_id, ripr_menuPrec, opt) {
|
||||
if (!text)
|
||||
return 0;
|
||||
|
||||
@@ -2095,6 +2332,12 @@ class Telegram {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
text = text.replace(/<br>/g, "\n");
|
||||
text = text.replace(/<div>/g, "");
|
||||
text = text.replace(/<\/div>/g, "\n");
|
||||
text = text.replace(/ /g, " ");
|
||||
|
||||
if (!form) {
|
||||
form = {
|
||||
"parse_mode": "HTML",
|
||||
@@ -2169,6 +2412,48 @@ class Telegram {
|
||||
return mymenuout;
|
||||
}
|
||||
|
||||
getInlineKeyboard(lang, arrrisp1, arrrisp2, arrrisp3) {
|
||||
let mykeyb = {
|
||||
parse_mode: 'HTML',
|
||||
reply_markup: {
|
||||
inline_keyboard: []
|
||||
}
|
||||
};
|
||||
|
||||
// text
|
||||
// callback_data
|
||||
|
||||
// url
|
||||
|
||||
const arrriga1 = [];
|
||||
if (!!arrrisp1) {
|
||||
for (const ris of arrrisp1) {
|
||||
arrriga1.push(ris);
|
||||
}
|
||||
}
|
||||
const arrriga2 = [];
|
||||
if (!!arrrisp2) {
|
||||
for (const ris of arrrisp2) {
|
||||
arrriga2.push(ris);
|
||||
}
|
||||
}
|
||||
const arrriga3 = [];
|
||||
if (!!arrrisp3) {
|
||||
for (const ris of arrrisp3) {
|
||||
arrriga3.push(ris);
|
||||
}
|
||||
}
|
||||
|
||||
if (arrriga1.length > 0)
|
||||
mykeyb.reply_markup.inline_keyboard.push(arrriga1);
|
||||
if (arrriga2.length > 0)
|
||||
mykeyb.reply_markup.inline_keyboard.push(arrriga2);
|
||||
if (arrriga3.length > 0)
|
||||
mykeyb.reply_markup.inline_keyboard.push(arrriga3);
|
||||
|
||||
return mykeyb;
|
||||
}
|
||||
|
||||
async ChiediSINO(msg, domanda) {
|
||||
|
||||
const lang = this.getlang(msg);
|
||||
@@ -2246,6 +2531,15 @@ if (!tools.testing()) {
|
||||
if (!!token) {
|
||||
const bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
if (url === '0') {
|
||||
const ngrok = require('ngrok');
|
||||
ngrok.connect(port, function onConnect(error, u) {
|
||||
if (error) throw error;
|
||||
url = u;
|
||||
console.log(`Game tunneled at ${url}`);
|
||||
});
|
||||
}
|
||||
|
||||
arrTelegram.push({ idapp, cl: new Telegram(idapp, bot) });
|
||||
|
||||
bot.onText(/\/start/, (msg) => {
|
||||
@@ -2290,10 +2584,52 @@ if (!tools.testing()) {
|
||||
});
|
||||
|
||||
// Handle callback queries
|
||||
bot.on('callback_query', function onCallbackQuery(callbackQuery) {
|
||||
console.log('callback_query', callbackQuery);
|
||||
bot.on('callback_query', async (callbackQuery) => {
|
||||
// console.log('callback_query', callbackQuery);
|
||||
|
||||
bot.answerCallbackQuery(callbackQuery.id, { url });
|
||||
const myclTelegram = getclTelegBytoken(bot.token);
|
||||
|
||||
const action = callbackQuery.data;
|
||||
const msg = callbackQuery.message;
|
||||
const opts = {
|
||||
chat_id: msg.chat.id,
|
||||
message_id: msg.message_id,
|
||||
};
|
||||
|
||||
const status = await myclTelegram.setInit(msg);
|
||||
|
||||
const rec = myclTelegram.getRecInMem(msg);
|
||||
if (!!rec) {
|
||||
if (!!rec.user) {
|
||||
if (action === InlineCmd.VOGLIO_IMBARCARMI) {
|
||||
// Controlla se è qualificato!
|
||||
const mydata = tools.AddDate(rec.user.date_reg, 7);
|
||||
|
||||
const newrecingr = await ListaIngresso.addUserInListaIngresso(rec.user.idapp, rec.user.username, rec.user.aportador_solidario, rec.user.lang, true, true, mydata);
|
||||
|
||||
bot.editMessageText(tools.gettranslate('ADDED_TOLISTAINGRESSO', rec.user.lang), opts);
|
||||
|
||||
} else if (action === InlineCmd.NON_VOGLIO_IMBARCARMI) {
|
||||
await User.NonVoglioImbarcarmi(rec.user.idapp, rec.user.username);
|
||||
|
||||
const msgadd = '[' + rec.user.username + '] ' + rec.user.name + ' ' + rec.user.surname + ' ha risposto che NON VUOLE IMBARCARSI !';
|
||||
|
||||
await local_sendMsgTelegramToTheManagers(rec.user.idapp, msgadd, msg, false); // Anche a STAFF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
let text;
|
||||
|
||||
if (action === 'edit') {
|
||||
text = 'Edited Text';
|
||||
}
|
||||
|
||||
bot.editMessageText(text, opts);
|
||||
*/
|
||||
|
||||
// bot.answerCallbackQuery(callbackQuery.id, { url });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user