';
+
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(/
/g, "\n");
+ text = text.replace(//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 });
});
}
diff --git a/src/server/tools/general.js b/src/server/tools/general.js
index 87a2fc4..8652394 100755
--- a/src/server/tools/general.js
+++ b/src/server/tools/general.js
@@ -25,6 +25,7 @@ const webpush = require('web-push');
const FILELOG = 'filelog.txt';
const FILEEVENTS = 'logevents.txt';
const FILEMANAGERS = 'logmanagers.txt';
+const FILESOSTITUZIONI = 'log_sostituzioni.txt';
const FILENAVE = 'logNave.txt';
const subject = process.env.URLBASE_APP1;
const publicVapidKey = process.env.PUBLIC_VAPI_KEY;
@@ -114,6 +115,7 @@ textlang = {
'TEMPORANEA': 'TEMPORANEA',
'NAVE': 'NAVE',
'MSG_SEND_FROM': 'Msg Inviato da',
+ 'VUOI_IMBARCARTI': 'Attenzione! Ci risulta che attualmente non ti è stato assegnato Nessun Imbarco.\nQuesto può essere dovuto ad un errore durante la fase di aggiornamento del sito, oppure perchè tu stesso hai cancellato l\'imbarco.\n\nVuoi Aggiungerti ora al prossimo Imbarco per continuare nel tuo Viaggio in AYNI? ',
},
si: {
"Email je že bila preverjena": "Email je že bila preverjenaL'Email è già stata Verificata",
@@ -181,6 +183,7 @@ textlang = {
'TEMPORANEA': 'ZAČASNA',
'NAVE': 'LADJE',
'MSG_SEND_FROM': 'sporočilo, ki ga je poslal',
+ 'VUOI_IMBARCARTI': 'Pozor! Opazili smo, da ti trenutno ni bila dodeljena Nobena ladjica.\nTo je lahko posledica napake med fazo posodabljanja spletnega mesta ali ker si sam zbrisal svoj vpis.\n\nAli želiš nadaljevati plovbo, če želiš nadaljevati potovanje z AYNI ?',
},
es: {
"L'Email è già stata Verificata": "El correo electrónico ya ha sido verificado",
@@ -246,6 +249,7 @@ textlang = {
'TEMPORANEA': 'TEMPORAL',
'NAVE': 'NAVE',
'MSG_SEND_FROM': 'Mensaje enviado por',
+ 'VUOI_IMBARCARTI': '¡Atención! Entendemos que actualmente no está asignado a No Boarding.\nEsto puede deberse a un error durante la fase de actualización del sitio web, o porque usted mismo ha cancelado el embarque.\n\n¿Quieres añadirte ahora al próximo embarque para continuar tu viaje en AYNI?',
},
enUs: {
"partecipanti": "participants",
@@ -308,6 +312,7 @@ textlang = {
'TEMPORANEA': 'TEMPORARY',
'NAVE': 'SHIP',
'MSG_SEND_FROM': 'Msg sent by',
+ 'VUOI_IMBARCARTI': 'Attention! We understand that you have No Boarding assigned.\nThis may be due to an error during the site update phase, or because you have cancelled boarding yourself.\n\nDo you want to add now to the Next Boarding to continue your AYNI Trip?',
},
fr: {
"L'Email è già stata Verificata": "Le courrier électronique a déjà été vérifié",
@@ -374,6 +379,7 @@ textlang = {
'TEMPORANEA': 'TEMPORAIRE',
'NAVE': 'NAVIRE',
'MSG_SEND_FROM': 'Message envoyé par',
+ 'VUOI_IMBARCARTI': 'Attention ! Nous comprenons que vous n\'êtes actuellement pas affecté Pas d\'embarquement.\nCela peut être dû à une erreur lors de la phase de mise à jour du site, ou parce que vous avez vous-même annulé l\'embarquement.\n\nVoulez-vous vous ajouter maintenant au prochain embarquement pour continuer votre voyage AYNI ? ',
},
pt: {
"L'Email è già stata Verificata": "",
@@ -440,6 +446,7 @@ textlang = {
'TEMPORANEA': 'TEMPORÁRIO',
'NAVE': 'NAVE',
'MSG_SEND_FROM': 'Mensagem enviada por',
+ 'VUOI_IMBARCARTI': 'Atenção! Compreendemos que actualmente não lhe é atribuído Sem Embarque.\nIsto pode ser devido a um erro durante a fase de actualização do site, ou porque você mesmo cancelou o embarque.\n\nDeseja juntar-se agora ao próximo embarque para continuar a sua viagem AYNI?',
},
};
@@ -449,6 +456,7 @@ module.exports = {
ACAPO: '\n',
ENABLE_CRONTAB: 'CRONTAB',
+ UPDATE_GRADUATORIA: 'UPDATE_GRAD',
LANGADMIN: 'it',
@@ -465,6 +473,12 @@ module.exports = {
SEND_MSG: 2,
SEND_MSG_SINGOLO: 3,
SEND_TO_ALL: 10,
+ SEND_MSG_EFFETTUA_IL_DONO: 1000,
+ SEND_MSG_SOLLECITO_DONATORI_NO_DONO: 1005,
+ SEND_MSG_A_MEDIATORI: 1010,
+ SEND_MSG_A_SOGNATORE: 1020,
+ SEND_MSG_A_UTENTE_SOSTITUITO: 1030,
+ SEND_MSG_DONO_RICEVUTO_CORRETTAMENTE: 1040,
},
Placca: {
@@ -982,6 +996,8 @@ module.exports = {
'note': { $exists: true },
"$expr": { "$gt": [{ "$strLenCP": "$note" }, 1] }
});
+ if (params.filterand.includes(shared_consts.FILTER_QUALIFIED))
+ filtriadded.push({ 'profile.qualified': true });
if (params.filterand.includes(shared_consts.FILTER_USER_NO_ZOOM))
filtriadded.push({ 'profile.saw_zoom_presentation': false });
if (params.filterand.includes(shared_consts.FILTER_USER_NO_INVITANTE))
@@ -1010,6 +1026,11 @@ module.exports = {
filtriadded.push({
deleted: { $exists: true, $eq: true }
});
+ if (params.filterand.includes(shared_consts.FILTER_NAVI_NON_PRESENTI))
+ filtriadded.push({
+ navinonpresenti: { $exists: true, $eq: true },
+ $or: [{ subaccount: { $exists: false } }, { subaccount: { $exists: true, $eq: false } }]
+ });
}
@@ -1210,7 +1231,7 @@ module.exports = {
numup
};
- if (idapp === tools.AYNI) {
+ if (idapp === this.AYNI) {
this.getRigaColByPosUp(mypos);
ris = this.getlimiti(mypos);
}
@@ -1294,6 +1315,15 @@ module.exports = {
}
},
+ getstrDateLongFile(mydate, lang) {
+ if (mydate) {
+ // console.log('getstrDate', mytimestamp)
+ return mydate.getFullYear() + '-' + this.appendLeadingZeroes(mydate.getMonth() + 1) + '-' + this.appendLeadingZeroes(mydate.getDate()) + ' (' + this.getWeekDayByLang(mydate, lang) + ')'
+ } else {
+ return '';
+ }
+ },
+
getlinkzoom(idconf) {
if (idconf === '')
idconf = '6668882000';
@@ -1378,12 +1408,22 @@ module.exports = {
// console.log('Saved!');
// });
- // mystr = this.getstrDateTimeShort(Date.now()) + ' ' + mystr;
+ mystr = this.getstrDateTimeShort(new Date(), 'it') + ': ' + mystr;
+
const stream = fs.createWriteStream(filename, { flags: 'a' });
stream.write('\n' + mystr);
stream.end();
},
+ readlogfile(idapp, filename) {
+
+ try{
+ return fs.readFileSync(idapp + '/' + filename, 'utf8');
+ }catch (e) {
+ return '';
+ }
+ },
+
writelog(mystr) {
this.writelogfile(mystr, FILELOG);
},
@@ -1396,6 +1436,20 @@ module.exports = {
this.writelogfile(mystr, FILEMANAGERS);
},
+ writeSostituzioniLog(mystr) {
+ this.writelogfile(mystr, FILESOSTITUZIONI);
+ },
+
+ writeFlottaLog(idapp, mystr, riga, col) {
+ this.mkdirpath(idapp + '/');
+ this.writelogfile(mystr, idapp + '/' + riga + '_' + col + '.txt');
+ },
+
+ readFlottaLog(idapp, riga, col) {
+ const nomefile = riga + '_' + col + '.txt';
+ return this.readlogfile(idapp, nomefile);
+ },
+
writeNaveLog(mystr) {
this.writelogfile(mystr, FILENAVE);
},
@@ -1523,6 +1577,9 @@ module.exports = {
if ('username' in fieldsvalue) {
return true;
}
+ if ('note' in fieldsvalue) {
+ return true;
+ }
}
if (table === 'navi') {
@@ -1541,12 +1598,15 @@ module.exports = {
return true;
}
}
+ if (table === 'flotte') {
+ return true;
+ }
return false;
},
NotifyIfDelRecord(table) {
- if ((table === 'users') || (table === 'extralist') || (table === 'listaingressos')) {
+ if ((table === 'users') || (table === 'extralist') || (table === 'listaingressos') || (table === 'graduatorias')) {
return true;
}
@@ -1572,5 +1632,41 @@ module.exports = {
return Math.pow(2, riga - 1);
},
+ getPrimoFuocoByIndCol(col) {
+ // let ris = Math.ceil(col - (col % 8)) + 1;
+ let ris = ((Math.ceil(col / 8) - 1) * 8) + 1;
+ if (ris <= 0)
+ ris = 1;
+ return ris
+ },
+
+ getPrimaColFlotta(col) {
+ // let ris = Math.ceil(col - (col % 8)) + 1;
+ let ris = ((Math.ceil(col / 64) - 1) * 64) + 1;
+ if (ris <= 0)
+ ris = 1;
+ return ris
+ },
+
+ getStrMsgByTipoMsg(tipomsg) {
+
+ let mystr = '';
+
+ if (tipomsg === this.TipoMsg.SEND_MSG_EFFETTUA_IL_DONO)
+ mystr = 'Inviato Messaggio per Effettuare il Dono a Tutta la Flotta';
+ else if (tipomsg === this.TipoMsg.SEND_MSG_SOLLECITO_DONATORI_NO_DONO)
+ mystr = 'Inviato Messaggio per RICORDARE di Effettuare il Dono a chi ancora non l\'ha fatto';
+ else if (tipomsg === this.TipoMsg.SEND_MSG_A_MEDIATORI)
+ mystr = 'Inviato Messaggio ai Mediatori';
+ else if (tipomsg === this.TipoMsg.SEND_MSG_A_SOGNATORE)
+ mystr = 'Inviato Messaggio al Sognatore';
+ else if (tipomsg === this.TipoMsg.SEND_MSG_A_UTENTE_SOSTITUITO)
+ mystr = 'Inviato Messaggio all\'utente Sostituito';
+ else if (tipomsg === this.TipoMsg.SEND_MSG_DONO_RICEVUTO_CORRETTAMENTE)
+ mystr = 'Inviato Messaggio Dono Ricevuto Correttamente';
+
+ return mystr;
+ }
+
};
diff --git a/src/server/tools/server_constants.js b/src/server/tools/server_constants.js
index 9546f43..7ce747b 100755
--- a/src/server/tools/server_constants.js
+++ b/src/server/tools/server_constants.js
@@ -16,6 +16,7 @@ module.exports = Object.freeze({
RIS_CODE_ERR_UNAUTHORIZED: -30,
RIS_CODE_LOGIN_ERR_GENERIC: -20,
RIS_CODE_LOGIN_ERR: -10,
+ RIS_CODE_LOGIN_ERR_SUBACCOUNT: -8,
RIS_CODE_OK: 1,
RIS_CODE_LOGIN_OK: 1,
diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js
index 16af737..da2895b 100755
--- a/src/server/tools/shared_nodejs.js
+++ b/src/server/tools/shared_nodejs.js
@@ -20,6 +20,8 @@ module.exports = {
FILTER_USER_TELEGRAM_BLOCKED: 1024,
FILTER_ATTIVI: 2048,
FILTER_NASCOSTI: 4096,
+ FILTER_NAVI_NON_PRESENTI: 8192,
+ FILTER_QUALIFIED: 16384,
Permissions: {
Admin: 1,
@@ -49,6 +51,8 @@ module.exports = {
AGGIUNGI_NUOVO_IMBARCO: 380,
CANCELLA_IMBARCO: 385,
DAMMI_PRIMO_UTENTE_LIBERO: 390,
+ GET_VALBYTABLE: 400,
+ SET_VALBYTABLE: 410,
},
fieldsUserToChange() {