Version 0.5.25

Registration with no need to insert "invitante"
This commit is contained in:
paoloar77
2022-11-02 15:00:13 +01:00
parent f3c26b798b
commit 03722c1867
3 changed files with 95 additions and 22 deletions

View File

@@ -63,5 +63,6 @@
"CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario (%s) può accumulare", "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", "CIRCUIT_COINS_ALREADY_PROCESSED": "La richiesta è stata già processata. Stato %s",
"STATUS_SENT": "Inviato", "STATUS_SENT": "Inviato",
"STATUS_REFUSED": "Rifiutato" "STATUS_REFUSED": "Rifiutato",
"CLICCA_QUI": "CLICCA QUI"
} }

View File

@@ -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) { sendEmail_CancelBooking: async function(res, lang, emailto, user, idapp, recbooking) {
tools.mylog('sendEmail_CancelBooking'); tools.mylog('sendEmail_CancelBooking');
@@ -403,8 +407,7 @@ module.exports = {
mylocalsconf = await this.preparaConfPerBooking(res, idapp, mylocalsconf, recbooking, 'Cancellazione'); mylocalsconf = await this.preparaConfPerBooking(res, idapp, mylocalsconf, recbooking, 'Cancellazione');
let msgtelegram = 'Cancellazione Evento [' + mylocalsconf.name + ' (' + mylocalsconf.name + ' ' + mylocalsconf.surname + ')] ' + let msgtelegram = 'Cancellazione Evento [' + this.getName(mylocalsconf) + '] ' + mylocalsconf.eventtextplain;
mylocalsconf.eventtextplain;
telegrambot.sendMsgTelegramToTheManagers(idapp, msgtelegram); telegrambot.sendMsgTelegramToTheManagers(idapp, msgtelegram);

View File

@@ -3,7 +3,7 @@ const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.RISO]; const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.ARCADEI, 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 appTelegramFinti = ['2', tools.CNM, tools.ARCADEI];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET, tools.FREEPLANET]; const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET, tools.FREEPLANET];
@@ -887,11 +887,13 @@ const MyTelegramBot = {
keyb = cl.getInlineKeyboard(myuser.lang, [ keyb = cl.getInlineKeyboard(myuser.lang, [
{ {
text: '✅ Accetta ' + myuser.username, 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, 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 += tools.get__('VERIF', this.getlang(msg));
mystr += '\n3. ' + this.getsymb(emo.PENCIL, mystr += '\n3. ' + this.getsymb(emo.PENCIL,
tools.isBitActive(user.profile.saw_and_accepted, tools.isBitActive(user.profile.saw_and_accepted,
shared_consts.Accepted.CHECK_READ_GUIDELINES)) + shared_consts.Accepted.CHECK_READ_GUIDELINES)) +
tools.get__('LINEE_GUIDA', this.getlang(msg)); tools.get__('LINEE_GUIDA', this.getlang(msg));
mystr += '\n4. ' + this.getsymb(emo.TV, mystr += '\n4. ' + this.getsymb(emo.TV,
tools.isBitActive(user.profile.saw_and_accepted, tools.isBitActive(user.profile.saw_and_accepted,
shared_consts.Accepted.CHECK_SEE_VIDEO_PRINCIPI)) + shared_consts.Accepted.CHECK_SEE_VIDEO_PRINCIPI)) +
tools.get__('VIDEO_INTRO', this.getlang(msg)); 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 += '\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 += '\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 { try {
let rec = this.getRecInMem(msg); let rec = this.getRecInMem(msg);
if (msg.text === undefined || msg.text === 'undefined') if (msg.text === undefined || msg.text === 'undefined')
return false; return false;
if (rec) { if (rec && !rec.aportador_solidario) {
rec.status = Status.SET_USERNAME_INVITANTE; 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)); 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) { } catch (e) {
console.error('Error setUsernameBo:', e); console.error('Error setUsernameBo:', e);
@@ -2584,11 +2588,13 @@ class Telegram {
async setUsernameInvitante(msg) { async setUsernameInvitante(msg) {
try { try {
if (!!msg.text) { let mymsg = msg.text.toString().trim().toLowerCase();
if (!!mymsg) {
const rec = this.getRecInMem(msg); const rec = this.getRecInMem(msg);
let aportador_solidario = rec.aportador_solidario; let aportador_solidario = rec.aportador_solidario;
if (!aportador_solidario) { if (!aportador_solidario) {
aportador_solidario = msg.text.toString().trim().toLowerCase(); aportador_solidario = mymsg;
aportador_solidario = tools.removeAtChar(aportador_solidario); aportador_solidario = tools.removeAtChar(aportador_solidario);
let user = await User.getUserShortDataByUsername(this.idapp, aportador_solidario); let user = await User.getUserShortDataByUsername(this.idapp, aportador_solidario);
if (!user) { if (!user) {
@@ -2954,6 +2960,41 @@ class Telegram {
return status; 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) { async receiveMsg(msg) {
// Check if Username Telegram Present // Check if Username Telegram Present
@@ -2974,9 +3015,22 @@ class Telegram {
// await this.setUsernameBo(msg); // await this.setUsernameBo(msg);
await this.settotheDatabase(msg); await this.settotheDatabase(msg);
} else if (status === Status.WAITFOR_USERNAME_INVITANTE && !this.selectMenuHelp(msg) && !this.selectMenuLang(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); // await this.settotheDatabase(msg);
} else if (status === Status.SET_USERNAME_INVITANTE) { } 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); await this.setUsernameInvitante(msg);
} else if (status === Status.NONE) { } else if (status === Status.NONE) {
await this.start(msg); await this.start(msg);
@@ -3081,12 +3135,12 @@ class Telegram {
let linkreg = tools.getLinkRegByIdAppAndMsgStrutt(this.idapp, msg, rec); let linkreg = tools.getLinkRegByIdAppAndMsgStrutt(this.idapp, msg, rec);
if (process.env.LOCALE === '1') { 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), [ const keyb = this.getInlineKeyboard(this.getlang(msg), [
{ {
text: '✅ CLICCA QUI ', text: '✅ ' + i18n.__('CLICCA_QUI'),
url: linkreg, 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); 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) { } else if (status === Status.WAITFOR_USERNAME_INVITANTE) {
await this.askUsernameInvitante(msg); await this.askUsernameInvitante(msg, false);
} }
return false; return false;
@@ -3204,6 +3258,9 @@ class Telegram {
this.arrUsers.push(rec); this.arrUsers.push(rec);
// Aportador
this.setInvitante(msg, this.getInvitanteByMsg(msg), false);
return rec; return rec;
} }
@@ -3258,7 +3315,7 @@ class Telegram {
rec.active_mem = false; rec.active_mem = false;
if (rec.active && rec.page === recuser.pagenow if (rec.active && rec.page === recuser.pagenow
&& (tools.isBitAttivoESelez(rec.visibility, && (tools.isBitAttivoESelez(rec.visibility,
shared_consts.VISIB_ONLY_ADMIN, isAdmin) && shared_consts.VISIB_ONLY_ADMIN, isAdmin) &&
tools.isBitAttivoESelez(rec.visibility, tools.isBitAttivoESelez(rec.visibility,
shared_consts.VISIB_ONLY_MANAGER, isManager) && shared_consts.VISIB_ONLY_MANAGER, isManager) &&
tools.isBitAttivoESelez(rec.visibility, tools.isBitAttivoESelez(rec.visibility,
@@ -3796,12 +3853,24 @@ if (true) {
// Listen for any kind of message. There are different kinds of // Listen for any kind of message. There are different kinds of
// messages. // messages.
bot.on('message', (msg) => { bot.on('message', async (msg) => {
const myclTelegram = getclTelegBytoken(bot.token); 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); myclTelegram.receiveMsg(msg);
}); });