From 3b6218d2ba75db27981540749ec1aa27c25f9a38 Mon Sep 17 00:00:00 2001 From: paoloar77 Date: Fri, 7 Jan 2022 01:18:01 +0100 Subject: [PATCH] Lista Amici Richieste di Fiducia Accettati Rifiutati --- src/server/models/site.js | 15 + src/server/models/user.js | 114 +- src/server/router/email_router.js | 14 + src/server/router/index_router.js | 12 +- src/server/router/users_router.js | 47 +- src/server/sendemail.js | 44 +- src/server/server.js | 31 +- src/server/telegram/telegrambot.js | 1547 +++++++++++++++++----------- src/server/tools/general.js | 56 +- src/server/tools/shared_nodejs.js | 9 + yarn.lock | 28 +- 11 files changed, 1254 insertions(+), 663 deletions(-) diff --git a/src/server/models/site.js b/src/server/models/site.js index ff96f1b..993baa9 100755 --- a/src/server/models/site.js +++ b/src/server/models/site.js @@ -35,12 +35,18 @@ const SiteSchema = new Schema({ host: { type: String, }, + host_test: { + type: String, + }, portapp: { type: String, }, dir: { type: String, }, + dir_test: { + type: String, + }, email_from: { type: String, }, @@ -53,9 +59,18 @@ const SiteSchema = new Schema({ telegram_bot_name: { type: String, }, + telegram_key_test: { + type: String, + }, + telegram_bot_name_test: { + type: String, + }, pathreg_add: { type: String, }, + ask_to_verify_reg: { + type: Boolean, + }, who: { type: String }, diff --git a/src/server/models/user.js b/src/server/models/user.js index 77cf4bb..25ce4e6 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -137,7 +137,6 @@ const UserSchema = new mongoose.Schema({ }, verified_by_aportador: { type: Boolean, - default: false, }, aportador_iniziale: { type: String, @@ -158,6 +157,15 @@ const UserSchema = new mongoose.Schema({ sospeso: { type: Boolean, }, + blocked: { + type: Boolean, + }, + username_who_block: { + type: String, + }, + date_blocked: { + type: Date, + }, non_voglio_imbarcarmi: { type: Boolean, }, @@ -303,6 +311,7 @@ const UserSchema = new mongoose.Schema({ description: {type: String}, rating: {type: Number}, }], + friends: [], // username }, }) @@ -1193,6 +1202,109 @@ UserSchema.statics.getUserProfileByUsername = async function(idapp, username) { }; +UserSchema.statics.getUsernameFriendsByUsername = async function( + idapp, username) { + + return User.findOne({ + idapp, 'username': username, + $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + }, {'profile.friends': 1}).then((rec) => rec ? rec._doc.profile.friends : []); +}; + +UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameDest, cmd, value) { + + let ris = null; + let update = { }; + if (cmd === shared_consts.FRIENDSCMD.SETTRUST) { + + return User.updateOne({idapp, username: usernameDest}, + { $set: { verified_by_aportador: value } }, { new: false } ); + + } else if (cmd === shared_consts.FRIENDSCMD.SETFRIEND) { + // Aggiungo l'Amicizia a me + const foundIfAlreadyFriend = await User.findOne({ + idapp, + members: { + $elemMatch: { 'profile.friends': usernameOrig } + } + }); + + update = { $push: { 'profile.friends': [usernameOrig] } }; + if (!foundIfAlreadyFriend) { + ris = await User.updateOne({idapp, username: usernameOrig}, update); + } + + // Controlla se lui aveva già la mia amicizia + const foundIfAlreadyFriend2 = await User.findOne({ + members: { + $elemMatch: { 'profile.friends': usernameOrig } + } + }); + + update = { $push: { 'profile.friends': [usernameOrig] } }; + if (!foundIfAlreadyFriend) { + ris = await User.updateOne({idapp, username: usernameOrig}, update); + } + } else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS) { + // Rimuovo l'Amicizia da lui + await User.updateOne({idapp, username: usernameDest}, { $pullAll: { 'profile.friends': [usernameOrig] } }); + // Rimuovo l'Amicizia da me + ris = await User.updateOne({idapp, username: usernameOrig}, { $pullAll: { 'profile.friends': [usernameDest] } }); + } else if (cmd === shared_consts.FRIENDSCMD.BLOCK_USER) { + // Rimuovo l'Amicizia da lui + await User.updateOne({idapp, username: usernameDest}, { $pullAll: { 'profile.friends': [usernameOrig] } }); + // Rimuovo l'Amicizia da me + await User.updateOne({idapp, username: usernameOrig}, { $pullAll: { 'profile.friends': [usernameDest] } }); + + // Blocco la persona + ris = await User.updateOne({idapp, username: usernameDest}, { $set: { blocked: true, sospeso: true, username_who_block: usernameOrig, date_blocked: new Date() } }); + } + + return ris; +}; + + +UserSchema.statics.getFriendsByUsername = async function(idapp, username) { + + const whatToShow = { + username: 1, + aportador_solidario: 1, + name: 1, + surname: 1, + deleted: 1, + sospeso: 1, + verified_email: 1, + verified_by_aportador: 1, + 'profile.nationality': 1, + 'profile.biografia': 1, + 'profile.username_telegram': 1, + 'profile.img': 1, + 'profile.sex': 1, + 'profile.dateofbirth': 1, + 'profile.born_city': 1, + 'profile.born_province': 1, + 'profile.born_country': 1, + email: 1, + date_reg: 1, + }; + + const arrUsernameFriends = await User.getUsernameFriendsByUsername(idapp, username); + + const listFriends = await User.find({ + idapp, + username: {$in: arrUsernameFriends}, + $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + }, whatToShow); + + const listTrusted = await User.find({ + idapp, aportador_solidario: username, + $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + }, whatToShow); + + return ({listFriends, listTrusted}); + +}; + UserSchema.statics.getAportadorSolidarioByUsername = async function( idapp, username) { const User = this; diff --git a/src/server/router/email_router.js b/src/server/router/email_router.js index ea08872..765e8af 100755 --- a/src/server/router/email_router.js +++ b/src/server/router/email_router.js @@ -17,4 +17,18 @@ router.get('/:idapp/:email', (req, res) => { }); }); +router.post('/ck', (req, res) => { + const idapp = req.body.idapp; + var email = req.body.email; + + User.findByEmail(idapp, email).then((user) => { + if (!user) { + return res.status(404).send(); + } + res.status(200).send(); + }).catch((e) => { + res.status(400).send(); + }); +}); + module.exports = router; diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 25b0a4a..5da5d65 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -455,7 +455,7 @@ router.post('/gettable', authenticate, (req, res) => { return res.send(ris); }).catch((e) => { - console.log(e.message); + console.log('gettable: ' + e.message); res.status(400).send(e); }); @@ -601,6 +601,13 @@ router.patch('/chval', authenticate, async (req, res) => { } + if (mydata.table === shared_consts.TAB_SITES) { + if (shared_consts.SITES_KEY_TO_CRYPTED in fieldsvalue) { + fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED] = tools.cryptdata(fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED]); + } + + } + await mytable.findByIdAndUpdate(id, {$set: fieldsvalue}).then(async (rec) => { // tools.mylogshow(' REC TO MODIFY: ', rec); if (!rec) { @@ -1559,8 +1566,9 @@ function uploadFile(req, res, version) { form.parse(req); let dirmain = '/statics'; + console.log('process.env.PROD', process.env.PROD); if (version > 0) { - if (process.env.PROD === 1) { + if (process.env.PROD === '1') { dirmain = ''; } else { dirmain = '/public'; diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js index 54dfa6e..b20b3f8 100755 --- a/src/server/router/users_router.js +++ b/src/server/router/users_router.js @@ -107,6 +107,12 @@ router.post('/', async (req, res) => { user.lasttimeonline = new Date(); user.date_reg = new Date(); user.aportador_iniziale = user.aportador_solidario; + + if (!tools.getAskToVerifyReg(body.idapp)) { + // Se non devo chiedere di verificare all'Invitato, allora lo verifico direttamente + user.verified_by_aportador = true; + } + /* if (user.idapp === tools.AYNI) { user.profile.paymenttypes = ['paypal']; } */ @@ -319,7 +325,7 @@ router.patch('/:id', authenticate, (req, res) => { }); }); -router.post('/profile', (req, res) => { +router.post('/profile', authenticate, (req, res) => { const username = req.body['username']; idapp = req.body.idapp; locale = req.body.locale; @@ -470,6 +476,45 @@ router.post('/import_extralist', async (req, res) => { res.send(ris); }); +router.post('/friends', authenticate, (req, res) => { + const username = req.user.username; + idapp = req.body.idapp; + locale = req.body.locale; + + return User.getFriendsByUsername(idapp, username).then((ris) => { + res.send(ris); + }).catch((e) => { + tools.mylog('ERRORE IN Profile: ' + e.message); + res.status(400).send(); + }); + +}); + +router.post('/friends/cmd', authenticate, (req, res) => { + const usernameLogged = req.user.username; + const idapp = req.body.idapp; + const locale = req.body.locale; + const usernameOrig = req.body.usernameOrig; + const usernameDest = req.body.usernameDest; + const cmd = req.body.cmd; + const value = req.body.value; + + if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) { + // If without permissions, exit + if (usernameOrig !== usernameLogged) { + return res.status(404).send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''}); + } + } + + return User.setFriendsCmd(idapp, usernameOrig, usernameDest, cmd, value).then((ris) => { + res.send(ris); + }).catch((e) => { + tools.mylog('ERRORE IN Friends/cmd: ' + e.message); + res.status(400).send(); + }); + +}); + async function eseguiDbOp(idapp, mydata, locale) { let ris = await User.DbOp(idapp, mydata); diff --git a/src/server/sendemail.js b/src/server/sendemail.js index 2def600..7ab33f5 100755 --- a/src/server/sendemail.js +++ b/src/server/sendemail.js @@ -553,7 +553,8 @@ module.exports = { try { mylocalsconf.dataemail.disclaimer_out = !!mylocalsconf.dataemail.disclaimer ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disclaimer) : ''; mylocalsconf.dataemail.disc_bottom_out = !!mylocalsconf.dataemail.disc_bottom ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.disc_bottom) : ''; - mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail) : ''; + if (mylocalsconf.dataemail.templ) + mylocalsconf.dataemail.templ.testoheadermail_out = !!mylocalsconf.dataemail.templ.testoheadermail ? this.fieldsloop(mylocalsconf, mylocalsconf.dataemail.templ.testoheadermail) : ''; } catch (e) { console.error('Error replacefields: ' + e) } @@ -872,29 +873,34 @@ module.exports = { const myarrevents = await MyEvent.getLastEvents(idapp); const myemail = await Settings.getValDbSettings(idapp, 'EMAIL_TEST'); - mylocalsconf = { - idapp, - locale: lang, - nomeapp: tools.getNomeAppByIdApp(idapp), - arrevents: myarrevents, - name: 'TestNome', - surname: 'TestCognome', - emailto: myemail, - baseurl: tools.getHostByIdApp(idapp), - hashemail: tools.getHash(myemail), - }; + if (myemail) { + mylocalsconf = { + idapp, + locale: lang, + nomeapp: tools.getNomeAppByIdApp(idapp), + arrevents: myarrevents, + name: 'TestNome', + surname: 'TestCognome', + subject: '', + emailto: myemail, + baseurl: tools.getHostByIdApp(idapp), + hashemail: tools.getHash(myemail), + }; - console.log('myarrevents'); - console.table(mylocalsconf.arrevents); + console.log('myarrevents'); + console.table(mylocalsconf.arrevents); - mylocalsconf.dataemail = await this.getdataemail(idapp); + mylocalsconf.dataemail = await this.getdataemail(idapp); - this.replacefields(mylocalsconf); + this.replacefields(mylocalsconf); - const smtpTransport = this.getTransport(mylocalsconf); + const smtpTransport = this.getTransport(mylocalsconf); - console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly', previewonly); - return this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, mylocalsconf, '', smtpTransport, previewonly); + console.log('-> Invio Email TEST a', mylocalsconf.emailto, 'previewonly', + previewonly); + return this.sendEmail_base('newsletter/' + lang, mylocalsconf.emailto, + mylocalsconf, '', smtpTransport, previewonly); + } }, diff --git a/src/server/server.js b/src/server/server.js index 0c2056b..090b5ce 100755 --- a/src/server/server.js +++ b/src/server/server.js @@ -227,7 +227,7 @@ async function mystart() { // tools.sendNotifToAdmin('Riparti', 'Riparti'); - // sendemail.testemail('2', 'it'); + let miapass = ''; @@ -378,16 +378,12 @@ async function inizia() { if (process.env.NODE_ENV === 'development') { 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!`); + } else { - // if (process.env.NODE_ENV === 'production') { - await telegrambot.sendMsgTelegram(tools.CNM, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`); - await telegrambot.sendMsgTelegramByIdTelegram(tools.CNM, telegrambot.ADMIN_IDTELEGRAM_SERVER, `Il Server ${process.env.DATABASE} è appena ripartito!`); - - // await telegrambot.sendMsgTelegramByIdTelegram('2', telegrambot.ADMIN_IDTELEGRAM_SERVER, `Il Server ${process.env.DATABASE} è appena ripartito!`); - - testo = 'Ciao Paolo!'; - myid = await telegrambot.sendMsgTelegramByIdTelegram(tools.CNM, telegrambot.ADMIN_IDTELEGRAM_SERVER, testo); + // 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!`); } } @@ -409,7 +405,7 @@ async function inizia() { // } async function faitest() { - console.log('Fai Test:') + // console.log('Fai Test:') const testfind = false; @@ -424,6 +420,21 @@ async function faitest() { console.log('ris', ris); } + if (false) { + // const {User} = require('./models/user'); + /* + const user = await User.findOne({ + idapp: 12, + username: 'paoloar77', + }); + + await sendemail.sendEmail_Registration('it', 'paolo@freeplanet.app', user, + '12', ''); + + */ + + } + if (false) { const { User } = require('./models/user'); diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 80b4825..1300ae0 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -1,32 +1,34 @@ const tools = require('../tools/general'); -const appTelegram = [tools.CNM, tools.FREEPLANET]; +const appTelegram = [tools.FREEPLANET]; -const appTelegram_TEST = [tools.FREEPLANET]; +const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM]; +const appTelegram_DEVELOP = [tools.PDNM]; -const appTelegramFinti = ['2']; -const appTelegramDest = [tools.CNM]; +const appTelegramFinti = ['2', tools.CNM]; +const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET]; const printf = require('util').format; -const { User } = require('../models/user'); -const { CalZoom } = require('../models/calzoom'); -const { Nave } = require('../models/nave'); -const { MyBot } = require('../models/bot'); +const {User} = require('../models/user'); +const {CalZoom} = require('../models/calzoom'); +const {Nave} = require('../models/nave'); +const {MyBot} = require('../models/bot'); const shared_consts = require('../tools/shared_nodejs'); -const { ListaIngresso } = require('../models/listaingresso'); -const { MsgTemplate } = require('../models/msg_template'); +const {ListaIngresso} = require('../models/listaingresso'); +const {MsgTemplate} = require('../models/msg_template'); const emoji = require('node-emoji'); -const { Flotta } = require('../models/flotta'); +const {Flotta} = require('../models/flotta'); -const i18n = require("i18n"); +const i18n = require('i18n'); let url = process.env.URL || 'https://'; -const Benvenuto = emoji.get('heartbeat') + emoji.get('heartbeat') + emoji.get('heartbeat') + ' Benvenuto!'; +const Benvenuto = emoji.get('heartbeat') + emoji.get('heartbeat') + + emoji.get('heartbeat') + ' Benvenuto!'; const emo = { JOY: emoji.get('joy'), @@ -69,36 +71,115 @@ const emo = { PERSON: emoji.get('man-tipping-hand'), }; - MsgBot = { - CIAO: ['ciao', 'ciaoo', 'hola', 'holaa', 'hey', 'salve', 'buongiorno', 'buondi', 'ciao ❤️'], + CIAO: [ + 'ciao', + 'ciaoo', + 'hola', + 'holaa', + 'hey', + 'salve', + 'buongiorno', + 'buondi', + 'ciao ❤️'], CI_SEI: ['ci sei', 'c\'è qualcuno', 'c\'è nessuno'], CHI_SONO_IO: ['chi sono io', 'chi sono'], - COME_STAI: ['tutto bene', 'come stai', 'come stai', 'come va', 'come butta', 'come va oggi'], - COME_TI_CHIAMI: ['chi sei', 'come ti chiami', 'qual\'è il tuo nome', 'qual\'e\' il tuo nome', 'che lavoro fai', 'di cosa ti occupi'], + COME_STAI: [ + 'tutto bene', + 'come stai', + 'come stai', + 'come va', + 'come butta', + 'come va oggi'], + COME_TI_CHIAMI: [ + 'chi sei', + 'come ti chiami', + 'qual\'è il tuo nome', + 'qual\'e\' il tuo nome', + 'che lavoro fai', + 'di cosa ti occupi'], COSA_FAI: ['cosa fai', 'cosa combini', 'che fai'], QUANTI_ANNI_HAI: ['quanti anni hai', 'che età hai'], - SEI_LIBERO_STASERA: ['sei libera stasera', 'sei libero stasera', 'usciamo insieme', 'fare l\'amore con me', 'fare sesso', 'vuoi scopare', 'vuoi trombare'], - MI_TROVI_UN_MOROSO: ['trovi un moroso', 'una morosa', 'fidanzato', 'fidanzata', 'trovi un marito', 'trovi una moglie'], + SEI_LIBERO_STASERA: [ + 'sei libera stasera', + 'sei libero stasera', + 'usciamo insieme', + 'fare l\'amore con me', + 'fare sesso', + 'vuoi scopare', + 'vuoi trombare'], + MI_TROVI_UN_MOROSO: [ + 'trovi un moroso', + 'una morosa', + 'fidanzato', + 'fidanzata', + 'trovi un marito', + 'trovi una moglie'], CHAT_EMPOWER: ['chat empower'], - MASCHIO_FEMMINA: ['sei uomo o donna', 'sei maschio o femmina', 'sei ragazzo o ragazza', 'che sesso hai'], + MASCHIO_FEMMINA: [ + 'sei uomo o donna', + 'sei maschio o femmina', + 'sei ragazzo o ragazza', + 'che sesso hai'], DAMMI_UN_BACIO: ['dammi un bacio', 'baciami'], HAHA: ['hahaha', 'ahah', '😂'], MI_AMI: ['mi ami'], TI_AMO: ['ti amo', 'ti adoro', 'ti lovvo'], - GRAZIE: ['grazie ainy', 'grazie', 'grazie mille', 'graziee', 'grazie 😘', 'grazie😘'], + GRAZIE: [ + 'grazie ainy', + 'grazie', + 'grazie mille', + 'graziee', + 'grazie 😘', + 'grazie😘'], PRINCIPE_AZZURRO: ['principe azzurro'], - SPOSAMI: ['sposami', 'vuoi sposar', 'sei sposat', 'ci sposiamo', 'ti sposo', 'sei sposat', 'mi sposi'], + SPOSAMI: [ + 'sposami', + 'vuoi sposar', + 'sei sposat', + 'ci sposiamo', + 'ti sposo', + 'sei sposat', + 'mi sposi'], CHE_TEMPO_FA: ['che tempo'], NON_TROO_INVITATI: ['non trovo invitati', 'non riesco a trovare invitati'], - PAROLACCE: ['stronz', 'fanculo', 'fottiti', 'cagare', 'ammazzat', 'muori', 'cretino', 'stupido'], + PAROLACCE: [ + 'stronz', + 'fanculo', + 'fottiti', + 'cagare', + 'ammazzat', + 'muori', + 'cretino', + 'stupido'], COME_SI_CHIAMA: ['come si chiama'], - PROSSIMO_ZOOM: ['prossimo zoom', 'fare lo zoom', 'gli zoom', 'conferenz', 'zoom'], + PROSSIMO_ZOOM: [ + 'prossimo zoom', + 'fare lo zoom', + 'gli zoom', + 'conferenz', + 'zoom'], LAVAGNA: ['lavagna', 'Lavagna', 'LAVAGNA'], SEI_LIBERO: ['sei liber', 'sei sposat', 'sei fidanzat', 'sei single'], - AIUTO: ['help', 'aiuto', 'ho bisogno di', 'ho problemi', 'non riesco', 'mi puoi aiutare', 'mi aiuti', 'aiutami', 'posso chiederti', 'puoi aiutarmi'], + AIUTO: [ + 'help', + 'aiuto', + 'ho bisogno di', + 'ho problemi', + 'non riesco', + 'mi puoi aiutare', + 'mi aiuti', + 'aiutami', + 'posso chiederti', + 'puoi aiutarmi'], UOMO: ['uomo', 'maschio'], - SORPRESA: ['noo', 'davvero', 'sii', 'facciamo festa', 'è qui la festa', 'festa'], + SORPRESA: [ + 'noo', + 'davvero', + 'sii', + 'facciamo festa', + 'è qui la festa', + 'festa'], UGUALE: ['👍🏻', '✨', '❤🏻', '⭐', '❤', '❤❤', '🤩'], SI: ['si', 'yes'], NO: ['no', 'noo'], @@ -109,36 +190,37 @@ MsgBot = { }; const MsgRisp = { - CHAT_EMPOWER: 'Entra nella Chat EMPOWER !!!\n' + 'https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g ' + emo.PURPLE_HEART + emo.GIFT_HEART + emo.BLUE_HEART + CHAT_EMPOWER: 'Entra nella Chat EMPOWER !!!\n' + + 'https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g ' + emo.PURPLE_HEART + + emo.GIFT_HEART + emo.BLUE_HEART, }; function getemojibynumber(number) { if (number === 0) { - return emoji.get('zero') + return emoji.get('zero'); } else if (number === 1) { - return emoji.get('one') + return emoji.get('one'); } else if (number === 2) { - return emoji.get('two') + return emoji.get('two'); } else if (number === 3) { - return emoji.get('three') + return emoji.get('three'); } else if (number === 4) { - return emoji.get('four') + return emoji.get('four'); } else if (number === 5) { - return emoji.get('five') + return emoji.get('five'); } else if (number === 6) { - return emoji.get('six') + return emoji.get('six'); } else if (number === 7) { - return emoji.get('seven') + return emoji.get('seven'); } else if (number === 8) { - return emoji.get('height') + return emoji.get('height'); } else if (number === 9) { - return emoji.get('nine') + return emoji.get('nine'); } else { return number; } } - const Menu = { LANG_IT: emoji.get('flag-it') + ' Italiano', LANG_EN: emoji.get('flag-gb') + ' English', @@ -156,7 +238,8 @@ const Menu = { 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', + 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', @@ -171,7 +254,7 @@ const Menu = { SI: emoji.get('thumbsup') + ' SI', NO: emoji.get('thumbsdown') + ' NO', ESCI_DA_CHAT: emoji.get('incoming_envelope') + ' Esci dalla Conversazione', - NUOVOSITO: '' + NUOVOSITO: '', }, es: { ACCEDI: emo.PERSON + ' Entra', @@ -243,58 +326,74 @@ const CHEDI_SE_IMBARCARTI = 'chiedi_se_imbarcarti'; const InlineCmd = { VOGLIO_IMBARCARMI: 'w_imb', - NON_VOGLIO_IMBARCARMI: 'nw_imb' + NON_VOGLIO_IMBARCARMI: 'nw_imb', }; const InlineZoomConferma = { CONFERMA_ZOOM_PRESENZA: 'conf_pres', - NON_CONFERMA_ZOOM_PRESENZA: 'nonconf_pres' + NON_CONFERMA_ZOOM_PRESENZA: 'nonconf_pres', }; -const SendMsgCmd = [CONTA_SOLO, RICEVI_EMAIL, NOME_COGNOME, CHEDI_SE_IMBARCARTI]; +const SendMsgCmd = [ + CONTA_SOLO, + RICEVI_EMAIL, + NOME_COGNOME, + CHEDI_SE_IMBARCARTI]; - -const MenuNoLogin = { - it: { menu: [[Menu.LANG], [Menu.it.ASSISTENZA]] }, - es: { menu: [[Menu.LANG], [Menu.es.ASSISTENZA]] }, - fr: { menu: [[Menu.LANG], [Menu.fr.ASSISTENZA]] }, - si: { menu: [[Menu.LANG], [Menu.si.ASSISTENZA]] }, - pt: { menu: [[Menu.LANG], [Menu.pt.ASSISTENZA]] }, - enUs: { menu: [[Menu.LANG], [Menu.enUs.ASSISTENZA]] }, -}; +// const MenuNoLogin = { +// it: { menu: [[Menu.LANG], [Menu.it.ASSISTENZA]] }, +// es: { menu: [[Menu.LANG], [Menu.es.ASSISTENZA]] }, +// fr: { menu: [[Menu.LANG], [Menu.fr.ASSISTENZA]] }, +// si: { menu: [[Menu.LANG], [Menu.si.ASSISTENZA]] }, +// pt: { menu: [[Menu.LANG], [Menu.pt.ASSISTENZA]] }, +// enUs: { menu: [[Menu.LANG], [Menu.enUs.ASSISTENZA]] }, +// }; // const MenuStandard = { // it: { menu: [[Menu.it.LAVAGNA, Menu.it.LINK_CONDIVIDERE], [Menu.it.ZOOM, Menu.it.ASSISTENZA], [Menu.LANG]] }, // }; const MenuLang = { - it: { menu: [[Menu.LANG_IT, Menu.LANG_EN], [Menu.LANG_ES, Menu.LANG_FR], [Menu.LANG_SI, Menu.LANG_PT, Menu.it.INDIETRO]] }, + it: { + menu: [ + [Menu.LANG_IT, Menu.LANG_EN], + [Menu.LANG_ES, Menu.LANG_FR], + [Menu.LANG_SI, Menu.LANG_PT, Menu.it.INDIETRO]], + }, }; const MenuYesNo = { - it: { menu: [[Menu.it.SI, Menu.it.NO]] }, - es: { menu: [[Menu.es.SI, Menu.es.NO]] }, - fr: { menu: [[Menu.fr.SI, Menu.fr.NO]] }, - si: { menu: [[Menu.si.SI, Menu.si.NO]] }, - pt: { menu: [[Menu.pt.SI, Menu.pt.NO]] }, - enUs: { menu: [[Menu.enUs.SI, Menu.enUs.NO]] }, + it: {menu: [[Menu.it.SI, Menu.it.NO]]}, + es: {menu: [[Menu.es.SI, Menu.es.NO]]}, + fr: {menu: [[Menu.fr.SI, Menu.fr.NO]]}, + si: {menu: [[Menu.si.SI, Menu.si.NO]]}, + pt: {menu: [[Menu.pt.SI, Menu.pt.NO]]}, + enUs: {menu: [[Menu.enUs.SI, Menu.enUs.NO]]}, }; const MenuAdmin = { - it: { menu: [[Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.it.INDIETRO], [Menu.MSGPAOLO]] }, + it: { + menu: [ + [Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.it.INDIETRO], + [Menu.MSGPAOLO]], + }, }; const MenuSend = { - it: { menu: [[CONTA_SOLO, RICEVI_EMAIL, NOME_COGNOME], [CHEDI_SE_IMBARCARTI, Menu.it.INDIETRO]] }, + it: { + menu: [ + [CONTA_SOLO, RICEVI_EMAIL, NOME_COGNOME], + [CHEDI_SE_IMBARCARTI, Menu.it.INDIETRO]], + }, }; const MenuChat = { - it: { menu: [[Menu.it.ESCI_DA_CHAT, Menu.it.INDIETRO]] }, - es: { menu: [[Menu.es.ESCI_DA_CHAT, Menu.es.INDIETRO]] }, - fr: { menu: [[Menu.fr.ESCI_DA_CHAT, Menu.fr.INDIETRO]] }, - si: { menu: [[Menu.si.ESCI_DA_CHAT, Menu.si.INDIETRO]] }, - pt: { menu: [[Menu.pt.ESCI_DA_CHAT, Menu.pt.INDIETRO]] }, - enUs: { menu: [[Menu.enUs.ESCI_DA_CHAT, Menu.enUs.INDIETRO]] }, + it: {menu: [[Menu.it.ESCI_DA_CHAT, Menu.it.INDIETRO]]}, + es: {menu: [[Menu.es.ESCI_DA_CHAT, Menu.es.INDIETRO]]}, + fr: {menu: [[Menu.fr.ESCI_DA_CHAT, Menu.fr.INDIETRO]]}, + si: {menu: [[Menu.si.ESCI_DA_CHAT, Menu.si.INDIETRO]]}, + pt: {menu: [[Menu.pt.ESCI_DA_CHAT, Menu.pt.INDIETRO]]}, + enUs: {menu: [[Menu.enUs.ESCI_DA_CHAT, Menu.enUs.INDIETRO]]}, }; const Sex = { @@ -336,7 +435,8 @@ const StatusMSGALL = { }; const txt = { - MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Scegli una voce di menu:' + emoji.get('dizzy'), + MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Scegli una voce di menu:' + + emoji.get('dizzy'), MSG_ASK_USERNAME_BO: 'Scrivi nel messaggio lo username o la email con cui ti sei registrato sul sito di %s:', MSG_ERRORE_USERNAME: 'Attenzione! Devi inserire solo lo username (40 caratteri massimo)', MSG_ERRORE_USERNAME_NOT_FOUND: 'Per Completare la Verifica Telegram BOT, devi ora scrivere qui sotto nel messaggio l\'Username OPPURE la email con cui ti sei registrato sul sito', @@ -344,25 +444,33 @@ const txt = { MSG_OPERAZ_ANNULLATA: 'Operazione Annullata', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Attenzione! Devi inserire solo il codice a 6 cifre', MSG_VERIFY_CODE: '1. Ora ritorna sul sito:\n%s\n2. Copia il codice di Autenticazione (di 6 cifre) che troverai scritto in alto\n3. Scrivilo (o incollalo) qui sotto come messaggio:', - MSG_ERR_VERIFY_CODE: 'Codice di Verifica Errato!' + emo.EXCLAMATION_MARK + '\nControlla sul sito %s e riscrivi il nuovo codice di 6 cifre.', - MSG_VERIFY_OK: emoji.get('grinning') + ' Benvenuto %s! Ti sei correttamente verificato con il BOT. ' + '\nSono il tuo assistente virtuale.\n' + - 'Questo Bot ti servirà per vedere velocemente la tua Lavagna e per ricevere Importanti avvisi su come procedere il tuo cammino.\n\nUsa il menu qui sotto per controllare la tua situazione.' + emo.GREEN_HEART, + MSG_ERR_VERIFY_CODE: 'Codice di Verifica Errato!' + emo.EXCLAMATION_MARK + + '\nControlla sul sito %s e riscrivi il nuovo codice di 6 cifre.', + MSG_VERIFY_OK: emoji.get('grinning') + + ' Benvenuto %s! Ti sei correttamente verificato con il BOT. ' + + '\nSono il tuo assistente virtuale.\n', MSG_ERR_UNKNOWN_VERIFY_CODE: 'Errore durante il salvataggio sul Server. Riprovare piú tardi', MSG_EXIT_TELEGRAM: 'L\'account è stato ora scollegato da questo Telegram BOT.', MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Si è appena Registrato "%s', - MSG_APORTADOR_ASK_CONFIRM: emo.QUESTION_MARK + ' Si vuole confermare di Conoscere "%s ?', + MSG_APORTADOR_ASK_CONFIRM: emo.QUESTION_MARK + + ' Si vuole confermare di Conoscere "%s ?', MSG_APORTADOR_CONFIRMED: emo.SUN + ' %s è stato confermato correttamente!', - MSG_APORTADOR_DEST_CONFIRMED: emo.SUN + ' Sei stato Verificato correttamente da %s!', - MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK + ' Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s. Contattalo se lo conosci, oppure trova un altro invitante !', - MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK + ' %s Non è stato Verificato !', + MSG_APORTADOR_DEST_CONFIRMED: emo.SUN + + ' Sei stato Verificato correttamente da %s!', + MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK + + ' Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s. Contattalo se lo conosci, oppure trova un altro invitante !', + MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK + + ' %s Non è stato Verificato !', MSG_ISCRITTO_CONACREIS: emo.FIRE + ' Si è appena Iscritto al Conacreis "%s"', MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !', MSG_MSG_TOSENT: emoji.get('envelope') + ' Messaggi da Inviare', - MSG_MSG_INCORSO: emoji.get('envelope') + ' messaggi in corso... Inviati attualmente', + MSG_MSG_INCORSO: emoji.get('envelope') + + ' messaggi in corso... Inviati attualmente', }; const txt_es = { - MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Elija un elemento del menú:' + emoji.get('dizzy'), + MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Elija un elemento del menú:' + + emoji.get('dizzy'), MSG_ASK_USERNAME_BO: 'Escriba en el mensaje el nombre de usuario o el correo electrónico con el que se registró en el sitio de %s:', MSG_ERRORE_USERNAME: '¡Atención! Debes introducir sólo el nombre de usuario (40 caracteres como máximo)', MSG_ERRORE_USERNAME_NOT_FOUND: 'Para completar la verificación del telegrama BOT, ahora debe escribir en el mensaje el nombre de usuario o el correo electrónico con el que se registró en el sitio.:', @@ -370,19 +478,27 @@ const txt_es = { MSG_OPERAZ_ANNULLATA: 'Operación cancelada', MSG_ERRORE_VERIFY_CODE_MAXLEN: '¡Atención! Sólo tienes que introducir el código de 6 dígitos', MSG_VERIFY_CODE: '1. Ahora, de vuelta en el sitio web:\n%s\n2. Copie el código de autenticación (6 dígitos) que encontrará escrito en la parte superior de la página\n3. Escríbelo (o pégalo) abajo como un mensaje:', - MSG_ERR_VERIFY_CODE: 'Código de verificación incorrecto!' + emo.EXCLAMATION_MARK + '\nComprueba en el sitio %s y reescribe el nuevo código de 6 dígitos.', - MSG_VERIFY_OK: emoji.get('grinning') + ' Bienvenido %s! Ha verificado correctamente con el BOT. ' + '\nSoy su asistente virtual.\nContinúa la guía paso a paso de vuelta a la página web.\n\n' + - 'Este chat le ayudará a ver rápidamente su pizarra y recibir alertas importantes sobre cómo proceder.\n\nUtilice el menú de abajo para comprobar su situación.' + emo.GREEN_HEART, + MSG_ERR_VERIFY_CODE: 'Código de verificación incorrecto!' + + emo.EXCLAMATION_MARK + + '\nComprueba en el sitio %s y reescribe el nuevo código de 6 dígitos.', + MSG_VERIFY_OK: emoji.get('grinning') + + ' Bienvenido %s! Ha verificado correctamente con el BOT. ' + + '\nSoy su asistente virtual.\nContinúa la guía paso a paso de vuelta a la página web.\n\n' + + 'Este chat le ayudará a ver rápidamente su pizarra y recibir alertas importantes sobre cómo proceder.\n\nUtilice el menú de abajo para comprobar su situación.' + + emo.GREEN_HEART, MSG_ERR_UNKNOWN_VERIFY_CODE: 'Error al guardar en el servidor. Inténtalo de nuevo más tarde.', MSG_EXIT_TELEGRAM: 'La cuenta ha sido desconectada de Telegram BOT.', - MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Acaba de registrarse "%s (n. %s)"\n(Invitado de %s)', + MSG_APORTADOR_USER_REGISTERED: emo.FIRE + + ' Acaba de registrarse "%s (n. %s)"\n(Invitado de %s)', MSG_MSG_SENT: emoji.get('envelope') + ' Mensajes enviados !', MSG_MSG_TOSENT: emoji.get('envelope') + ' Mensajes a enviar', - MSG_MSG_INCORSO: emoji.get('envelope') + ' mensajes en progreso... Enviado actualmente', + MSG_MSG_INCORSO: emoji.get('envelope') + + ' mensajes en progreso... Enviado actualmente', }; const txt_fr = { - MSG_SCEGLI_MENU: emoji.get('dizzy') + 'Choisissez un élément de menu:' + emoji.get('dizzy'), + MSG_SCEGLI_MENU: emoji.get('dizzy') + 'Choisissez un élément de menu:' + + emoji.get('dizzy'), MSG_ASK_USERNAME_BO: 'Écrivez dans le message l\'username ou l\'e-mail avec lequel vous vous êtes enregistré sur le site de %s: ', MSG_ERRORE_USERNAME: 'Attention! Vous devez insérer seulement l’username (40 caractères maximum)', MSG_ERRORE_USERNAME_NOT_FOUND: 'Pour Compléter la Vérification Telegram BOT, vous devez maintenant écrire dans le message ci-dessous l\'Username ou l\'adresse e-mail avec lequel vous vous êtes inscrit sur le site: ', @@ -390,15 +506,22 @@ const txt_fr = { MSG_OPERAZ_ANNULLATA: 'Opération Annullée', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Attention! Vous devez insérer seulement le code à 6 chiffres', MSG_VERIFY_CODE: '1. Ᾱ présent retournez sur le site:\n%s\n2. Copiez le Code d’Authentification (de 6 chiffres) che vous trouverez écrit en haut \n3. Ecrivez-le (ou copiez-le) ci-dessous comme message:', - MSG_ERR_VERIFY_CODE: ' Code de vérification incorrect!' + emo.EXCLAMATION_MARK + '\nControllez sur le site %s et réécrivez le nouveau code à 6 chiffres.', - MSG_VERIFY_OK: emoji.get('grinning') + ' Bienvenu(e) %s! Vous vous êtes vérifié avec succès avec le BOT. ' + '\nJe suis ton assistant virtuel.\n' + - "Continuez le guide étape par étape en revenant sur le site. \n\nCe chat vous servira pour voir rapidement votre tableau de bord et recevoir des avis importants sur la marche à suivre pour continuer votre parcours.\n\nUtilisez le menu ci-dessous pour vérifier votre situation. " + emo.GREEN_HEART, + MSG_ERR_VERIFY_CODE: ' Code de vérification incorrect!' + + emo.EXCLAMATION_MARK + + '\nControllez sur le site %s et réécrivez le nouveau code à 6 chiffres.', + MSG_VERIFY_OK: emoji.get('grinning') + + ' Bienvenu(e) %s! Vous vous êtes vérifié avec succès avec le BOT. ' + + '\nJe suis ton assistant virtuel.\n' + + 'Continuez le guide étape par étape en revenant sur le site. \n\nCe chat vous servira pour voir rapidement votre tableau de bord et recevoir des avis importants sur la marche à suivre pour continuer votre parcours.\n\nUtilisez le menu ci-dessous pour vérifier votre situation. ' + + emo.GREEN_HEART, MSG_ERR_UNKNOWN_VERIFY_CODE: 'Erreur lors de l\'enregistrement sur le serveur. Retentez plus tard', MSG_EXIT_TELEGRAM: 'L\'account a été déconnecté de Telegram BOT.', - MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Vous venez à peine de vous inscrire "%s (n)', + MSG_APORTADOR_USER_REGISTERED: emo.FIRE + + ' Vous venez à peine de vous inscrire "%s (n)', MSG_MSG_SENT: emoji.get('envelope') + ' Messages envoyés !', MSG_MSG_TOSENT: emoji.get('envelope') + ' Messages à envoyer', - MSG_MSG_INCORSO: emoji.get('envelope') + ' messages en cours... Actuellement envoyé', + MSG_MSG_INCORSO: emoji.get('envelope') + + ' messages en cours... Actuellement envoyé', }; const txt_si = { @@ -410,16 +533,22 @@ const txt_si = { MSG_OPERAZ_ANNULLATA: 'Operacija preklicana', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Pozor! Vstavi D mestno kodo', MSG_VERIFY_CODE: '1. Vrni se na spletno strani: \n%s\n2. Kopiraj kodo Authenticazione (6 mestno) ki jo najdeš zgoraj zapisano\n3. Napiši (ali prilepi) tu spodaj kot sporočilo: ', - MSG_ERR_VERIFY_CODE: 'Napačna koda za preverjanje!' + emo.EXCLAMATION_MARK + '\nPreveri na strani %s in ponovno napiši 6 mestno kodo.', - MSG_VERIFY_OK: emoji.get('grinning') + 'Dobrodošel %s! Pravilno ste se preveriliz BOT. ' + ' \nsem tvoj virtualni asisten.\n ' + - 'Vodenje se nadeljuje z vodenimi koraki, ko se vrneš na spletno stran. \n\nTa klepet ti bo služil za hitri pregled tvoje table in za sprejemanje pomembnih obvestil glede poteka tvojega potovanja. \n\nUporabite meni tu spodaj, da lahko kontrolirate svojo situacijo. ' + emo.GREEN_HEART, + MSG_ERR_VERIFY_CODE: 'Napačna koda za preverjanje!' + emo.EXCLAMATION_MARK + + '\nPreveri na strani %s in ponovno napiši 6 mestno kodo.', + MSG_VERIFY_OK: emoji.get('grinning') + + 'Dobrodošel %s! Pravilno ste se preveriliz BOT. ' + + ' \nsem tvoj virtualni asisten.\n ' + + 'Vodenje se nadeljuje z vodenimi koraki, ko se vrneš na spletno stran. \n\nTa klepet ti bo služil za hitri pregled tvoje table in za sprejemanje pomembnih obvestil glede poteka tvojega potovanja. \n\nUporabite meni tu spodaj, da lahko kontrolirate svojo situacijo. ' + + emo.GREEN_HEART, MSG_ERR_UNKNOWN_VERIFY_CODE: 'Napaka strežnika.Poskusi kasneje ', MSG_EXIT_TELEGRAM: 'Račun se nahaja v programu Telegram BOT.', - MSG_APORTADOR_USER_REGISTERED: emo.FIRE + 'Registracija registracije %s (n. %s)\n(povabil ga %s)', + MSG_APORTADOR_USER_REGISTERED: emo.FIRE + + 'Registracija registracije %s (n. %s)\n(povabil ga %s)', }; const txt_en = { - MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Choose a menu item:' + emoji.get('dizzy'), + MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Choose a menu item:' + + emoji.get('dizzy'), MSG_ASK_USERNAME_BO: 'Write in the message the username or email with which you registered on the site of %s:', MSG_ERRORE_USERNAME: 'Attention! You must enter only the username (40 characters maximum)', MSG_ERRORE_USERNAME_NOT_FOUND: 'To complete the Telegram BOT Verification, you must now write below in the message the Username OR the email with which you registered on the website:', @@ -427,21 +556,28 @@ const txt_en = { MSG_OPERAZ_ANNULLATA: 'Operation Cancelled', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Attention! You only need to enter the 6-digit code', MSG_VERIFY_CODE: '1. Now return to the website: %s\n' + - '2. Copy the Authentication code (of 6 digits) that you will find written at the top\n' + - '3. Write it (or paste it) below as a message:', - MSG_ERR_VERIFY_CODE: 'Incorrect Verification Code!' + emo.EXCLAMATION_MARK + '\nCheck on the site %s and rewrite the new 6-digit code.', - MSG_VERIFY_OK: emoji.get('grinning') + ' Welcome %s! You have correctly verified yourself with BOT. ' + '\nI am your virtual assistant.\n' + - 'Continue the step-by-step guide back to the website.\n\nThis chat will help you to quickly see your DashBoard and receive important alerts on how to proceed on your path.\n\nUse the menu below to check your situation.' + emo.GREEN_HEART, + '2. Copy the Authentication code (of 6 digits) that you will find written at the top\n' + + '3. Write it (or paste it) below as a message:', + MSG_ERR_VERIFY_CODE: 'Incorrect Verification Code!' + emo.EXCLAMATION_MARK + + '\nCheck on the site %s and rewrite the new 6-digit code.', + MSG_VERIFY_OK: emoji.get('grinning') + + ' Welcome %s! You have correctly verified yourself with BOT. ' + + '\nI am your virtual assistant.\n' + + 'Continue the step-by-step guide back to the website.\n\nThis chat will help you to quickly see your DashBoard and receive important alerts on how to proceed on your path.\n\nUse the menu below to check your situation.' + + emo.GREEN_HEART, MSG_ERR_UNKNOWN_VERIFY_CODE: 'Error while saving to the Server. Try again later', MSG_EXIT_TELEGRAM: 'The account has now been disconnected from this Telegram BOT.', - MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' He/She\'s just registered "%s (n. %s)"\n(Invited from %s)', + MSG_APORTADOR_USER_REGISTERED: emo.FIRE + + ' He/She\'s just registered "%s (n. %s)"\n(Invited from %s)', MSG_MSG_SENT: emoji.get('envelope') + ' Sent Messages !', MSG_MSG_TOSENT: emoji.get('envelope') + ' Messages to Send', - MSG_MSG_INCORSO: emoji.get('envelope') + ' messages in progress... Currently sent', + MSG_MSG_INCORSO: emoji.get('envelope') + + ' messages in progress... Currently sent', }; const txt_pt = { - MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Escolha um item do menu:' + emoji.get('dizzy'), + MSG_SCEGLI_MENU: emoji.get('dizzy') + ' Escolha um item do menu:' + + emoji.get('dizzy'), MSG_ASK_USERNAME_BO: 'Escreva na mensagem o nome de usuário ou e-mail com o qual se registrou no site de %s:', MSG_ERRORE_USERNAME: 'Atenção! Você deve inserir apenas o nome de usuário (40 caracteres no máximo)', MSG_ERRORE_USERNAME_NOT_FOUND: 'Para completar a Verificação do Telegrama BOT, você deve agora escrever abaixo na mensagem o Nome de Usuário OU o e-mail com o qual você se registrou no site:', @@ -449,24 +585,28 @@ const txt_pt = { MSG_OPERAZ_ANNULLATA: 'Operação Cancelada', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Atenção! Você só precisa digitar o código de 6 dígitos', MSG_VERIFY_CODE: '1. Agora de volta ao site:\n%s\n2. Copie o código de autenticação (6 dígitos) que você encontrará escrito na parte superior da página\n3. Escreva-o (ou cole-o) abaixo como uma mensagem:', - MSG_ERR_VERIFY_CODE: 'Código de Verificação Incorrecto!' + emo.EXCLAMATION_MARK + '\nCódigo de Verificação ErradoCheque no local %s e reescreva o novo código de 6 dígitos.', - MSG_VERIFY_OK: emoji.get('grinning') + ' Bem-vindo %s! Você verificou corretamente com BOT. ' + '\nEu sou o vosso assistente virtual.\n' + - 'Continue o guia passo-a-passo de volta ao site.\n\nEste chat vai ajudá-lo a ver rapidamente o seu Quadro Negro e a receber alertas importantes sobre como proceder..\n\n' + - 'Use o menu abaixo para verificar a sua situação.' + emo.GREEN_HEART, + MSG_ERR_VERIFY_CODE: 'Código de Verificação Incorrecto!' + + emo.EXCLAMATION_MARK + + '\nCódigo de Verificação ErradoCheque no local %s e reescreva o novo código de 6 dígitos.', + MSG_VERIFY_OK: emoji.get('grinning') + + ' Bem-vindo %s! Você verificou corretamente com BOT. ' + + '\nEu sou o vosso assistente virtual.\n' + + 'Continue o guia passo-a-passo de volta ao site.\n\nEste chat vai ajudá-lo a ver rapidamente o seu Quadro Negro e a receber alertas importantes sobre como proceder..\n\n' + + 'Use o menu abaixo para verificar a sua situação.' + emo.GREEN_HEART, MSG_ERR_UNKNOWN_VERIFY_CODE: 'Erro ao salvar no Servidor. Tente novamente mais tarde.', MSG_EXIT_TELEGRAM: 'A conta foi agora desconectada deste Telegrama BOT.', - MSG_APORTADOR_USER_REGISTERED: emo.FIRE + ' Acabou de se registar "%s (n. %s)"\n(Convidado por %s)', + MSG_APORTADOR_USER_REGISTERED: emo.FIRE + + ' Acabou de se registar "%s (n. %s)"\n(Convidado por %s)', MSG_MSG_SENT: emoji.get('envelope') + ' Mensagens Enviadas !', MSG_MSG_TOSENT: emoji.get('envelope') + ' Mensagens a enviar', - MSG_MSG_INCORSO: emoji.get('envelope') + ' mensagens em progresso... Actualmente enviado', + MSG_MSG_INCORSO: emoji.get('envelope') + + ' mensagens em progresso... Actualmente enviado', }; - const TelegramBot = require('node-telegram-bot-api'); const ADMIN_IDTELEGRAM_TEST = 5022837609; //Perseo - module.exports = { ADMIN_IDTELEGRAM_SERVER: '12429864', //Paolo @@ -475,10 +615,10 @@ module.exports = { phase: { REGISTRATION: 1, - ISCRIZIONE_CONACREIS: 2 + ISCRIZIONE_CONACREIS: 2, }, - getFormDaMostrare: function (idapp, myfunc, myuser) { + getFormDaMostrare: function(idapp, myfunc, myuser) { FormDaMostrare = null; @@ -489,12 +629,14 @@ module.exports = { { text: 'Conferma Presenza Zoom', // callback_data: { action: InlineZoomConferma.CONFERMA_ZOOM_PRESENZA, username: myuser.username } - callback_data: InlineZoomConferma.CONFERMA_ZOOM_PRESENZA + '|' + myuser.username + callback_data: InlineZoomConferma.CONFERMA_ZOOM_PRESENZA + '|' + + myuser.username, }, { text: 'Annulla Presenza Zoom', // callback_data: { action: InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA, username: myuser.username } - callback_data: InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA + '|' + myuser.username + callback_data: InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA + '|' + + myuser.username, }, ]); } @@ -502,11 +644,11 @@ module.exports = { return FormDaMostrare; }, - getCiao: function (idapp, username, lang) { + getCiao: function(idapp, username, lang) { return tools.gettranslate('CIAO', lang) + ' ' + username + '!\n'; }, - notifyToTelegram: async function (phase, mylocalsconf) { + notifyToTelegram: async function(phase, mylocalsconf) { let userdest = mylocalsconf.user.aportador_solidario; let langdest = mylocalsconf.user.lang; let NameFrom = `${mylocalsconf.user.name} ${mylocalsconf.user.surname}`; @@ -523,16 +665,17 @@ module.exports = { let text = ''; if (phase === this.phase.REGISTRATION) { if (userdest) { - NameFrom = await User.getNameSurnameByUsername(mylocalsconf.idapp, userdest) + aportador; + NameFrom = await User.getNameSurnameByUsername(mylocalsconf.idapp, + userdest) + aportador; aportador = NameFrom; } - text = printf(getstr(langdest, 'MSG_APORTADOR_USER_REGISTERED'), `${mylocalsconf.user.name} ${mylocalsconf.user.surname} (${mylocalsconf.user.username})`); + text = printf(getstr(langdest, 'MSG_APORTADOR_USER_REGISTERED'), + `${mylocalsconf.user.name} ${mylocalsconf.user.surname} (${mylocalsconf.user.username})`); } - let addtext = ""; + let addtext = ''; let rismsg = null; - if (!!mylocalsconf.user.aportador_solidario) { addtext = '[Inviato a ' + NameFrom + ']:' + '\n'; rismsg = await this.sendMsgTelegram(mylocalsconf.idapp, userdest, text); @@ -549,35 +692,38 @@ module.exports = { const msgNo = printf(getstr(langdest, 'MSG_APORTADOR_NOT_CONFIRMED'), `${mylocalsconf.user.name + ' ' + mylocalsconf.user.surname}`); - const msgDestyes = printf(getstr(langdest, 'MSG_APORTADOR_DEST_CONFIRMED'), + const msgDestyes = printf( + getstr(langdest, 'MSG_APORTADOR_DEST_CONFIRMED'), `${mylocalsconf.user.name + ' ' + mylocalsconf.user.surname}`); - const msgDestNo = printf(getstr(langdest, 'MSG_APORTADOR_DEST_NOT_CONFIRMED'), + const msgDestNo = printf( + getstr(langdest, 'MSG_APORTADOR_DEST_NOT_CONFIRMED'), `${mylocalsconf.user.name + ' ' + mylocalsconf.user.surname}`); const cl = getclTelegByidapp(mylocalsconf.idapp); if (cl) { await cl.createIfNotExist(rismsg); - await cl.menumsgDomanda(rismsg, Cmd.VALIDATE_REGISTRATION, Destin.DOMANDA, userdest, '', domanda, msgyes, msgNo, msgDestyes, msgDestNo, mylocalsconf.user.username); + await cl.menumsgDomanda(rismsg, Cmd.VALIDATE_REGISTRATION, + Destin.DOMANDA, userdest, '', domanda, msgyes, msgNo, msgDestyes, + msgDestNo, mylocalsconf.user.username); } } }, - - notifyIscrizioneToTelegram: async function (phase, mylocalsconf) { + notifyIscrizioneToTelegram: async function(phase, mylocalsconf) { let langdest = mylocalsconf.iscritto.lang; let NameFrom = `${mylocalsconf.iscritto.name} ${mylocalsconf.iscritto.surname}`; let text = printf(getstr(langdest, 'MSG_ISCRITTO_CONACREIS'), NameFrom); - let addtext = ""; + let addtext = ''; await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text); }, - - sendMsgTelegramToTheManagers: async function (idapp, text, onlyintofile = false, MyForm = null) { + sendMsgTelegramToTheManagers: async function( + idapp, text, onlyintofile = false, MyForm = null) { tools.writeManagersLog(text); @@ -585,16 +731,18 @@ module.exports = { const usersmanagers = await User.getusersManagers(idapp); if (usersmanagers) { for (const rec of usersmanagers) { - await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm); - await tools.snooze(100) + await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, + emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm); + await tools.snooze(100); } } } - return true + return true; }, - sendMsgTelegramToTheManagersAndZoomeri: async function (idapp, text, onlyintofile, MyForm = null) { + sendMsgTelegramToTheManagersAndZoomeri: async function( + idapp, text, onlyintofile, MyForm = null) { tools.writeManagersLog(text); @@ -603,18 +751,19 @@ module.exports = { const usersmanagers = await User.getusersManagers(idapp); if (usersmanagers) { for (const rec of usersmanagers) { - await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm); - await tools.snooze(100) + await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, + emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm); + await tools.snooze(100); } } } - return true + return true; }, - getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) { + getMsgByTipoMsg: async function(mydata, lang, user, sonosognatore) { if (!!mydata.msgextra) { - return { body: mydata.msgextra, title: '' }; + return {body: mydata.msgextra, title: ''}; } let title = ''; @@ -622,16 +771,25 @@ module.exports = { if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) { if (sonosognatore) - msg = 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 - 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) { + 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) { if (!!mydata.username_mitt) { - msg = '[' + tools.gettranslate('MSG_SEND_FROM', lang) + ' ' + mydata.username_mitt + ']:' + tools.ACAPO; + msg = '[' + tools.gettranslate('MSG_SEND_FROM', lang) + ' ' + + mydata.username_mitt + ']:' + tools.ACAPO; } msg += mydata.msgpar1; } else if (mydata.tipomsg >= 1000) { - const ris = await MsgTemplate.getMsgByLang(user.idapp, mydata.tipomsg, lang); + const ris = await MsgTemplate.getMsgByLang(user.idapp, mydata.tipomsg, + lang); msg = ris.body; title = ris.title; } @@ -660,9 +818,13 @@ module.exports = { if (!!mydata.flotta) { // SOSTITUISCI LE PAROLE CHIAVI if (!!mydata.flotta.date_start) - msg = msg.replace('{date_start}', tools.getstrDateLongTot(new Date(mydata.flotta.date_start), user.lang)); + msg = msg.replace('{date_start}', + tools.getstrDateLongTot(new Date(mydata.flotta.date_start), + user.lang)); if (!!mydata.flotta.date_close) - msg = msg.replace('{date_close}', tools.getstrDateLongTot(new Date(mydata.flotta.date_close), user.lang)); + msg = msg.replace('{date_close}', + tools.getstrDateLongTot(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) @@ -676,13 +838,16 @@ module.exports = { if (!!mydata.flotta.sognatore_nomecognome) msg = msg.replace('{sognatore}', mydata.flotta.sognatore_nomecognome); if (!!mydata.flotta.sognatore_nomecognome) - msg = msg.replace('{flotta}', mydata.flotta.riga + '.' + Math.ceil(mydata.flotta.col_prima / 8) + ' - ' + mydata.flotta.riga + '.' + Math.ceil(mydata.flotta.col_ultima / 8)); + msg = msg.replace('{flotta}', + mydata.flotta.riga + '.' + Math.ceil(mydata.flotta.col_prima / 8) + + ' - ' + mydata.flotta.riga + '.' + + Math.ceil(mydata.flotta.col_ultima / 8)); } - return { body: msg, title }; + return {body: msg, title}; }, - sendMsgTelegramToNave: async function (idapp, mydata, res) { + sendMsgTelegramToNave: async function(idapp, mydata, res) { let nummsgtosend = 0; let nummsgsent = 0; let strout = ''; @@ -695,32 +860,34 @@ module.exports = { let strflotta = ''; if (flotta) { strflotta = Flotta.getStrFlotta(flotta); - arrnavi = await Nave.getusersByFlotta(idapp, flotta.riga, flotta.col_prima, flotta.col_ultima); + 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 }); + arrnavi = await User.find({idapp, username: flotta.sognatore}); } } else { arrnavi = await Nave.getusersByNave(idapp, mydata.navemediatore); } - // console.log('usersmanagers', usersmanagers); - let mymsg = ""; - let mymsgprimo = ""; + let mymsg = ''; + let mymsgprimo = ''; tipomsgorig = mydata.tipomsg; if (arrnavi) { if (!flotta) - tools.writeManagersLog('sendMsgTelegramToNave', mydata.navemediatore.riga + '.' + mydata.navemediatore.col); + 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); + tools.writeFlottaLog(idapp, mystrmsg, flotta.riga, + flotta.col_prima); } } @@ -735,7 +902,8 @@ module.exports = { } else { user = await User.findByIndOrder(idapp, nave.ind_order); - if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_SOLLECITO_DONATORI_NO_DONO) { + 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; @@ -747,7 +915,8 @@ module.exports = { if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_EFFETTUA_IL_DONO) { user = null; } - if (mydata.tipomsg === tools.TipoMsg.SEND_MSG_SOLLECITO_DONATORI_NO_DONO) { + if (mydata.tipomsg === + tools.TipoMsg.SEND_MSG_SOLLECITO_DONATORI_NO_DONO) { user = null; } } else { @@ -765,7 +934,8 @@ module.exports = { const lang = user.lang; const idteleg = user.profile.teleg_id; mydata.nave = nave; - const rismsg = await this.getMsgByTipoMsg(mydata, lang, user, false); + const rismsg = await this.getMsgByTipoMsg(mydata, lang, user, + false); mymsg = rismsg.body; mytitle = rismsg.title; @@ -776,18 +946,21 @@ module.exports = { } if (!!idteleg) { - strout += '\n (' + index + ') ' + user.name + ' ' + user.surname + ':'; + strout += '\n (' + index + ') ' + user.name + ' ' + user.surname + + ':'; if (mydata.inviareale) { - await this.sendMsgTelegramByIdTelegram(idapp, idteleg, mymsg, undefined, undefined, true); + await this.sendMsgTelegramByIdTelegram(idapp, idteleg, mymsg, + undefined, undefined, true); await tools.snooze(100); 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 - }); + await sendemail.sendEmail_ByText(user.lang, user.email, user, + idapp, { + emailbody: mymsg, + emailtitle: mytitle, + }); strout += ' -> (EMAIL OK)'; } @@ -803,7 +976,9 @@ module.exports = { } if (!mydata.inviareale) { - await this.sendMsgTelegram(idapp, res.req.user.username, 'TEST INVIO MESSAGGIO:\n' + mymsgprimo + '\n\n(Messaggi da Inviare: ' + nummsgtosend + ')'); + await this.sendMsgTelegram(idapp, res.req.user.username, + 'TEST INVIO MESSAGGIO:\n' + mymsgprimo + + '\n\n(Messaggi da Inviare: ' + nummsgtosend + ')'); } if ((nummsgsent > 1) && (mydata.inviareale)) { @@ -811,14 +986,19 @@ module.exports = { let msg = ''; if (!!flotta) { if (!!mydata.tipomsg) { - msg = 'Flotta ' + strflotta + '): ' + tools.getStrMsgByTipoMsg(mydata.tipomsg) + '\n' + mymsg; + msg = 'Flotta ' + strflotta + '): ' + + tools.getStrMsgByTipoMsg(mydata.tipomsg) + '\n' + mymsg; } else { - msg = 'Inviato messaggio a tutta la FLOTTA DA ' + flotta.riga + '.' + flotta.col_prima + ' A ' + flotta.riga + '.' + flotta.col_ultima + ' \n' + mymsg; + 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; + msg = 'Inviato messaggio a tutti i Donatori della Nave ' + + mydata.navemediatore.riga + '.' + mydata.navemediatore.col + + '\n' + mymsg; } - await this.sendMsgTelegramToTheManagers(idapp, msg) + await this.sendMsgTelegramToTheManagers(idapp, msg); } catch (e) { } @@ -855,22 +1035,22 @@ module.exports = { if (nummsgsent > 0) { if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) { const fields_to_update = { - sent_msg_howto_make_gift: true + sent_msg_howto_make_gift: true, }; - await Nave.findOneAndUpdate({ _id: mydata.navemediatore.id }, { $set: fields_to_update }, { new: false }); + await Nave.findOneAndUpdate({_id: mydata.navemediatore.id}, + {$set: fields_to_update}, {new: false}); } } - - return { nummsgsent, strout }; + return {nummsgsent, strout}; } catch (e) { console.error(e.message); strout = 'Error: ' + e.message + '\n' + strout; - return { nummsgsent, strout }; + return {nummsgsent, strout}; } }, - sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) { + sendMsgTelegramToTheAdmin: async function(idapp, text, senzaintestazione) { const usersmanagers = await User.getusersManagers(idapp); let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': '; @@ -880,40 +1060,42 @@ module.exports = { if (usersmanagers) { for (const rec of usersmanagers) { if (User.isAdmin(rec.perm)) { - this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, intestaz + text, undefined, undefined, true); - await tools.snooze(300) + this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, + intestaz + text, undefined, undefined, true); + await tools.snooze(300); } } } - return true + return true; }, - sendMsgTelegramToALL: async function (idapp, text) { + sendMsgTelegramToALL: async function(idapp, text) { const usersall = await User.getUsersTelegALL(idapp); if (usersall) { for (const rec of usersall) { this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, text); - await tools.snooze(300) + await tools.snooze(300); } } }, - sendMsgTelegram: async function (idapp, username, text, alsotomanagers, username_mitt) { - const { User } = require('../models/user'); + sendMsgTelegram: async function( + idapp, username, text, alsotomanagers, username_mitt) { + const {User} = require('../models/user'); const teleg_id = await User.TelegIdByUsername(idapp, username); const cl = getclTelegByidapp(idapp); let ris = null; if (cl && teleg_id) { - ris = await cl.sendMsg(teleg_id, text) + ris = await cl.sendMsg(teleg_id, text); } if (cl && teleg_id) { if (alsotomanagers) { - await this.sendMsgTelegramToTheManagers(idapp, text) + await this.sendMsgTelegramToTheManagers(idapp, text); } if (!!username_mitt) { const rec = cl.getRecByUsername(username); @@ -926,7 +1108,9 @@ module.exports = { return ris; }, - sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec, MyForm = null) { + sendMsgTelegramByIdTelegram: async function( + idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec, + MyForm = null) { if (!idtelegram) return; @@ -934,19 +1118,20 @@ module.exports = { if (cl && idtelegram) { let myform = null; - return await cl.sendMsg(idtelegram, text, null, MyForm, message_id, chat_id, ripr_menuPrec) + return await cl.sendMsg(idtelegram, text, null, MyForm, message_id, + chat_id, ripr_menuPrec); } }, - reloadMenuBot: async function (idapp) { + reloadMenuBot: async function(idapp) { const cl = getclTelegByidapp(idapp); if (cl) { return await cl.updateMenuBot(); } - } + }, }; @@ -962,7 +1147,9 @@ async function sendMsgTelegramToTheAdmin(idapp, text, msg) { username = msg.chat.username; } - text = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': Da ' + msg.chat.first_name + ' ' + msg.chat.last_name + ' [' + username + ']: \n' + text; + text = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': Da ' + + msg.chat.first_name + ' ' + msg.chat.last_name + ' [' + username + + ']: \n' + text; tools.writeEventsLog(text); if (usersmanagers) { @@ -971,13 +1158,13 @@ async function sendMsgTelegramToTheAdmin(idapp, text, msg) { const idtelegram = rec.profile.teleg_id; const cl = getclTelegByidapp(idapp); if (cl && idtelegram) { - await cl.sendMsg(idtelegram, text) + await cl.sendMsg(idtelegram, text); } - await tools.snooze(300) + await tools.snooze(300); } } } - return true + return true; } @@ -994,14 +1181,16 @@ function getusernameByUser(idapp, msg) { return username; } -async function local_sendMsgTelegramToTheManagers(idapp, text, msg, username_bo) { +async function local_sendMsgTelegramToTheManagers( + idapp, text, msg, username_bo) { const usersmanagers = await User.getusersManagers(idapp); let username = msg.chat.username; if (username_bo) username = username_bo; - text = emo.ROBOT_FACE + ': Da ' + msg.chat.first_name + ' ' + msg.chat.last_name + ' (' + username + '): \n' + text; + text = emo.ROBOT_FACE + ': Da ' + msg.chat.first_name + ' ' + + msg.chat.last_name + ' (' + username + '): \n' + text; tools.writeEventsLog(text); if (usersmanagers) { @@ -1009,47 +1198,47 @@ async function local_sendMsgTelegramToTheManagers(idapp, text, msg, username_bo) const idtelegram = rec.profile.teleg_id; const cl = getclTelegByidapp(idapp); if (cl && idtelegram) { - await cl.sendMsg(idtelegram, text, undefined, undefined, undefined, undefined, true) + await cl.sendMsg(idtelegram, text, undefined, undefined, undefined, + undefined, true); } - await tools.snooze(100) + await tools.snooze(100); } } - return true + return true; } - function getstr(lang, key, param1) { let mystr = ''; if ((lang === 'si') || (lang === 'sl-si')) { try { - mystr = txt_si[key] + mystr = txt_si[key]; } catch (e) { mystr = ''; } } else if ((lang === 'en') || (lang === 'enUs')) { try { - mystr = txt_en[key] + mystr = txt_en[key]; } catch (e) { mystr = ''; } } else if (lang === 'es') { try { - mystr = txt_es[key] + mystr = txt_es[key]; } catch (e) { mystr = ''; } } else if (lang === 'fr') { try { - mystr = txt_fr[key] + mystr = txt_fr[key]; } catch (e) { mystr = ''; } } else if (lang === 'pt') { try { - mystr = txt_pt[key] + mystr = txt_pt[key]; } catch (e) { mystr = ''; } @@ -1075,7 +1264,7 @@ class Telegram { this.pageChange = false; this.menuDb = null; this.menuSaved = {}; - this.lastid = 0 + this.lastid = 0; //++ } @@ -1085,14 +1274,14 @@ class Telegram { let rec = this.getRecInMem(msg); if (!!rec) { if (rec.user) - rec.status = Status.VERIFIED + rec.status = Status.VERIFIED; } else { - return false + return false; } } - return true + return true; } else { - return false + return false; } } @@ -1107,7 +1296,7 @@ class Telegram { rec = this.addUser(msg); if (rec.user) - rec.status = Status.VERIFIED + rec.status = Status.VERIFIED; } else { let prova = 1; // await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', tools.getNomeAppByIdApp(this.idapp)), MenuNoLogin); @@ -1116,7 +1305,7 @@ class Telegram { } geturlfaq() { - return tools.getHostByIdApp(this.idapp) + '/faq' + return tools.getHostByIdApp(this.idapp) + '/faq'; } async IsTesto(msg) { @@ -1136,13 +1325,16 @@ class Telegram { const rec = this.getRecInMem(msg); let myname = ''; if (rec.user) { - myname = rec.user.name + ' ' + rec.user.surname + ' (n.' + rec.user.index + ')'; + myname = rec.user.name + ' ' + rec.user.surname + ' (n.' + + rec.user.index + ')'; lang = rec.user.lang; } if (rec.statusmsg === Status.WAITFOR_RISPOSTA) { if (rec.msgcodeprec === MsgBot.COME_STAI) { - risp = 'L\'importante è trovare Serenità dentro di noi' + emo.GIFT_HEART + '\nNutrirsi di Sole e Viaggiare il più possibile ! ' + emo.DREAM; + risp = 'L\'importante è trovare Serenità dentro di noi' + + emo.GIFT_HEART + + '\nNutrirsi di Sole e Viaggiare il più possibile ! ' + emo.DREAM; } else if (rec.msgcodeprec === MsgBot.QUANTI_ANNI_HAI) { const eta = testo.match(/\d+/g); if (!eta) { @@ -1164,7 +1356,7 @@ class Telegram { } } else if (rec.msgcodeprec === MsgBot.CHAT_EMPOWER) { if (!MsgBot.SI.includes(testo)) { - risp = MsgRisp.CHAT_EMPOWER + risp = MsgRisp.CHAT_EMPOWER; } else { risp = 'Bene ! Allora divertiti conoscendo persone nuove ! '; } @@ -1198,15 +1390,21 @@ class Telegram { } else if (MsgBot.COME_STAI.includes(testo.replace('?', ''))) { risp = 'Io Benone Grazie! ' + emoji.get('heartbeat') + ' E tu?'; rec.statusmsg = Status.WAITFOR_RISPOSTA; - rec.msgcodeprec = MsgBot.COME_STAI + rec.msgcodeprec = MsgBot.COME_STAI; } else if (MsgBot.CHI_SONO_IO.includes(testo.replace('?', ''))) { - risp = 'Su Telegram ti chiami "' + msg.chat.first_name + ' ' + msg.chat.last_name + '"\n'; + risp = 'Su Telegram ti chiami "' + msg.chat.first_name + ' ' + + msg.chat.last_name + '"\n'; if (!!rec.user) { - const myrec = await User.getUserShortDataByUsername(this.idapp, rec.user.username); - risp += '\nSul sito ti sei registrato come:\n\n[N. ' + rec.user.index + ']: ' + rec.user.name + ' ' + rec.user.surname + '\nUsername: ' + rec.user.username + '\n' + 'Email: ' + rec.user.email + '\nLang: ' + rec.user.lang + tools.ACAPO; + const myrec = await User.getUserShortDataByUsername(this.idapp, + rec.user.username); + risp += '\nSul sito ti sei registrato come:\n\n[N. ' + + rec.user.index + ']: ' + rec.user.name + ' ' + rec.user.surname + + '\nUsername: ' + rec.user.username + '\n' + 'Email: ' + + rec.user.email + '\nLang: ' + rec.user.lang + tools.ACAPO; risp += 'Num Invitati: ' + myrec.numinvitati + tools.ACAPO; - risp += 'Num Invitati Attivi: ' + myrec.numinvitatiattivi + tools.ACAPO; + risp += 'Num Invitati Attivi: ' + myrec.numinvitatiattivi + + tools.ACAPO; } else { risp = 'Ancora non ti sei Attivato sul BOT'; } @@ -1214,19 +1412,24 @@ class Telegram { risp = 'Io Si, ci sono !'; } else if (MsgBot.QUANTI_ANNI_HAI.includes(testo.replace('?', ''))) { - risp = 'Io sono abbastanza Giovane ! ' + emo.SMILE_STAR + '\nNon posso dirti che età ho. E tu?'; + risp = 'Io sono abbastanza Giovane ! ' + emo.SMILE_STAR + + '\nNon posso dirti che età ho. E tu?'; rec.statusmsg = Status.WAITFOR_RISPOSTA; - rec.msgcodeprec = MsgBot.QUANTI_ANNI_HAI + rec.msgcodeprec = MsgBot.QUANTI_ANNI_HAI; } else if (MsgBot.DAMMI_UN_BACIO.includes(testo)) { risp = emo.KISS; } else if (MsgBot.COSA_FAI.includes(testo)) { - risp = 'Ora sto chattando con te!\nSolitamente sono in attesa di ricevere messaggi ' + emo.ENVELOPE; + risp = 'Ora sto chattando con te!\nSolitamente sono in attesa di ricevere messaggi ' + + emo.ENVELOPE; } else if (MsgBot.MASCHIO_FEMMINA.includes(testo.replace('?', ''))) { risp = 'Cosa vorresti che fossi? Uomo o donna?'; rec.msgcodeprec = MsgBot.MASCHIO_FEMMINA; rec.statusmsg = Status.WAITFOR_RISPOSTA; } else if (MsgBot.COME_TI_CHIAMI.includes(testo.replace('?', ''))) { - risp = 'Io mi chiamo BOT e sono il tuo assistente Virtuale. ' + emo.EYES + '\nPuoi usare il menu che compare qui sotto per sapere tutto sulle mie funzionalità ' + emo.GREEN_HEART; + risp = 'Io mi chiamo BOT e sono il tuo assistente Virtuale. ' + + emo.EYES + + '\nPuoi usare il menu che compare qui sotto per sapere tutto sulle mie funzionalità ' + + emo.GREEN_HEART; contastiera = true; } else if (MsgBot.UGUALE.includes(testo)) { risp = testo; @@ -1237,44 +1440,68 @@ class Telegram { } else if (MsgBot.GRAZIE.includes(testo.replace('!', ''))) { risp = 'Prego ! ' + emo.KISS + emo.KISS + emo.KISS; } else if (MsgBot.MI_AMI.find((rec) => testo.indexOf(rec) > -1)) { - risp = ' Tantissimo! ' + emo.KISS + emo.GIFT_HEART + emo.GIFT_HEART + emo.GIFT_HEART; + risp = ' Tantissimo! ' + emo.KISS + emo.GIFT_HEART + emo.GIFT_HEART + + emo.GIFT_HEART; } else if (MsgBot.TI_AMO.find((rec) => testo.indexOf(rec) > -1)) { - risp = ' Anche IO! ' + emo.KISS + emo.SMILE_STAR + emo.GIFT_HEART + emo.BLUE_HEART + emo.GREEN_HEART; - } else if (MsgBot.PRINCIPE_AZZURRO.find((rec) => testo.indexOf(rec) > -1)) { + risp = ' Anche IO! ' + emo.KISS + emo.SMILE_STAR + emo.GIFT_HEART + + emo.BLUE_HEART + emo.GREEN_HEART; + } else if (MsgBot.PRINCIPE_AZZURRO.find( + (rec) => testo.indexOf(rec) > -1)) { risp = 'Chissà... Forse si!\nAnche se meglio averne un altro di scorta, nel caso il Principe non sia disponibile.'; } else if (MsgBot.AIUTO.find((rec) => testo.indexOf(rec) > -1)) { - risp = 'Clicca qui per entrare nella Chat HELP di Supporto\n' + tools.HELP_CHAT + '\n\nI miei colleghi umani ti aiuteranno a risolvere !'; + risp = 'Clicca qui per entrare nella Chat HELP di Supporto\n' + + tools.HELP_CHAT + + '\n\nI miei colleghi umani ti aiuteranno a risolvere !'; } else if (MsgBot.SPOSAMI.find((rec) => testo.indexOf(rec) > -1)) { - risp = 'No Grazie! Sono per la Libertà a Vita! ' + emo.JOY + '\nMa se vuoi possiamo conoscerci meglio!' + emo.DANCER + emo.FIRE; + risp = 'No Grazie! Sono per la Libertà a Vita! ' + emo.JOY + + '\nMa se vuoi possiamo conoscerci meglio!' + emo.DANCER + emo.FIRE; } else if (MsgBot.CHE_TEMPO_FA.find((rec) => testo.indexOf(rec) > -1)) { risp = 'Il tempo oggi è Sereno da me! ' + emo.SUN; - } else if (MsgBot.NON_TROO_INVITATI.find((rec) => testo.indexOf(rec) > -1)) { + } else if (MsgBot.NON_TROO_INVITATI.find( + (rec) => testo.indexOf(rec) > -1)) { risp = MsgRisp.CHAT_EMPOWER; } else if (MsgBot.SEI_LIBERO.find((rec) => testo.indexOf(rec) > -1)) { - risp = 'Io? Sono per la Libertà! ' + emo.JOY + '\nMa se vuoi possiamo conoscerci meglio!' + emo.DANCER + emo.FIRE; + risp = 'Io? Sono per la Libertà! ' + emo.JOY + + '\nMa se vuoi possiamo conoscerci meglio!' + emo.DANCER + emo.FIRE; } else if (MsgBot.FARE_DOMANDA.find((rec) => testo.indexOf(rec) > -1)) { risp = 'Dipende ' + emo.SMILE_STAR + '\nProvaci!'; - } else if (MsgBot.DIVENTERO_RICCA.find((rec) => testo.indexOf(rec) > -1)) { - risp = 'Mmmmh... Perchè non pensi di Vivere già nell\'Abbondanza ?\nCosa ti manca veramente?\nForse di realizzare che la ricchezza è un sentirlo, non un diventarlo.' + emo.GIFT_HEART; + } else if (MsgBot.DIVENTERO_RICCA.find( + (rec) => testo.indexOf(rec) > -1)) { + risp = 'Mmmmh... Perchè non pensi di Vivere già nell\'Abbondanza ?\nCosa ti manca veramente?\nForse di realizzare che la ricchezza è un sentirlo, non un diventarlo.' + + emo.GIFT_HEART; } else if (MsgBot.MA_ALLORA.find((rec) => testo.indexOf(rec) > -1)) { risp = 'Ma allora cosa?'; - } else if (MsgBot.SEI_LIBERO_STASERA.find((rec) => testo.indexOf(rec) > -1)) { - risp = 'Si vabbeh, non è che puoi prendere subito tutta questa confidenza' + emo.EXCLAMATION_MARK + emo.SMILE_STAR + '\nIntanto inizia ad invitare altre persone a conoscermi, poi ne riparliamo ' + emo.GIFT_HEART; - } else if (MsgBot.MI_TROVI_UN_MOROSO.find((rec) => testo.indexOf(rec) > -1)) { - risp = emo.SMILE_STAR + emo.SMILE_STAR + emo.SMILE_STAR + emo.SMILE_STAR + '\nMagari! Così la smetteresti di scrivere a me (ad un BOT Virtuale) e tromberesti di più ' + emo.DANCER + emo.DANCER; + } else if (MsgBot.SEI_LIBERO_STASERA.find( + (rec) => testo.indexOf(rec) > -1)) { + risp = 'Si vabbeh, non è che puoi prendere subito tutta questa confidenza' + + emo.EXCLAMATION_MARK + emo.SMILE_STAR + + '\nIntanto inizia ad invitare altre persone a conoscermi, poi ne riparliamo ' + + emo.GIFT_HEART; + } else if (MsgBot.MI_TROVI_UN_MOROSO.find( + (rec) => testo.indexOf(rec) > -1)) { + risp = emo.SMILE_STAR + emo.SMILE_STAR + emo.SMILE_STAR + + emo.SMILE_STAR + + '\nMagari! Così la smetteresti di scrivere a me (ad un BOT Virtuale) e tromberesti di più ' + + emo.DANCER + emo.DANCER; risp += '\n\n' + MsgRisp.CHAT_EMPOWER; - } else if (MsgBot.SORPRESA.find((rec) => testo.indexOf(rec) > -1) && testo.length < 15) { + } else if (MsgBot.SORPRESA.find((rec) => testo.indexOf(rec) > -1) && + testo.length < 15) { risp = 'Siiiii ! Davvero! ' + emo.DREAM; } else if (MsgBot.PAROLACCE.find((rec) => testo.indexOf(rec) > -1)) { - risp = 'Da te non me l\'aspettavo proprio !! ' + emo.INNOCENT + emo.CROSS_ROSSA; - } else if (MsgBot.HAHA.find((rec) => testo.indexOf(rec) > -1) && testo.length < 8) { + risp = 'Da te non me l\'aspettavo proprio !! ' + emo.INNOCENT + + emo.CROSS_ROSSA; + } else if (MsgBot.HAHA.find((rec) => testo.indexOf(rec) > -1) && + testo.length < 8) { risp = emo.JOY + emo.JOY + emo.JOY; } else if (testo.length >= 10) { noanswer = true; let myfaq = this.geturlfaq(); - risp = 'Io sono solo un Robot ' + emo.ROBOT_FACE + emo.JOY2 + '\n\nPer AIUTO, clicca qui:\n👉🏻👉🏻FAQ di AIUTO (risposte alle domande più frequenti)\n\nSe non trovi risposta allora contatta la Chat HELP.\nGrazie'; + risp = 'Io sono solo un Robot ' + emo.ROBOT_FACE + emo.JOY2 + + '\n\nPer AIUTO, clicca qui:\n👉🏻👉🏻FAQ di AIUTO (risposte alle domande più frequenti)\n\nSe non trovi risposta allora contatta la Chat HELP.\nGrazie'; // risp += '\nClicca qui per entrare nella Chat - HELP di Supporto\n' + 'https://t.me/joinchat/AL2qKE80rxDkgbeMGO-0bw' + '\n\nI miei colleghi umani ti aiuteranno a risolvere !'; - await local_sendMsgTelegramToTheManagers(this.idapp, testo, msg, rec.username_bo); + await local_sendMsgTelegramToTheManagers(this.idapp, testo, msg, + rec.username_bo); } } @@ -1282,12 +1509,12 @@ class Telegram { if (contastiera) { keyboard = { - "parse_mode": "HTML", - "reply_markup": { - "resize_keyboard": true, - "keyboard": await this.getKeyboard(id, undefined, this.getlang(msg)) - } - } + 'parse_mode': 'HTML', + 'reply_markup': { + 'resize_keyboard': true, + 'keyboard': await this.getKeyboard(id, undefined, this.getlang(msg)), + }, + }; } @@ -1314,7 +1541,7 @@ class Telegram { rec.numdomande++; if (!noanswer) { await tools.snooze(600); - risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp + risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp; } this._inviaMsg(id, risp, keyboard); @@ -1323,13 +1550,12 @@ class Telegram { tools.writelog(strlog); } - return risp !== ''; } async isMenuNotVerified(rec, msg) { if (this.isSelMenu(msg, msg.text, 'ASSISTENZA')) { - await this.menuAssistenza(msg) + await this.menuAssistenza(msg); } else if (msg.text === Menu.LANG_IT) { await this.ScegliLang(msg, 'it'); } else if (msg.text === Menu.LANG_ES) { @@ -1343,11 +1569,12 @@ class Telegram { } else if (msg.text === Menu.LANG_PT) { await this.ScegliLang(msg, 'pt'); } else if (this.isSelMenu(msg, msg.text, 'INFO')) { - await this.menuInformazioni(msg) + await this.menuInformazioni(msg); } else if (msg.text === Menu.LANG) { - await this.menuLang(msg) - } else if (this.isSelMenu(msg, msg.text, 'ZOOM') || MsgBot.PROSSIMO_ZOOM.find((rec) => msg.text.indexOf(rec) > -1)) { - await this.menuZoom(msg) + await this.menuLang(msg); + } else if (this.isSelMenu(msg, msg.text, 'ZOOM') || + MsgBot.PROSSIMO_ZOOM.find((rec) => msg.text.indexOf(rec) > -1)) { + await this.menuZoom(msg); } else if (await this.IsTesto(msg)) { // OK } else { @@ -1383,54 +1610,58 @@ class Telegram { if (msg.text === undefined) return; - const arrtext = msg.text.split(" "); - let cmd2 = ""; + const arrtext = msg.text.split(' '); + let cmd2 = ''; let cmd1 = arrtext[0]; if (arrtext.length > 1) cmd2 = arrtext[1]; let oldusername = rec.msgall_username_specifico; - if ((this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) || (this.isSelMenu(msg, msg.text, 'INDIETRO'))) { + if ((this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) || + (this.isSelMenu(msg, msg.text, 'INDIETRO'))) { rec.msgall_username_specifico = ''; } else { if (rec.msgall_username_specifico !== '') { - await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico, msg.text); + await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico, + msg.text); return true; } } - if (this.isSelMenu(msg, msg.text, 'LAVAGNA') || MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) { + if (this.isSelMenu(msg, msg.text, 'LAVAGNA') || + MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) { await this.menuLavagna(msg); } else if (this.isSelMenu(msg, msg.text, 'ACCEDI')) { - await this.menuAccedi(msg) + await this.menuAccedi(msg); } else if (this.isSelMenu(msg, msg.text, 'LINK_CONDIVIDERE')) { - await this.menuLinkCondividere(msg) + await this.menuLinkCondividere(msg); } else if (msg.text === Menu.EXIT_TELEGRAM) { - await this.menuExitToTelegram(msg) + await this.menuExitToTelegram(msg); } else if (msg.text === Menu.ADMIN) { - await this.menuAdmin(msg) + await this.menuAdmin(msg); } else if (msg.text === Menu.LANG) { - await this.menuLang(msg) + await this.menuLang(msg); } else if (msg.text === Menu.MSGATUTTI) { - await this.menumsgAll(msg) + await this.menumsgAll(msg); } else if (msg.text === Menu.MSGSTAFF) { - await this.menumsgStaff(msg) + await this.menumsgStaff(msg); } else if (msg.text === Menu.MSGPAOLO) { - await this.menumsgPaolo(msg) + await this.menumsgPaolo(msg); } else if (msg.text === Menu.MSG_NO_7_REQ) { - await this.menumsg_No_7_Req(msg) + await this.menumsg_No_7_Req(msg); } else if (msg.text === Menu.MSG_NO_9_REQ) { - await this.menumsg_No_9_Req(msg) + 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) + await this.menumsg_to_Nave(msg, cmd2); } else if (msg.text === Menu.MSG_SI_INVITATI_NO_7REQ_INVITATI) { - await this.menumsg_Si_Invitati_No_7Req(msg) + await this.menumsg_Si_Invitati_No_7Req(msg); } else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) { - await this.menumsg_A_Utente(msg) - } else if (this.isSelMenu(msg, msg.text, 'INDIETRO') || (msg.text === Menu.it.INDIETRO)) { + await this.menumsg_A_Utente(msg); + } else if (this.isSelMenu(msg, msg.text, 'INDIETRO') || + (msg.text === Menu.it.INDIETRO)) { await this.msgScegliMenu(msg); } else if (this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) { await this.sendMsg(msg.chat.id, 'Uscito dalla Chat con ' + oldusername); @@ -1459,9 +1690,9 @@ class Telegram { if (user) { if (user.profile.my_dream) if (user.profile.my_dream.length > 10) - return true + return true; } - return false + return false; } ispayment(user) { @@ -1480,13 +1711,14 @@ class Telegram { } } - return false + return false; } async menuAccedi(msg) { let status = this.getstatusInMemory(msg); if (status === Status.WAITFOR_USERNAME_BO) { - await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'), MenuNoLogin); + await this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND')); } } @@ -1499,7 +1731,7 @@ class Telegram { if (rec.lang !== '' && rec.lang !== undefined) return rec.lang; else { - return msg.from.language_code + return msg.from.language_code; } } } @@ -1508,12 +1740,15 @@ class Telegram { let mystr = ''; - const dashboard = await User.getDashboard(this.idapp, user.aportador_solidario, user.username, user.aportador_solidario_name_surname); - const downline = await User.getDownline(this.idapp, user.aportador_solidario, user.username); + const dashboard = await User.getDashboard(this.idapp, + user.aportador_solidario, user.username, + user.aportador_solidario_name_surname); + const downline = await User.getDownline(this.idapp, + user.aportador_solidario, user.username); let numpersone = (downline.downline) ? downline.downline.length : 0; let invitati_attivi = dashboard.myself.numinvitatiattivi; - mystr = ""; + mystr = ''; // if (dashboard.aportador) { // mystr = emoji.get('seedling') + ` Chi ti ha invitato: ${dashboard.aportador.username} (${dashboard.aportador.name} ${dashboard.aportador.surname})\n`; // } else { @@ -1526,11 +1761,14 @@ class Telegram { let mystrnave = ''; if (user) { - mystr += tools.get__('BENVENUTO', this.getlang(msg)) + ' ' + user.name + ' (' + user.username + ') ' + emo.DIZZY + '\n\n'; + mystr += tools.get__('BENVENUTO', this.getlang(msg)) + ' ' + user.name + + ' (' + user.username + ') ' + emo.DIZZY + '\n\n'; - tuttie9 = dashboard.myself.qualified && (numpersone >= 2) && invitati_attivi >= 2; + tuttie9 = dashboard.myself.qualified && (numpersone >= 2) && + invitati_attivi >= 2; - mystrnave = await Nave.getNaveByUser(this.idapp, user.username, user.lang, true); + mystrnave = await Nave.getNaveByUser(this.idapp, user.username, user.lang, + true); if (mystrnave === '' && tuttie9) { mystr += tools.gettranslate('NO_PROG', user.lang); @@ -1543,7 +1781,10 @@ class Telegram { } else { if (!tuttie9) { - mystr += dashboard.myself.qualified ? emo.SMILE_STAR + tools.get__('HAI_I_7_REQUISITI', this.getlang(msg)) + emo.SMILE_STAR : emo.EXCLAMATION_MARK + tools.get__('NON_HAI_I_7_REQUISITI', this.getlang(msg)); + mystr += dashboard.myself.qualified ? emo.SMILE_STAR + + tools.get__('HAI_I_7_REQUISITI', this.getlang(msg)) + + emo.SMILE_STAR : emo.EXCLAMATION_MARK + + tools.get__('NON_HAI_I_7_REQUISITI', this.getlang(msg)); mystr += '\n\n'; } // mystr += tuttie9 ? emo.SMILE_STAR + tools.get__('HAI_I_9_REQUISITI', this.getlang(msg)) + emo.SMILE_STAR : emo.EXCLAMATION_MARK + tools.get__('NON_HAI_I_9_REQUISITI', this.getlang(msg)); @@ -1553,16 +1794,26 @@ class Telegram { mystr += '\n' + '1. ' + this.getsymb(emo.ENVELOPE, user.verified_email); mystr += tools.get__('EMAIL', this.getlang(msg)) + ' '; - mystr += user.verified_email ? tools.get__('VERIF', this.getlang(msg)) : tools.get__('EMAIL_NON_VERIF', this.getlang(msg)); + mystr += user.verified_email + ? tools.get__('VERIF', this.getlang(msg)) + : tools.get__('EMAIL_NON_VERIF', this.getlang(msg)); - mystr += '\n2. ' + this.getsymb(emo.ROBOT_FACE, true) + tools.get__('BOT', this.getlang(msg)) + ' '; + mystr += '\n2. ' + this.getsymb(emo.ROBOT_FACE, true) + + tools.get__('BOT', this.getlang(msg)) + ' '; mystr += tools.get__('VERIF', this.getlang(msg)); - mystr += '\n3. ' + this.getsymb(emo.PENCIL, tools.isBitActive(user.profile.saw_and_accepted, shared_consts.Accepted.CHECK_READ_GUIDELINES)) + tools.get__('LINEE_GUIDA', this.getlang(msg)); - mystr += '\n4. ' + this.getsymb(emo.TV, tools.isBitActive(user.profile.saw_and_accepted, shared_consts.Accepted.CHECK_SEE_VIDEO_PRINCIPI)) + tools.get__('VIDEO_INTRO', this.getlang(msg)); + mystr += '\n3. ' + this.getsymb(emo.PENCIL, + tools.isBitActive(user.profile.saw_and_accepted, + shared_consts.Accepted.CHECK_READ_GUIDELINES)) + + tools.get__('LINEE_GUIDA', this.getlang(msg)); + mystr += '\n4. ' + this.getsymb(emo.TV, + tools.isBitActive(user.profile.saw_and_accepted, + shared_consts.Accepted.CHECK_SEE_VIDEO_PRINCIPI)) + + tools.get__('VIDEO_INTRO', this.getlang(msg)); // mystr += '\n5. ' + this.getsymb(emo.EYES, user.profile.saw_zoom_presentation) + tools.get__('ZOOM_PARTECIPATO', this.getlang(msg)); // mystr += '\n6. ' + this.getsymb(emo.DREAM, this.isdreamset(user)) + tools.get__('SCRITTO_SOGNO', this.getlang(msg)); - mystr += '\n7. ' + this.getsymb(emo.CREDIT_CARD, this.ispayment(user)) + tools.get__('PAYMENTS', this.getlang(msg)); + mystr += '\n7. ' + this.getsymb(emo.CREDIT_CARD, this.ispayment(user)) + + tools.get__('PAYMENTS', this.getlang(msg)); } // } else{ @@ -1572,8 +1823,13 @@ class Telegram { // numpersone = 2; if (!mystrnave) { - mystr += '\n8. ' + this.getsymb(emo.INVITATI, numpersone >= 2, numpersone, numpersone, numpersone >= 3) + tools.get__('INVITATI', this.getlang(msg)); - mystr += '\n9. ' + this.getsymb(emo.INVITATI, invitati_attivi >= 2, invitati_attivi, invitati_attivi, invitati_attivi >= 3) + tools.get__('INVITATI_ATTIVI', this.getlang(msg)) + '\n' + '\n'; + mystr += '\n8. ' + + this.getsymb(emo.INVITATI, numpersone >= 2, numpersone, numpersone, + numpersone >= 3) + tools.get__('INVITATI', this.getlang(msg)); + mystr += '\n9. ' + + this.getsymb(emo.INVITATI, invitati_attivi >= 2, invitati_attivi, + invitati_attivi, invitati_attivi >= 3) + + tools.get__('INVITATI_ATTIVI', this.getlang(msg)) + '\n' + '\n'; if (numpersone > 0) { mystr += tools.get__('INVITATI_LISTA', this.getlang(msg)) + ':\n'; @@ -1586,11 +1842,11 @@ class Telegram { index++; }); } else { - mystr += tools.get__('NESSUN_INVITATO', this.getlang(msg)) + tools.ACAPO; + mystr += tools.get__('NESSUN_INVITATO', this.getlang(msg)) + + tools.ACAPO; } } - // if (dashboard.downnotreg) { // if (dashboard.downnotreg.length > 0) { // mystr += '\n' + emo.QUESTION_MARK + ' ' + tools.get__('NONREG', msg) + ':' + emo.QUESTION_MARK + '\n'; @@ -1603,9 +1859,12 @@ class Telegram { // } if (tuttie9) - mystr += '\n' + printf(tools.get__('INFO_LAVAGNA_SITO', this.getlang(msg))); + mystr += '\n' + + printf(tools.get__('INFO_LAVAGNA_SITO', this.getlang(msg))); else - mystr += '\n' + printf(tools.get__('INFO_LAVAGNA_SITO_COMPLETARE', this.getlang(msg)), tools.getHostByIdApp(this.idapp)); + mystr += '\n' + + printf(tools.get__('INFO_LAVAGNA_SITO_COMPLETARE', this.getlang(msg)), + tools.getHostByIdApp(this.idapp)); return mystr; } @@ -1614,7 +1873,7 @@ class Telegram { const rec = this.getRecInMem(msg); let mystr = ''; if (rec.user) { - mystr = await this.getLavagnaByUser(rec.user, msg) + mystr = await this.getLavagnaByUser(rec.user, msg); } if (!!mystr) @@ -1625,10 +1884,10 @@ class Telegram { const rec = this.getRecInMem(msg); let mystr = ''; if (!rec.user) - return ""; + return ''; let username_to_check = rec.user.username; - let arrstringa = msg.text.split(" "); + let arrstringa = msg.text.split(' '); if (!!arrstringa) { if (arrstringa.length > 1) { @@ -1639,19 +1898,23 @@ class Telegram { } } - mystr = await Nave.getNaveByUser(this.idapp, username_to_check, rec.user.lang, true); + mystr = await Nave.getNaveByUser(this.idapp, username_to_check, + rec.user.lang, true); if (!!mystr) await this.sendMsg(msg.chat.id, mystr); } - async menuLinkCondividere(msg) { const rec = this.getRecInMem(msg); let mystr = ''; if (rec.user) { - mystr += printf(tools.get__('INFO_LINK_DA_CONDIVIDERE', this.getlang(msg)), tools.getHostByIdApp(this.idapp) + '/signup/' + rec.user.username); - mystr += tools.ACAPO + tools.ACAPO + printf(tools.get__('INFO_LINK_ZOOM', this.getlang(msg)), tools.getlinkzoom(null)); + mystr += printf( + tools.get__('INFO_LINK_DA_CONDIVIDERE', this.getlang(msg)), + tools.getHostByIdApp(this.idapp) + '/signup/' + rec.user.username); + mystr += tools.ACAPO + tools.ACAPO + + printf(tools.get__('INFO_LINK_ZOOM', this.getlang(msg)), + tools.getlinkzoom(null)); await this.sendMsg(msg.chat.id, mystr); } } @@ -1659,13 +1922,14 @@ class Telegram { async menuExitToTelegram(msg) { const rec = this.getRecInMem(msg); if (rec.user) { - await User.SetTelegramIdSuccess(this.idapp, rec.user._id, 0) - .then((recuser) => { - if (recuser) { - this.deleteRecInMem(msg); - this.sendMsg(msg.chat.id, getstr(rec.user.lang, 'MSG_EXIT_TELEGRAM')); - } - }) + await User.SetTelegramIdSuccess(this.idapp, rec.user._id, 0). + then((recuser) => { + if (recuser) { + this.deleteRecInMem(msg); + this.sendMsg(msg.chat.id, + getstr(rec.user.lang, 'MSG_EXIT_TELEGRAM')); + } + }); } else { this.deleteRecInMem(msg); } @@ -1682,7 +1946,8 @@ class Telegram { let mystr = ''; - mystr += emo.STARS + tools.get__('ZOOM_CONFERENCE', this.getlang(msg)) + emo.STARS + '\n\n'; + mystr += emo.STARS + tools.get__('ZOOM_CONFERENCE', this.getlang(msg)) + + emo.STARS + '\n\n'; // let pwd = 'Password: 123123'; @@ -1692,35 +1957,38 @@ class Telegram { if (nextzoom) iniziata = (nextzoom._id.toString() === evento._id.toString()); - let lang = this.getlang(msg); if (iniziata) { - mystr += emo.CHECK_VERDE + ' ' + tools.get__('ZOOM_INIZIATO', lang) + ' ' + emo.CHECK_VERDE + '\n'; + mystr += emo.CHECK_VERDE + ' ' + tools.get__('ZOOM_INIZIATO', lang) + + ' ' + emo.CHECK_VERDE + '\n'; } - mystr += tools.getflagtelegrambyLang(evento.lang) + ` ${emo.EYES} ${tools.getstrDateTimeShort(evento.date_start, this.getlang(msg))} ${emo.EYES}`; + mystr += tools.getflagtelegrambyLang(evento.lang) + + ` ${emo.EYES} ${tools.getstrDateTimeShort(evento.date_start, + this.getlang(msg))} ${emo.EYES}`; mystr += `\n${evento.title}\n(${evento.note})`; mystr += `\n${tools.getlinkzoom(evento)}\n\n`; if (nextzoom) { if (iniziata) { - mystr += emo.FIRE + tools.get__('CLICCA_ENTRA', this.getlang(msg)) + ' ' + emo.FIRE + '\n'; + mystr += emo.FIRE + tools.get__('CLICCA_ENTRA', this.getlang(msg)) + + ' ' + emo.FIRE + '\n'; mystr += tools.getlinkzoom(evento) + '\n'; mystr += '\n'; //mystr += pwd + '\n\n'; } } - index++; }); if (!nextzoom && index > 1) { - mystr += "✨✨✨✨✨✨✨✨✨✨✨✨\n" + - tools.get__('CLICCA_PER_ZOOM', this.getlang(msg)) + '\n' + "✨✨✨✨✨✨✨✨✨✨✨✨\n"; + mystr += '✨✨✨✨✨✨✨✨✨✨✨✨\n' + + tools.get__('CLICCA_PER_ZOOM', this.getlang(msg)) + '\n' + + '✨✨✨✨✨✨✨✨✨✨✨✨\n'; } - return mystr + return mystr; } async menuZoom(msg) { @@ -1732,13 +2000,13 @@ class Telegram { async menuAdmin(msg) { const mystr = tools.get__('SCEGLI_VOCE', this.getlang(msg)); await - this.sendMsg(msg.chat.id, mystr, MenuAdmin); + this.sendMsg(msg.chat.id, mystr, MenuAdmin); } async menuLang(msg) { const mystr = tools.get__('SCEGLI_VOCE', this.getlang(msg)); await - this.sendMsg(msg.chat.id, mystr, MenuLang); + this.sendMsg(msg.chat.id, mystr, MenuLang); } getDestinStr(msg, destin, rec) { @@ -1760,13 +2028,13 @@ class Telegram { return 'No Imbarcati (7 Req) '; else if (destin === Destin.A_UTENTE) { const rec = this.getRecInMem(msg); - return rec.msgall_username_specifico + return rec.msgall_username_specifico; } else if (destin === Destin.DOMANDA) { const rec = this.getRecInMem(msg); - return rec.msg_username_domanda + return rec.msg_username_domanda; } else if (destin === Destin.RISPOSTA) { const rec = this.getRecInMem(msg); - return rec.msg_username_risposta + return rec.msg_username_risposta; } } @@ -1818,12 +2086,15 @@ class Telegram { if (!!username) { rec.msgall_username_specifico = username; } - const mystr = 'Scrivi qui un Messaggio da inviare a' + ' [' + this.getDestinStr(msg, dest, rec) + ']:'; + const mystr = 'Scrivi qui un Messaggio da inviare a' + ' [' + + this.getDestinStr(msg, dest, rec) + ']:'; await this.sendMsg(msg.chat.id, mystr, MenuSend); } } - async menumsgDomanda(msg, cmd, dest, username, extraparam, domanda, msgYes, msgNo, destYes, destNo, username_risposta) { + async menumsgDomanda( + msg, cmd, dest, username, extraparam, domanda, msgYes, msgNo, destYes, + destNo, username_risposta) { const rec = this.getRecInMem(msg); if (rec.user) { rec.msgall_status = StatusMSGALL.CONFIRM; @@ -1843,7 +2114,7 @@ class Telegram { getlink(qualelink) { if (qualelink === 'website') { - return '' + return ''; } else if (qualelink === 'biblio') { return ''; } else if (qualelink === 'help') { @@ -1860,34 +2131,38 @@ class Telegram { const biblio = this.getlink('biblio'); const faq = this.getlink('faq'); - let help = ""; + let help = ''; let helpaperta = true; - if (tools.isMonToFri() && tools.isBetweenTwoTime('9:00:00', '19:00:00')) { + /*if (tools.isMonToFri() && tools.isBetweenTwoTime('9:00:00', '19:00:00')) { help = '✅ ' + this.getlink('help'); } else { help = "🔴 [ORA CHIUSA - NOW CLOSED]"; helpaperta = false; - } + }*/ - let mytext = ""; + help = '✅ ' + this.getlink('help'); + + let mytext = ''; if (this.getlang(msg) === 'it') - mytext = printf(tools.get__('TESTO_ASSISTENZA', this.getlang(msg)), sito, biblio, empower, faq, help); + mytext = printf(tools.get__('TESTO_ASSISTENZA', this.getlang(msg)), sito, + biblio, empower, faq, help); else - mytext = printf(tools.get__('TESTO_ASSISTENZA', this.getlang(msg)), sito, biblio, empower, help); + mytext = printf(tools.get__('TESTO_ASSISTENZA', this.getlang(msg)), sito, + biblio, empower, help); let menu = null; const rec = this.getRecInMem(msg); if (!rec.user) { - menu = MenuNoLogin + menu = null; } await - this.sendMsg(msg.chat.id, mytext, menu); + this.sendMsg(msg.chat.id, mytext, menu); } existInMemory(msg) { const rec = this.getRecInMem(msg); - return !!rec + return !!rec; } getstatus(rec) { @@ -1915,7 +2190,8 @@ class Telegram { } deleteRecInMem(msg) { - this.arrUsers = this.arrUsers.filter((rec) => rec.id !== this.getchatid(msg)); + this.arrUsers = this.arrUsers.filter( + (rec) => rec.id !== this.getchatid(msg)); } async getUser(msg, rec, conmsg) { @@ -1925,7 +2201,8 @@ class Telegram { const user = await User.findByUsername(this.idapp, mystruser, true); if (!user) { if (conmsg) { - await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'), MenuNoLogin); + await this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'), null); const lang = this.getlang(msg); // const textman = msg.chat.first_name + ' ' + msg.chat.last_name + ' sta tentando di autenticarsi con il BOT (lang=' + lang + ') (username che scrive: ' + msg.text + ') '; // await local_sendMsgTelegramToTheManagers(this.idapp, textman, msg); @@ -1937,7 +2214,7 @@ class Telegram { ok = true; } - return { rec, user, myid, ok }; + return {rec, user, myid, ok}; } async setUsernameBo(msg) { @@ -1955,23 +2232,30 @@ class Telegram { if (ris.ok) { rec.user = ris.user; - await User.SetTelegramCheckCode(this.idapp, ris.myid.toString(), rec.code); + await User.SetTelegramCheckCode(this.idapp, ris.myid.toString(), + rec.code); rec.status = Status.WAITFOR_VERIFY_CODE; - await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_VERIFY_CODE', tools.getHostByIdApp(this.idapp)), MenuNoLogin) + await this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_VERIFY_CODE', + tools.getHostByIdApp(this.idapp)), null); } else { - await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', tools.getNomeAppByIdApp(this.idapp)), MenuNoLogin); + await this.sendMsg(msg.chat.id, + getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', + tools.getNomeAppByIdApp(this.idapp)), null); } } } else if (text.length === 0) { if (rec) rec.status = Status.NONE; - await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_ANNULLA')); - this.deleteRecInMem(msg) + await this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_ANNULLA')); + this.deleteRecInMem(msg); } else { - await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME')) + await this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME')); } } catch (e) { - console.error('Error setUsernameBo:', e) + console.error('Error setUsernameBo:', e); } } @@ -1980,38 +2264,47 @@ class Telegram { if (!!msg.text) { const code = msg.text.toString().trim(); const rec = this.getRecInMem(msg); - const user = await User.findByUsername(this.idapp, rec.username_bo, true); + const user = await User.findByUsername(this.idapp, rec.username_bo, + true); let telegcode = 0; if (user) { telegcode = user.profile.teleg_checkcode.toString(); } else { await - this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'), MenuNoLogin); - return + this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'), + null); + return; } if (code.length < 7) { if (rec) { if (code === telegcode) { // let ris = await this.getUser(msg, rec, false); rec.status = Status.VERIFIED; - await User.SetTelegramIdSuccess(this.idapp, user._id, msg.from.id).then((recuser) => { + await User.SetTelegramIdSuccess(this.idapp, user._id, + msg.from.id).then((recuser) => { if (recuser) { let name = recuser.name; - this.sendMsg(msg.from.id, printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), name)); + this.sendMsg(msg.from.id, + printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), name)); // local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg); } else { - this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERR_UNKNOWN_VERIFY_CODE')); + this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERR_UNKNOWN_VERIFY_CODE')); } }); } else { if (rec.retry < 2) { rec.retry++; await - this.sendMsg(msg.from.id, printf(getstr(this.getlang(msg), 'MSG_ERR_VERIFY_CODE'), tools.getHostByIdApp(this.idapp))); + this.sendMsg(msg.from.id, + printf(getstr(this.getlang(msg), 'MSG_ERR_VERIFY_CODE'), + tools.getHostByIdApp(this.idapp))); } else { rec.status = Status.NONE; await - this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_ANNULLA')); + this.sendMsg(msg.from.id, getstr(this.getlang(msg), + 'MSG_ERRORE_USERNAME_ANNULLA')); this.deleteRecInMem(msg); } } @@ -2020,10 +2313,12 @@ class Telegram { if (rec) rec.status = Status.NONE; await - this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_ANNULLA')) + this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_ANNULLA')); } else { await - this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_VERIFY_CODE_MAXLEN')) + this.sendMsg(msg.from.id, + getstr(this.getlang(msg), 'MSG_ERRORE_VERIFY_CODE_MAXLEN')); } } } catch (e) { @@ -2034,7 +2329,8 @@ class Telegram { async sistemaRecDest(rec, msg) { let recdest = this.getRecByUsername(rec.msgall_username_specifico); if (!recdest) { - const userdest = await User.findByUsername(this.idapp, rec.msgall_username_specifico); + const userdest = await User.findByUsername(this.idapp, + rec.msgall_username_specifico); if (!!userdest) { let msgdest = msg; msgdest.from.id = userdest.profile.teleg_id; @@ -2048,13 +2344,13 @@ class Telegram { rec.msgall_username_specifico = ''; } - return recdest + return recdest; } - async setCmdToUsername(rec, username, cmd_to_set, valuebool) { if (cmd_to_set === Cmd.VALIDATE_REGISTRATION) { - return await User.setVerifiedByAportador(rec.user.idapp, username, valuebool); + return await User.setVerifiedByAportador(rec.user.idapp, username, + valuebool); } } @@ -2082,12 +2378,12 @@ class Telegram { let nummsgsent = 0; - let textdainviare = ""; + let textdainviare = ''; let preparatesto = ''; let myid = ''; if (this.isSelMenu(msg, texttosend, 'ZOOM')) { - texttosend = await this.getNextZoom(msg) + texttosend = await this.getNextZoom(msg); } const cmd = texttosend.toLowerCase(); @@ -2095,10 +2391,11 @@ class Telegram { if (usersall) { if (this.isSelMenu(msg, cmd, 'INDIETRO')) { rec.msgall_status = StatusMSGALL.NONE; - return + return; } - tools.writeEventsLog(this.getDestinStr(msg, destin, rec) + ':\n' + texttosend); + tools.writeEventsLog( + this.getDestinStr(msg, destin, rec) + ':\n' + texttosend); // let chiedisino = false; @@ -2132,16 +2429,22 @@ class Telegram { } else if (destin === Destin.RISPOSTA) { invia = utente.username === rec.msg_username_risposta; } else if (destin === Destin.NO_7_REQ) { - invia = !await User.isUserQualified7(this.idapp, utente.username); + invia = !await User.isUserQualified7(this.idapp, + utente.username); } else if (destin === Destin.NO_9_REQ) { - invia = !await User.isUserQualified9(this.idapp, utente.username); + invia = !await User.isUserQualified9(this.idapp, + utente.username); } else if (destin === Destin.NESSUN_IMBARCO_7REQ) { - invia = await User.NessunaNavePresenteByUsername(this.idapp, utente.username); + invia = await User.NessunaNavePresenteByUsername(this.idapp, + utente.username); } else if (destin === Destin.MSG_TO_NAVE) { - invia = !await Nave.findDonatoreByNave(this.idapp, rec.extraparam); + invia = !await Nave.findDonatoreByNave(this.idapp, + rec.extraparam); } else if (destin === Destin.SI_INVITATI_NO_7REQ_INVITATI) { - const numinvitati = await ListaIngresso.getnumInvitati(this.idapp, utente.username); - const numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(this.idapp, utente.username); + const numinvitati = await ListaIngresso.getnumInvitati( + this.idapp, utente.username); + const numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi( + this.idapp, utente.username); invia = (numinvitati >= 2) && (numinvitatiattivi < 2); } @@ -2153,7 +2456,8 @@ class Telegram { if (cmd === RICEVI_EMAIL) { preparatesto += utente.email + ', '; } else if (cmd === NOME_COGNOME) { - preparatesto += utente.name + ' ' + utente.surname + '(' + utente.username + ')' + '\n'; + preparatesto += utente.name + ' ' + utente.surname + '(' + + utente.username + ')' + '\n'; } else if (cmd === CONTA_SOLO) { // Niente } else if (cmd === CHEDI_SE_IMBARCARTI) { @@ -2162,11 +2466,13 @@ class Telegram { FormDaMostrare = this.getInlineKeyboard(lang, [ { text: Menu[lang].SI, - callback_data: InlineCmd.VOGLIO_IMBARCARMI + '|' + utente.username + callback_data: InlineCmd.VOGLIO_IMBARCARMI + '|' + + utente.username, }, { text: Menu[lang].NO, - callback_data: InlineCmd.NON_VOGLIO_IMBARCARMI + '|' + utente.username + callback_data: InlineCmd.NON_VOGLIO_IMBARCARMI + '|' + + utente.username, }, ]); inviaveramente = true; @@ -2174,11 +2480,12 @@ class Telegram { 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); + await this.sendMsg(utente.profile.teleg_id, + '[' + rec.username_bo + ' ti scrive]:\n' + + textdainviare, MenuChat); } else { // if (chiedisino) { @@ -2190,7 +2497,8 @@ class Telegram { // if (process.env.PROD === "0") { // telegid = 12429864; // } - await this.sendMsg(telegid, textdainviare, null, FormDaMostrare); + await this.sendMsg(telegid, textdainviare, null, + FormDaMostrare); // break; } @@ -2199,11 +2507,12 @@ class Telegram { nummsgsent++; } - if (!SendMsgCmd.includes(cmd)) { if ((nummsgsent % 100) === 0) { - myid = await this.sendMsg(msg.chat.id, nummsgsent + ' ' + getstr(this.getlang(msg), 'MSG_MSG_INCORSO'), null, null, myid); - await tools.snooze(100) + myid = await this.sendMsg(msg.chat.id, nummsgsent + ' ' + + getstr(this.getlang(msg), 'MSG_MSG_INCORSO'), null, + null, myid); + await tools.snooze(100); } } } @@ -2211,9 +2520,10 @@ class Telegram { } } - let msgris = ""; + let msgris = ''; if (cmd === CONTA_SOLO) { - msgris = nummsgsent + ' ' + getstr(this.getlang(msg), 'MSG_MSG_TOSENT'); + msgris = nummsgsent + ' ' + + getstr(this.getlang(msg), 'MSG_MSG_TOSENT'); } else if (cmd === NOME_COGNOME) { msgris = nummsgsent + ' ' + 'Utenti'; await this.sendMsg(msg.chat.id, msgris); @@ -2224,16 +2534,21 @@ class Telegram { msgris = preparatesto; } else { if (destin !== Destin.DOMANDA && destin !== Destin.RISPOSTA) { - msgris = nummsgsent + ' ' + getstr(this.getlang(msg), 'MSG_MSG_SENT'); + msgris = nummsgsent + ' ' + + getstr(this.getlang(msg), 'MSG_MSG_SENT'); } } if (destin === Destin.A_UTENTE) { const recdest = await this.sistemaRecDest(rec); if (!!recdest) { - await this.sendMsg(msg.chat.id, 'Conversazione Iniziata con ' + rec.msgall_username_specifico + ' !', MenuChat); + await this.sendMsg(msg.chat.id, + 'Conversazione Iniziata con ' + rec.msgall_username_specifico + + ' !', MenuChat); } else { - await this.sendMsg(msg.chat.id, 'Utente ' + rec.msgall_username_specifico + ' non presente sul BOT !'); + await this.sendMsg(msg.chat.id, + 'Utente ' + rec.msgall_username_specifico + + ' non presente sul BOT !'); } } else { if (msgris) { @@ -2248,14 +2563,16 @@ class Telegram { } } - selectMenuHelp(msg) { - return ((this.isSelMenu(msg, msg.text, 'INFO')) || (this.isSelMenu(msg, msg.text, 'ASSISTENZA'))) + return ((this.isSelMenu(msg, msg.text, 'INFO')) || + (this.isSelMenu(msg, msg.text, 'ASSISTENZA'))); } selectMenuLang(msg) { - return ((msg.text === Menu.LANG) || (msg.text === Menu.LANG_EN) || (msg.text === Menu.LANG_IT) || (msg.text === Menu.LANG_ES) - || (msg.text === Menu.LANG_FR) || (msg.text === Menu.LANG_SI) || (msg.text === Menu.LANG_PT)) + return ((msg.text === Menu.LANG) || (msg.text === Menu.LANG_EN) || + (msg.text === Menu.LANG_IT) || (msg.text === Menu.LANG_ES) + || (msg.text === Menu.LANG_FR) || (msg.text === Menu.LANG_SI) || + (msg.text === Menu.LANG_PT)); } async setInit(msg) { @@ -2266,7 +2583,7 @@ class Telegram { if (status !== Status.VERIFIED) return Status.EXIT; } else { - await this.setUser(msg) + await this.setUser(msg); } return status; @@ -2277,16 +2594,17 @@ class Telegram { let status = await this.setInit(msg); if (status === Status.EXIT) { - return + return; } const rec = this.getRecInMem(msg); status = this.getstatus(rec); - if (status === Status.WAITFOR_USERNAME_BO && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) { - await this.setUsernameBo(msg) + if (status === Status.WAITFOR_USERNAME_BO && !this.selectMenuHelp(msg) && + !this.selectMenuLang(msg)) { + await this.setUsernameBo(msg); } else if (status === Status.WAITFOR_VERIFY_CODE) { - await this.setVerifyCode(msg) + await this.setVerifyCode(msg); } else if (status === Status.NONE) { await this.start(msg); } else if (status === Status.VERIFIED) { @@ -2294,7 +2612,7 @@ class Telegram { if (rec.msgall_status === StatusMSGALL.CONFIRM) { if (this.isSelMenu(msg, msg.text, 'SI')) { // Take msg to send to ALL - await this.sendMsgToAll(rec, msg, rec.msgtosent, rec.msgall_achi) + await this.sendMsgToAll(rec, msg, rec.msgtosent, rec.msgall_achi); } else { let msgout = rec.msgNo; if (!msgout) @@ -2305,13 +2623,17 @@ class Telegram { if (rec.msg_toDest_yes) { rec.msgall_achi = Destin.RISPOSTA; if (this.isSelMenu(msg, msg.text, 'SI')) { - const ris = await this.setCmdToUsername(rec, rec.msg_username_risposta, rec.cmd_to_set, true); + const ris = await this.setCmdToUsername(rec, + rec.msg_username_risposta, rec.cmd_to_set, true); if (ris) { - await this.sendMsgToAll(rec, msg, rec.msg_toDest_yes, rec.msgall_achi); + await this.sendMsgToAll(rec, msg, rec.msg_toDest_yes, + rec.msgall_achi); } } else if (this.isSelMenu(msg, msg.text, 'NO')) { - const ris = await this.setCmdToUsername(rec, rec.msg_username_risposta, rec.cmd_to_set, false); - await this.sendMsgToAll(rec, msg, rec.msg_toDest_no, rec.msgall_achi); + const ris = await this.setCmdToUsername(rec, + rec.msg_username_risposta, rec.cmd_to_set, false); + await this.sendMsgToAll(rec, msg, rec.msg_toDest_no, + rec.msgall_achi); } } } @@ -2349,9 +2671,9 @@ class Telegram { } else { rec.msgall_status = StatusMSGALL.NONE; await - this.msgScegliMenu(msg); + this.msgScegliMenu(msg); } - normale = false + normale = false; } if (normale) { @@ -2360,7 +2682,7 @@ class Telegram { } } else { await - this.isMenuNotVerified(rec, msg); + this.isMenuNotVerified(rec, msg); } } @@ -2372,7 +2694,9 @@ class Telegram { await this.addUser(msg); // await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), printf(txt.MSG_ASK_USERNAME_BO, tools.getHostByIdApp(this.idapp)))); - await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', tools.getNomeAppByIdApp(this.idapp)), MenuNoLogin); + await this.sendMsg(msg.chat.id, + getstr(this.getlang(msg), 'MSG_ASK_USERNAME_BO', + tools.getNomeAppByIdApp(this.idapp)), null); return false; } @@ -2420,12 +2744,12 @@ class Telegram { if (user) rec.username_bo = user.username; else - rec.username_bo = '' + rec.username_bo = ''; } } catch (e) { console.error('Error: ', e); } - return !!rec + return !!rec; } updateMenuBot() { @@ -2486,7 +2810,7 @@ class Telegram { const recuser = this.getRecInMemById(id); if (recuser) { if (!recuser.datemenu_updated) - load = true + load = true; } if (check) { if (!(this.menuSaved[idapp])) @@ -2496,13 +2820,15 @@ class Telegram { // Check if you are Admin const user = await User.UserByIdTelegram(idapp, id); - let isAdmin = user ? user.profile.manage_telegram && user.username === 'paoloar77' : false - const isManager = user ? user.profile.manage_telegram : false - const isVerified = user ? user.profile.teleg_id > 0 && user.verified_email && user.verified_by_aportador : false; + let isAdmin = user ? user.profile.manage_telegram && user.username === + 'paoloar77' : false; + const isManager = user ? user.profile.manage_telegram : false; + const isVerified = user ? user.profile.teleg_id > 0 && + user.verified_email && user.verified_by_aportador : false; this.menuDb = await MyBot.findAllIdApp(idapp); - let arrlang = {} + let arrlang = {}; let riga = 0; let arrtemp = []; @@ -2510,21 +2836,24 @@ class Telegram { for (const rec of this.menuDb) { if (rec.active && rec.main && rec.page === this.pagenow - && ((isAdmin && tools.isBitActive(rec.visibility, shared_consts.VISIB_ONLY_ADMIN)) - || (isManager && tools.isBitActive(rec.visibility, shared_consts.VISIB_ONLY_MANAGER)) - || (isVerified && tools.isBitActive(rec.visibility, shared_consts.VISIB_ONLYIF_LOGGED)) + && ((isAdmin && tools.isBitActive(rec.visibility, + shared_consts.VISIB_ONLY_ADMIN)) + || (isManager && tools.isBitActive(rec.visibility, + shared_consts.VISIB_ONLY_MANAGER)) + || (isVerified && tools.isBitActive(rec.visibility, + shared_consts.VISIB_ONLYIF_LOGGED)) || (rec.visibility === 0)) ) { lang = rec.lang; if (!arrlang[rec.lang]) - arrlang[rec.lang] = {menu: []} + arrlang[rec.lang] = {menu: []}; if (riga !== rec.riga) { if (arrtemp.length > 0) arrlang[rec.lang].menu.push(arrtemp); riga = rec.riga; - arrtemp = [] + arrtemp = []; } arrtemp.push(rec.label); @@ -2553,12 +2882,13 @@ class Telegram { const recuser = await this.getRecInMemById(id); if (recuser) { if (!recuser.datemenu_updated) { - await this.loadMenuFromDb(this.idapp, id) + await this.loadMenuFromDb(this.idapp, id); } } for (const rec of this.menuDb) { - if (rec.idapp === idapp && rec.lang === lang && rec.label.toLowerCase() === testo) { + if (rec.idapp === idapp && rec.lang === lang && + rec.label.toLowerCase() === testo) { return true; } } @@ -2571,7 +2901,8 @@ class Telegram { getValueMenu(idapp, testo, lang) { try { for (const rec of this.menuDb) { - if (rec.idapp === idapp && rec.lang === lang && rec.label.toLowerCase() === testo) { + if (rec.idapp === idapp && rec.lang === lang && + rec.label.toLowerCase() === testo) { if (rec.type === shared_consts.BOTTYPE_TEXT) { return rec.value; } @@ -2595,10 +2926,10 @@ class Telegram { async getKeyboard(id, menu, lang) { let keyb = null; - this.lastid = id + this.lastid = id; if (menu) { - keyb = menu + keyb = menu; } else { keyb = await this.loadMenuFromDb(this.idapp, id); } @@ -2607,13 +2938,17 @@ class Telegram { if (!!keyb) { mykeyb = this.getmenuKey(keyb, lang); } + if (mykeyb === null) { + mykeyb = []; + } + // console.log('mykeyboard', mykeyb); return mykeyb; } modificaMsg(chatid, idmodif, text) { const form = { - "chat_id": chatid, - "message_id": idmodif, + 'chat_id': chatid, + 'message_id': idmodif, }; try { @@ -2628,7 +2963,7 @@ class Telegram { if (!text) return 0; - if (process.env.LOCALE === "1") { + if (process.env.LOCALE === '1') { if (id !== ADMIN_IDTELEGRAM_TEST) id = '12429864'; } @@ -2642,18 +2977,18 @@ class Telegram { if (!menu) { if (recmem) { if (recmem.msgall_username_specifico !== '') { - menu = MenuChat + menu = MenuChat; } } } if (recmem) { - recmem.lastmenu = menu + recmem.lastmenu = menu; } if (ripr_menuPrec) { if (recmem && !!recmem.lastmenu) { - menu = recmem.lastmenu + menu = recmem.lastmenu; } } @@ -2665,45 +3000,45 @@ class Telegram { try { - text = text.replace(/
/g, "\n"); - text = text.replace(/
/g, ""); - text = text.replace(//g, ""); - text = text.replace(//g, ""); - text = text.replace(/

/g, ""); - text = text.replace(/<\/div>/g, "\n"); - text = text.replace(/ /g, " "); + text = text.replace(/
/g, '\n'); + text = text.replace(/

/g, ''); + text = text.replace(//g, ''); + text = text.replace(//g, ''); + text = text.replace(/

/g, ''); + text = text.replace(/<\/div>/g, '\n'); + text = text.replace(/ /g, ' '); if (!form) { form = { - "parse_mode": "HTML", - "message_id": msg_id, - "reply_markup": { - "resize_keyboard": true, - "keyboard": await this.getKeyboard(id, menu, mylang) - } + 'parse_mode': 'HTML', + 'message_id': msg_id, + 'reply_markup': { + 'resize_keyboard': true, + 'keyboard': await this.getKeyboard(id, menu, mylang), + }, }; } - return this.bot.sendMessage(id, text, form) - .catch((e) => { - let blocked = false; - if ((e.message.indexOf('Forbidden') > 0) || (e.message.indexOf('chat not found') > 0)) { - blocked = true; - } - if (!blocked) { - console.error(e.message); - } - if (blocked) { - User.SetTelegramWasBlocked(this.idapp, id); - // ++Todo: DA FARE ! local_sendMsgTelegramToTheManagers(this.idapp, addtext + text); - } - return 0; - }); + return this.bot.sendMessage(id, text, form).catch((e) => { + let blocked = false; + if ((e.message.indexOf('Forbidden') > 0) || + (e.message.indexOf('chat not found') > 0)) { + blocked = true; + } + if (!blocked) { + console.error(e.message); + } + if (blocked) { + User.SetTelegramWasBlocked(this.idapp, id); + // ++Todo: DA FARE ! local_sendMsgTelegramToTheManagers(this.idapp, addtext + text); + } + return 0; + }); } catch (e) { console.error(e); - return 0 + return 0; } } @@ -2716,24 +3051,28 @@ class Telegram { if (telegid > 0) { await this.sistemaRecDest(rec, msg); // await this.sendMsg(msg.chat.id, '[Msg inviato a ' + username + ']: '); - await this.sendMsg(telegid, Menu.CHAT_PERSONALE + '[' + rec.username_bo + ' ti scrive]:\n' + text, MenuChat); + await this.sendMsg(telegid, + Menu.CHAT_PERSONALE + '[' + rec.username_bo + ' ti scrive]:\n' + + text, MenuChat); } else { await this.sendMsg(msg.chat.id, 'Username non valido'); - rec.msgall_username_specifico = '' + rec.msgall_username_specifico = ''; } } } - async sendMsg(id, text, menu, form, msg_id, chat_id, ripr_menuPrec) { if (text.length > 4090) { let text1 = text.slice(0, 4090); let text2 = text.slice(4090, text.length); - await this._inviaMsg(id, text1, form, menu, msg_id, chat_id, ripr_menuPrec); - return await this._inviaMsg(id, text2, form, menu, msg_id, chat_id, ripr_menuPrec); + await this._inviaMsg(id, text1, form, menu, msg_id, chat_id, + ripr_menuPrec); + return await this._inviaMsg(id, text2, form, menu, msg_id, chat_id, + ripr_menuPrec); } else { - return await this._inviaMsg(id, text, form, menu, msg_id, chat_id, ripr_menuPrec); + return await this._inviaMsg(id, text, form, menu, msg_id, chat_id, + ripr_menuPrec); } } @@ -2754,8 +3093,8 @@ class Telegram { let mykeyb = { parse_mode: 'HTML', reply_markup: { - inline_keyboard: [] - } + inline_keyboard: [], + }, }; // text @@ -2797,15 +3136,14 @@ class Telegram { const lang = this.getlang(msg); this._inviaMsg(msg.from.id, domanda, { - "reply_markup": { - "resize_keyboard": true, + 'reply_markup': { + 'resize_keyboard': true, 'one_time_keyboard': true, - "keyboard": this.getmenuKey(MenuYesNo, lang) - } + 'keyboard': this.getmenuKey(MenuYesNo, lang), + }, }); } - async ScegliLang(msg, lang) { const rec = this.getRecInMem(msg); if (rec) { @@ -2822,13 +3160,13 @@ class Telegram { } async msgScegliMenu(msg) { - // const rec = this.getRecInMem(msg); this._inviaMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_SCEGLI_MENU'), { - "parse_mode": "HTML", - "reply_markup": { - "resize_keyboard": true, - "keyboard": await this.getKeyboard(msg.from.id, undefined, this.getlang(msg)) - } + 'parse_mode': 'HTML', + 'reply_markup': { + 'resize_keyboard': true, + 'keyboard': await this.getKeyboard(msg.from.id, undefined, + this.getlang(msg)), + }, }); } } @@ -2851,7 +3189,6 @@ function getclTelegByidapp(idapp) { idapp = appTelegramDest[ind]; // Invia } - const rec = arrTelegram.find((rec) => rec.idapp === idapp); if (!!rec) return rec.cl; @@ -2863,143 +3200,149 @@ function getclTelegByidapp(idapp) { if (true) { let arrTeleg = appTelegram; if (process.env.NODE_ENV === 'development') + arrTeleg = appTelegram_DEVELOP; + else if (process.env.NODE_ENV === 'test') arrTeleg = appTelegram_TEST; - console.log('TELEGRAM STARTING.... '); + console.log('TELEGRAM STARTING.... NODE_ENV:' + process.env.NODE_ENV); for (const idapp of arrTeleg) { - const token = tools.getTelegramKeyByIdApp(idapp); - // console.log('idapp', idapp, 'token', token); + try { + const token = tools.getTelegramKeyByIdApp(idapp); + const nomebot = tools.getTelegramBotNameByIdApp(idapp); + // console.log('idapp', idapp, 'token', token); - if (!!token) { - const bot = new TelegramBot(token, { polling: true }); + if (!!token) { + console.log('*** START BOT ' + nomebot); + 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}`); + 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) => { + const myclTelegram = getclTelegBytoken(bot.token); + + myclTelegram.start(msg); + + }); + + // Matches "/echo [whatever]" + bot.onText(/\/echo (.+)/, (msg, match) => { + // 'msg' is the received Message from Telegram + // 'match' is the result of executing the regexp above on the text content + // of the message + + const chatId = msg.chat.id; + const resp = match[1]; // the captured "whatever" + + // send back the matched "whatever" to the chat + bot.sendMessage(chatId, resp); + }); + + // Listen for any kind of message. There are different kinds of + // messages. + bot.on('message', (msg) => { + + const myclTelegram = getclTelegBytoken(bot.token); + + // const chatId = msg.chat.id; + + myclTelegram.receiveMsg(msg); + }); + + // Handle callback queries + bot.on('callback_query', async (callbackQuery) => { + // console.log('callback_query', callbackQuery); + + const myclTelegram = getclTelegBytoken(bot.token); + + let dataarr = []; + let data = { + action: 0, + username: '', + }; + + const datastr = callbackQuery.data; + if (!!datastr) { + dataarr = datastr.split('|'); + if (!!dataarr) { + data = { + action: dataarr[0], + username: dataarr[1], + }; + } + } + 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); + const user = await User.getUserShortDataByUsername(idapp, + data.username); + if (!!rec) { + if (!!user) { + if (data.action === InlineCmd.VOGLIO_IMBARCARMI) { + // Controlla se è qualificato! + const mydata = tools.AddDate(user.date_reg, 7); + + const newrecingr = await ListaIngresso.addUserInListaIngresso( + user.idapp, user.username, user.aportador_solidario, + user.lang, true, true, mydata); + + bot.editMessageText( + tools.gettranslate('ADDED_TOLISTAINGRESSO', user.lang), + opts); + + } else if (data.action === InlineCmd.NON_VOGLIO_IMBARCARMI) { + await User.NonVoglioImbarcarmi(user.idapp, user.username); + + const msgadd = '[' + user.username + '] ' + user.name + ' ' + + user.surname + ' ha risposto che NON VUOLE IMBARCARSI !'; + + await local_sendMsgTelegramToTheManagers(user.idapp, msgadd, + msg, false); // Anche a STAFF + } else if (data.action === + InlineZoomConferma.CONFERMA_ZOOM_PRESENZA) { + + await User.setZoomPresenza(user.idapp, user._id, true); + + } else if (data.action === + InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA) { + + await User.setZoomPresenza(user.idapp, user._id, false); + + } + } + } + + /* + let text; + + if (action === 'edit') { + text = 'Edited Text'; + } + + bot.editMessageText(text, opts); + */ + + // bot.answerCallbackQuery(callbackQuery.id, { url }); }); } - - arrTelegram.push({ idapp, cl: new Telegram(idapp, bot) }); - - bot.onText(/\/start/, (msg) => { - const myclTelegram = getclTelegBytoken(bot.token); - - myclTelegram.start(msg); - - - }); - - // Matches "/echo [whatever]" - bot.onText(/\/echo (.+)/, (msg, match) => { - // 'msg' is the received Message from Telegram - // 'match' is the result of executing the regexp above on the text content - // of the message - - - const chatId = msg.chat.id; - const resp = match[1]; // the captured "whatever" - - // send back the matched "whatever" to the chat - bot.sendMessage(chatId, resp); - }); - - // Listen for any kind of message. There are different kinds of - // messages. - bot.on('message', (msg) => { - - const myclTelegram = getclTelegBytoken(bot.token); - - // console.log('msg', msg); - const chatId = msg.chat.id; - - myclTelegram.receiveMsg(msg); - // var bye = "bye"; - // if (msg.text.toString().toLowerCase().includes(bye)) { - // bot.sendMessage(msg.chat.id, "Hope to see you around again , Bye"); - // } - - // send a message to the chat acknowledging receipt of their message - // bot.sendMessage(chatId, 'Received your message'); - }); - - // Handle callback queries - bot.on('callback_query', async (callbackQuery) => { - // console.log('callback_query', callbackQuery); - - const myclTelegram = getclTelegBytoken(bot.token); - - let dataarr = []; - let data = { - action: 0, - username: '' - }; - - const datastr = callbackQuery.data; - if (!!datastr) { - dataarr = datastr.split("|"); - if (!!dataarr) { - data = { - action: dataarr[0], - username: dataarr[1], - } - } - } - 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); - const user = await User.getUserShortDataByUsername(idapp, data.username); - if (!!rec) { - if (!!user) { - if (data.action === InlineCmd.VOGLIO_IMBARCARMI) { - // Controlla se è qualificato! - const mydata = tools.AddDate(user.date_reg, 7); - - const newrecingr = await ListaIngresso.addUserInListaIngresso(user.idapp, user.username, user.aportador_solidario, user.lang, true, true, mydata); - - bot.editMessageText(tools.gettranslate('ADDED_TOLISTAINGRESSO', user.lang), opts); - - } else if (data.action === InlineCmd.NON_VOGLIO_IMBARCARMI) { - await User.NonVoglioImbarcarmi(user.idapp, user.username); - - const msgadd = '[' + user.username + '] ' + user.name + ' ' + user.surname + ' ha risposto che NON VUOLE IMBARCARSI !'; - - await local_sendMsgTelegramToTheManagers(user.idapp, msgadd, msg, false); // Anche a STAFF - } else if (data.action === InlineZoomConferma.CONFERMA_ZOOM_PRESENZA) { - - await User.setZoomPresenza(user.idapp, user._id, true); - - } else if (data.action === InlineZoomConferma.NON_CONFERMA_ZOOM_PRESENZA) { - - await User.setZoomPresenza(user.idapp, user._id, false); - - } - } - } - - /* - let text; - - if (action === 'edit') { - text = 'Edited Text'; - } - - bot.editMessageText(text, opts); - */ - - // bot.answerCallbackQuery(callbackQuery.id, { url }); - }); + } catch (e) { + console.error('Error Telegram LOOP : ' + e.message); } - } } diff --git a/src/server/tools/general.js b/src/server/tools/general.js index 44dd42f..623c00f 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -384,6 +384,7 @@ module.exports = { FREEPLANET: '1', AYNI: '7', CNM: '10', + PDNM: '12', HELP_CHAT: '', TYPECONF_ZOOM: 'zoom', @@ -918,7 +919,7 @@ module.exports = { const myapp = this.getApps().find(item => item.idapp === idapp); if (myapp) - return myapp.name; + return ((process.env.NODE_ENV === 'test') ? 'Test: ' : '') + myapp.name; else return ''; }, @@ -928,9 +929,13 @@ module.exports = { const myapp = this.getApps().find(item => item.idapp === idapp); if (myapp) { - let siteport = (myapp.portapp !== '0') ? (':' + myapp.portapp) : ''; + let siteport = (myapp.portapp && myapp.portapp !== '0') ? (':' + myapp.portapp) : ''; + + if (process.env.NODE_ENV === 'test') + return myapp.host_test + siteport; + else + return myapp.host + siteport; - return myapp.host + siteport; } else return ''; }, @@ -945,7 +950,10 @@ module.exports = { const myapp = this.getApps().find(item => item.idapp === idapp); if (myapp) { - return myapp.dir; + if (process.env.NODE_ENV === 'test') + return (myapp) ? myapp.dir_test : ''; + else + return (myapp) ? myapp.dir : ''; } else return ''; }, @@ -977,6 +985,15 @@ module.exports = { } }, + getAskToVerifyReg: function(idapp) { + const myapp = this.getApps().find((item) => item.idapp === idapp); + if (myapp) { + return myapp.ask_to_verify_reg; + } else { + return false; + } + }, + isManagAndAdminDifferent(idapp) { const manag = this.getManagerEmailByIdApp(idapp); return (manag !== this.getAdminEmailByIdApp(idapp)) && (manag !== ''); @@ -1002,13 +1019,19 @@ module.exports = { getTelegramBotNameByIdApp: function(idapp) { const myapp = this.getApps().find((item) => item.idapp === idapp); - return (myapp) ? myapp.telegram_bot_name : ''; + if (process.env.NODE_ENV === 'test') + return (myapp) ? myapp.telegram_bot_name_test : ''; + else + return (myapp) ? myapp.telegram_bot_name : ''; }, getTelegramKeyByIdApp: function(idapp) { const myarr = this.getApps(); const myapp = myarr.find((item) => item.idapp === idapp); - return (myapp) ? myapp.telegram_key : ''; + if (process.env.NODE_ENV === 'test') + return (myapp) ? myapp.telegram_key_test : ''; + else + return (myapp) ? myapp.telegram_key : ''; }, getLookup: function(params, num, pass_proj) { @@ -1069,10 +1092,7 @@ module.exports = { throw new Error('endRow must be number'); } - let newvers = true; - - if (params.lk_LF) - newvers = false; + let newvers = !!params.lookup1; let query = []; @@ -1236,8 +1256,10 @@ module.exports = { filtriadded.push(...params.filtersearch); } - if (filtriadded.length > 0) - query.push({$match: {$and: filtriadded}}); + if (filtriadded) { + if (filtriadded.length > 0) + query.push({$match: {$and: filtriadded}}); + } if (idapp > 0) { query.push({$match: {idapp}}); @@ -1275,8 +1297,10 @@ module.exports = { const q4 = this.getLookup(params.lookup4, 4, proj); if (q4) query = [...query, ...q4]; - if (params.filtersearch2.length > 0) { - query.push({$match: {$and: params.filtersearch2}}); + if (params.filtersearch2) { + if (params.filtersearch2.length > 0) { + query.push({$match: {$and: params.filtersearch2}}); + } } } else { @@ -1779,12 +1803,16 @@ module.exports = { }, cryptdata(mydata) { + if (mydata === '') + return ''; // Encrypt //return CryptoJS.AES.encrypt(JSON.stringify(mydata), process.env.SECRK); return this.encrypt(mydata, process.env.SECRK); }, decryptdata(mydatacrypted) { + if (mydatacrypted === '') + return ''; // Decrypt // const bytes = CryptoJS.AES.decrypt(mydatacrypted.toString(), process.env.SECRK); // return JSON.parse(bytes.toString(CryptoJS.enc.Utf8)); diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js index 034577f..d79b4f2 100755 --- a/src/server/tools/shared_nodejs.js +++ b/src/server/tools/shared_nodejs.js @@ -32,15 +32,24 @@ module.exports = { FILTER_MYSKILL_SKILL: 1, + FRIENDSCMD: { + SETTRUST: 121, + SETFRIEND: 132, + REMOVE_FROM_MYFRIENDS: 144, + BLOCK_USER: 155, + }, + REPORT_FILT_RESP: 1, REPORT_FILT_ATTIVITA: 2, TAB_COUNTRY: 'countries', TAB_PHONES: 'phones', TAB_SETTINGS: 'settings', + TAB_SITES: 'sites', TAB_MYBOTS: 'mybots', KEY_TO_CRYPTED: ['PWD_FROM'], + SITES_KEY_TO_CRYPTED: ['email_pwd'], TablePickup: ['countries', 'phones'], TableCities: ['citta', 'province'], diff --git a/yarn.lock b/yarn.lock index 3691382..e92b90d 100755 --- a/yarn.lock +++ b/yarn.lock @@ -6491,15 +6491,15 @@ mongodb-connection-string-url@^2.0.0: "@types/whatwg-url" "^8.2.1" whatwg-url "^9.1.0" -mongodb@3.6.11: - version "3.6.11" - resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.6.11.tgz#8a59a0491a92b00a8c925f72ed9d9a5b054aebb2" - integrity sha512-4Y4lTFHDHZZdgMaHmojtNAlqkvddX2QQBEN0K//GzxhGwlI9tZ9R0vhbjr1Decw+TF7qK0ZLjQT292XgHRRQgw== +mongodb@3.7.3: + version "3.7.3" + resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.7.3.tgz#b7949cfd0adc4cc7d32d3f2034214d4475f175a5" + integrity sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw== dependencies: bl "^2.2.1" bson "^1.1.4" denque "^1.4.1" - optional-require "^1.0.3" + optional-require "^1.1.8" safe-buffer "^5.1.2" optionalDependencies: saslprep "^1.0.0" @@ -6520,16 +6520,16 @@ mongoose-legacy-pluralize@1.0.2: resolved "https://registry.yarnpkg.com/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz#3ba9f91fa507b5186d399fb40854bff18fb563e4" integrity sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ== -mongoose@^5.13.9: - version "5.13.9" - resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.13.9.tgz#4421a13566daea8fcc80149734c76e5641f477ce" - integrity sha512-JbLw5ie0LJxm7V9LoNxRY//6cyFJf0cOpON2TWUWvF9pabil6ArfECL3xHV2N+mwwO4gXiIa+c0pwTzDUVTgqw== +mongoose@^5.13.13: + version "5.13.14" + resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.13.14.tgz#ffc9704bd022dd018fbddcbe27dc802c77719fb4" + integrity sha512-j+BlQjjxgZg0iWn42kLeZTB91OejcxWpY2Z50bsZTiKJ7HHcEtcY21Godw496GMkBqJMTzmW7G/kZ04mW+Cb7Q== dependencies: "@types/bson" "1.x || 4.0.x" "@types/mongodb" "^3.5.27" bson "^1.1.4" kareem "2.3.2" - mongodb "3.6.11" + mongodb "3.7.3" mongoose-legacy-pluralize "1.0.2" mpath "0.8.4" mquery "3.2.5" @@ -7026,10 +7026,10 @@ optional-require@1.0.x: resolved "https://registry.yarnpkg.com/optional-require/-/optional-require-1.0.3.tgz#275b8e9df1dc6a17ad155369c2422a440f89cb07" integrity sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA== -optional-require@^1.0.3: - version "1.1.7" - resolved "https://registry.yarnpkg.com/optional-require/-/optional-require-1.1.7.tgz#9ab5b254f59534108d4b2201d9ae96a063abc015" - integrity sha512-cIeRZocXsZnZYn+SevbtSqNlLbeoS4mLzuNn4fvXRMDRNhTGg0sxuKXl0FnZCtnew85LorNxIbZp5OeliILhMw== +optional-require@^1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/optional-require/-/optional-require-1.1.8.tgz#16364d76261b75d964c482b2406cb824d8ec44b7" + integrity sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA== dependencies: require-at "^1.0.6"