From 03722c1867509750d7e0f41a93ef6e7ccefcbe88 Mon Sep 17 00:00:00 2001 From: paoloar77 Date: Wed, 2 Nov 2022 15:00:13 +0100 Subject: [PATCH] Version 0.5.25 Registration with no need to insert "invitante" --- src/server/locales/it.json | 3 +- src/server/sendemail.js | 7 +- src/server/telegram/telegrambot.js | 107 ++++++++++++++++++++++++----- 3 files changed, 95 insertions(+), 22 deletions(-) diff --git a/src/server/locales/it.json b/src/server/locales/it.json index f74902f..e114a21 100644 --- a/src/server/locales/it.json +++ b/src/server/locales/it.json @@ -63,5 +63,6 @@ "CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario (%s) può accumulare", "CIRCUIT_COINS_ALREADY_PROCESSED": "La richiesta è stata già processata. Stato %s", "STATUS_SENT": "Inviato", - "STATUS_REFUSED": "Rifiutato" + "STATUS_REFUSED": "Rifiutato", + "CLICCA_QUI": "CLICCA QUI" } diff --git a/src/server/sendemail.js b/src/server/sendemail.js index 0990ce1..3cecaa2 100755 --- a/src/server/sendemail.js +++ b/src/server/sendemail.js @@ -380,6 +380,10 @@ module.exports = { }, + getName: function(mylocalsconf) { + return mylocalsconf.name ? (mylocalsconf.surname ? (mylocalsconf.name + ' ' + mylocalsconf.surname) : mylocalsconf.name) : mylocalsconf.username + }, + sendEmail_CancelBooking: async function(res, lang, emailto, user, idapp, recbooking) { tools.mylog('sendEmail_CancelBooking'); @@ -403,8 +407,7 @@ module.exports = { mylocalsconf = await this.preparaConfPerBooking(res, idapp, mylocalsconf, recbooking, 'Cancellazione'); - let msgtelegram = 'Cancellazione Evento [' + mylocalsconf.name + ' (' + mylocalsconf.name + ' ' + mylocalsconf.surname + ')] ' + - mylocalsconf.eventtextplain; + let msgtelegram = 'Cancellazione Evento [' + this.getName(mylocalsconf) + '] ' + mylocalsconf.eventtextplain; telegrambot.sendMsgTelegramToTheManagers(idapp, msgtelegram); diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 39169a1..5e52bbe 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -3,7 +3,7 @@ const tools = require('../tools/general'); const appTelegram = [tools.FREEPLANET, tools.RISO]; const appTelegram_TEST = [tools.FREEPLANET, tools.ARCADEI, tools.RISO]; -const appTelegram_DEVELOP = [tools.RISO, tools.FREEPLANET]; +const appTelegram_DEVELOP = [tools.RISO]; const appTelegramFinti = ['2', tools.CNM, tools.ARCADEI]; const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET, tools.FREEPLANET]; @@ -887,11 +887,13 @@ const MyTelegramBot = { keyb = cl.getInlineKeyboard(myuser.lang, [ { text: '✅ Accetta ' + myuser.username, - callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP + groupid, + callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP + + groupid, }, { text: '🚫 Rifiuta ' + myuser.username, - callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP + groupid, + callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP + + groupid, }, ]); } @@ -2026,12 +2028,12 @@ class Telegram { 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.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.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)); @@ -2502,16 +2504,18 @@ class Telegram { } - async askUsernameInvitante(msg) { + async askUsernameInvitante(msg, linkreg) { try { let rec = this.getRecInMem(msg); if (msg.text === undefined || msg.text === 'undefined') return false; - if (rec) { + if (rec && !rec.aportador_solidario) { rec.status = Status.SET_USERNAME_INVITANTE; await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_ASK_USERNAME_INVITANTE', tools.getNomeAppByIdApp(this.idapp), null)); - + } else { + // if (linkreg) + // this.asktoRegistrationByLink(msg); } } catch (e) { console.error('Error setUsernameBo:', e); @@ -2584,11 +2588,13 @@ class Telegram { async setUsernameInvitante(msg) { try { - if (!!msg.text) { + let mymsg = msg.text.toString().trim().toLowerCase(); + + if (!!mymsg) { const rec = this.getRecInMem(msg); let aportador_solidario = rec.aportador_solidario; if (!aportador_solidario) { - aportador_solidario = msg.text.toString().trim().toLowerCase(); + aportador_solidario = mymsg; aportador_solidario = tools.removeAtChar(aportador_solidario); let user = await User.getUserShortDataByUsername(this.idapp, aportador_solidario); if (!user) { @@ -2954,6 +2960,41 @@ class Telegram { return status; } + getInvitanteByMsg(msg) { + try { + + let mymsg = msg.text.toString().trim().toLowerCase(); + let invitante = ''; + if (mymsg.startsWith('/start')) { + let myarrmsg = mymsg.split(' '); + if (myarrmsg.length > 0) { + mymsg = myarrmsg[1]; + if (mymsg.startsWith('inv_')) { + invitante = mymsg.substring(4); + return invitante; + } + } + } + } catch (e) { + + } + return ''; + } + + async setInvitante(msg, invitante, crea) { + let rec = this.getRecInMem(msg); + if (!rec && crea) { + let status = await this.setInit(msg); + rec = this.getRecInMem(msg); + } + if (rec) { + if (!rec.aportador_solidario && invitante) { + rec.aportador_solidario = invitante; + rec.status = Status.SET_USERNAME_INVITANTE; + } + } + } + async receiveMsg(msg) { // Check if Username Telegram Present @@ -2974,9 +3015,22 @@ class Telegram { // await this.setUsernameBo(msg); await this.settotheDatabase(msg); } else if (status === Status.WAITFOR_USERNAME_INVITANTE && !this.selectMenuHelp(msg) && !this.selectMenuLang(msg)) { - await this.askUsernameInvitante(msg); + await this.askUsernameInvitante(msg, true); // await this.settotheDatabase(msg); } else if (status === Status.SET_USERNAME_INVITANTE) { + let mymsg = msg.text.toString().trim().toLowerCase(); + let invitante = ''; + if (mymsg && mymsg.startsWith('/start')) { + let myarrmsg = mymsg.split(' '); + if (myarrmsg.length > 0) { + mymsg = myarrmsg[1]; + if (mymsg && mymsg.startsWith('inv_')) { + invitante = mymsg.substring(4); + await this.setInvitante(msg, invitante); + } + } + } + await this.setUsernameInvitante(msg); } else if (status === Status.NONE) { await this.start(msg); @@ -3081,12 +3135,12 @@ class Telegram { let linkreg = tools.getLinkRegByIdAppAndMsgStrutt(this.idapp, msg, rec); if (process.env.LOCALE === '1') { - linkreg = 'http://192.168.1.115:8084/signup/' + rec.aportador_solidario + '/' + msg.from.username + '/' + msg.from.id; + // linkreg = 'http://localhost:8084/signup/' + rec.aportador_solidario + '/' + msg.from.username + '/' + msg.from.id; } const keyb = this.getInlineKeyboard(this.getlang(msg), [ { - text: '✅ CLICCA QUI ', + text: '✅ ' + i18n.__('CLICCA_QUI'), url: linkreg, }, ]); @@ -3095,7 +3149,7 @@ class Telegram { await this.sendMsg(msg.chat.id, getstr(this.getlang(msg), 'MSG_SIGNUP', tools.getNomeAppByIdApp(this.idapp)), null, keyb); } else if (status === Status.WAITFOR_USERNAME_INVITANTE) { - await this.askUsernameInvitante(msg); + await this.askUsernameInvitante(msg, false); } return false; @@ -3204,6 +3258,9 @@ class Telegram { this.arrUsers.push(rec); + // Aportador + this.setInvitante(msg, this.getInvitanteByMsg(msg), false); + return rec; } @@ -3258,7 +3315,7 @@ class Telegram { rec.active_mem = false; if (rec.active && rec.page === recuser.pagenow && (tools.isBitAttivoESelez(rec.visibility, - shared_consts.VISIB_ONLY_ADMIN, isAdmin) && + shared_consts.VISIB_ONLY_ADMIN, isAdmin) && tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_MANAGER, isManager) && tools.isBitAttivoESelez(rec.visibility, @@ -3796,12 +3853,24 @@ if (true) { // Listen for any kind of message. There are different kinds of // messages. - bot.on('message', (msg) => { + bot.on('message', async (msg) => { const myclTelegram = getclTelegBytoken(bot.token); - // const chatId = msg.chat.id; + let mymsg = msg.text.toString().trim().toLowerCase(); + let invitante = ''; + if (mymsg && mymsg.startsWith('/start')) { + let myarrmsg = mymsg.split(' '); + if (myarrmsg.length > 0) { + mymsg = myarrmsg[1]; + if (mymsg && mymsg.startsWith('inv_')) { + invitante = mymsg.substring(4); + // await myclTelegram.setInvitante(msg, invitante); + } + } + } + // const chatId = msg.chat.id; myclTelegram.receiveMsg(msg); });