Non permettere il cambio del codice del gruppo

disattivare l'abilitazione se la registrazione arriva da me paoloar77
Sistemato il Menu del BOT per inviare msg a tutti e per ricevere il proprio Link personale.
Non permettere il cambio del codice del gruppo
Aggiunta la Provincia tra parentesi nei Comuni: es Rimini (RN)
This commit is contained in:
paoloar77
2022-02-26 17:35:50 +01:00
parent 574d192661
commit 2749506de7
7 changed files with 241 additions and 119 deletions

View File

@@ -65,7 +65,7 @@ BotSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {idapp}; const myfind = {idapp};
return Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}); return Bot.find(myfind).sort({page: 1, lang: 1, riga: 1, index: 1}).lean();
}; };
const MyBot = mongoose.model('Bot', BotSchema); const MyBot = mongoose.model('Bot', BotSchema);

View File

@@ -114,24 +114,50 @@ CitySchema.statics.executeQueryPickup = async function(idapp, params) {
} }
let filterfindexact = {}; let filterfindexact = {};
if (strfind){ if (strfind) {
filterfindexact = {comune: strfind}; filterfindexact = {comune: strfind};
} }
let limit = 10 let limit = 10;
let risexact = [] let risexact = [];
let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}}; let filterfind = {comune: {$regex: '^' + strfind, $options: 'i'}};
let aggr1 = [
{
$match: {comune: strfind},
},
{ $limit : 1 },
{
$project: {
comune: { $concat: ["$comune", " (", "$prov", ")"] },
},
},
];
if (params.filter) { if (params.filter) {
filterfind = {...params.filter, ...filterfind} filterfind = {...params.filter, ...filterfind};
limit = 200 limit = 200;
} else{ } else {
risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean(); // risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
risexact = await City.aggregate(aggr1);
} }
let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit); let aggr2 = [
{
$match: filterfind,
},
{ $limit : limit },
{
$project: {
comune: { $concat: ["$comune", " (", "$prov", ")"] },
},
},
];
// let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit);
let ris = await City.aggregate(aggr2).limit(limit);
return [...risexact, ...ris]; return [...risexact, ...ris];

View File

@@ -145,6 +145,9 @@ const UserSchema = new mongoose.Schema({
verified_by_aportador: { verified_by_aportador: {
type: Boolean, type: Boolean,
}, },
notask_verif: {
type: Boolean,
},
trust_modified: { trust_modified: {
type: Date, type: Date,
}, },
@@ -880,6 +883,24 @@ UserSchema.statics.setVerifiedByAportador = async function(
return !!myrec; return !!myrec;
}; };
UserSchema.statics.setnotask_verif = async function(
idapp, username, valuebool) {
const User = this;
if (username === undefined)
return false;
const myquery = {
'idapp': idapp,
'username': username,
};
const myrec = await User.findOneAndUpdate(myquery,
{$set: {'notask_verif': valuebool}}, {new: false});
return !!myrec;
};
UserSchema.statics.setVerifiedByAportadorToALL = async function() { UserSchema.statics.setVerifiedByAportadorToALL = async function() {
return User.updateMany({}, {$set: {'verified_by_aportador': true}}, return User.updateMany({}, {$set: {'verified_by_aportador': true}},
@@ -1247,6 +1268,7 @@ UserSchema.statics.getUserProfileByUsername = async function(
sospeso: 1, sospeso: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
notask_verif: 1,
'profile.nationality': 1, 'profile.nationality': 1,
'profile.qualifica': 1, 'profile.qualifica': 1,
'profile.biografia': 1, 'profile.biografia': 1,
@@ -1641,6 +1663,7 @@ function getWhatToShow(idapp, username) {
sospeso: 1, sospeso: 1,
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
notask_verif: 1,
'profile.nationality': 1, 'profile.nationality': 1,
'profile.qualifica': 1, 'profile.qualifica': 1,
'profile.biografia': 1, 'profile.biografia': 1,
@@ -1857,6 +1880,18 @@ UserSchema.statics.TelegIdByUsername = async function(idapp, username) {
console.error('TelegIdByUsername', e); console.error('TelegIdByUsername', e);
}); });
}; };
UserSchema.statics.notAsk_VerifByUsername = async function(idapp, username) {
return User.findOne({
idapp, username,
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
}, {'notask_verif': 1}).then((rec) => {
return (!!rec && rec.notask_verif) ? true: false;
}).catch((e) => {
console.error('notAsk_VerifByUsername', e);
return false;
});
};
UserSchema.statics.SetTelegramCheckCode = async function( UserSchema.statics.SetTelegramCheckCode = async function(
idapp, id, teleg_checkcode) { idapp, id, teleg_checkcode) {
@@ -2124,7 +2159,7 @@ UserSchema.statics.getusersManagers = async function(idapp) {
const User = this; const User = this;
return User.find({idapp, 'profile.manage_telegram': true}, return User.find({idapp, 'profile.manage_telegram': true},
{'profile.teleg_id': 1, perm: 1}).then((arrrec) => { {username: 1, 'profile.teleg_id': 1, perm: 1}).then((arrrec) => {
return (!!arrrec) ? arrrec : null; return (!!arrrec) ? arrrec : null;
}).catch((e) => { }).catch((e) => {
console.error('getusersManagers', e); console.error('getusersManagers', e);
@@ -2619,6 +2654,7 @@ UserSchema.statics.checkUser = async function(idapp, username) {
return User.findOne({idapp, username}, { return User.findOne({idapp, username}, {
verified_email: 1, verified_email: 1,
verified_by_aportador: 1, verified_by_aportador: 1,
notask_verif: 1,
'profile.teleg_id': 1, 'profile.teleg_id': 1,
'profile.teleg_checkcode': 1, 'profile.teleg_checkcode': 1,
}).then((rec) => { }).then((rec) => {

View File

@@ -549,13 +549,13 @@ router.post('/groups/cmd', authenticate, (req, res) => {
const cmd = req.body.cmd; const cmd = req.body.cmd;
const value = req.body.value; const value = req.body.value;
if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) { /*if (!User.isAdmin(req.user.perm) || !User.isManager(req.user.perm)) {
// If without permissions, exit // If without permissions, exit
if (usernameOrig !== usernameLogged) { if (usernameOrig !== usernameLogged) {
return res.status(404). return res.status(404).
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''}); send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
} }
} }*/
return User.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value). return User.setGroupsCmd(idapp, usernameOrig, groupnameDest, cmd, value).
then((ris) => { then((ris) => {

View File

@@ -240,10 +240,10 @@ const Menu = {
MSG_TO_USER: 'sendmsgto', MSG_TO_USER: 'sendmsgto',
ADMIN: emoji.get('information_desk_person') + ' Admin', ADMIN: emoji.get('information_desk_person') + ' Admin',
ALTRO: emoji.get('newspaper') + ' Altro', ALTRO: emoji.get('newspaper') + ' Altro',
MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi', // MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
MSG_NO_7_REQ: emoji.get('incoming_envelope') + 'No 7 Req.', // MSG_NO_7_REQ: emoji.get('incoming_envelope') + 'No 7 Req.',
MSG_NO_9_REQ: emoji.get('incoming_envelope') + 'No 9 Req', // MSG_NO_9_REQ: emoji.get('incoming_envelope') + 'No 9 Req',
NESSUN_IMBARCO_7REQ: emoji.get('incoming_envelope') + 'No Imbarco (7 Req)', // NESSUN_IMBARCO_7REQ: emoji.get('incoming_envelope') + 'No Imbarco (7 Req)',
MSG_SI_INVITATI_NO_7REQ_INVITATI: emoji.get('incoming_envelope') + MSG_SI_INVITATI_NO_7REQ_INVITATI: emoji.get('incoming_envelope') +
'Inv e NO 7 Req', 'Inv e NO 7 Req',
MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF', MSGSTAFF: emoji.get('incoming_envelope') + ' Invia a STAFF',
@@ -745,7 +745,7 @@ module.exports = {
rismsg = await this.sendMsgTelegram(mylocalsconf.idapp, userdest, text); rismsg = await this.sendMsgTelegram(mylocalsconf.idapp, userdest, text);
} }
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text); await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text, false, null, userdest);
if (phase === this.phase.REGISTRATION) { if (phase === this.phase.REGISTRATION) {
await this.askConfirmationUserRegistration(mylocalsconf.idapp, shared_consts.CallFunz.REGISTRATION, await this.askConfirmationUserRegistration(mylocalsconf.idapp, shared_consts.CallFunz.REGISTRATION,
@@ -790,8 +790,7 @@ module.exports = {
await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text); await this.sendMsgTelegramToTheManagers(mylocalsconf.idapp, addtext + text);
}, },
sendMsgTelegramToTheManagers: async function( sendMsgTelegramToTheManagers: async function(idapp, text, onlyintofile = false, MyForm = null, nottousername = '') {
idapp, text, onlyintofile = false, MyForm = null) {
tools.writeManagersLog(text); tools.writeManagersLog(text);
@@ -799,9 +798,12 @@ module.exports = {
const usersmanagers = await User.getusersManagers(idapp); const usersmanagers = await User.getusersManagers(idapp);
if (usersmanagers) { if (usersmanagers) {
for (const rec of usersmanagers) { for (const rec of usersmanagers) {
await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, if (rec.username !== nottousername) {
emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm); await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id,
await tools.snooze(100); emo.ROBOT_FACE + ': ' + text, undefined, undefined, true,
MyForm);
await tools.snooze(100);
}
} }
} }
} }
@@ -828,7 +830,6 @@ module.exports = {
return true; return true;
}, },
getMsgByTipoMsg: async function(mydata, lang, user, sonosognatore) { getMsgByTipoMsg: async function(mydata, lang, user, sonosognatore) {
if (!!mydata.msgextra) { if (!!mydata.msgextra) {
return {body: mydata.msgextra, title: ''}; return {body: mydata.msgextra, title: ''};
@@ -862,26 +863,11 @@ module.exports = {
title = ris.title; title = ris.title;
} }
if (!!user) { const cl = getclTelegByidapp(user.idapp);
msg = msg.replace('{username}', user.username); if (cl) {
msg = msg.replace('{name}', user.name ? user.name : user.username); msg = cl.convertSpecialTags(rec.user, msg);
msg = msg.replace('{surname}', user.surname ? user.surname : '');
if (!!user.profile.link_payment)
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
if (!!user.profile.revolut)
msg = msg.replace('{revolut}', user.profile.revolut);
if (!!user.profile.payeer_id)
msg = msg.replace('{payeer_id}', user.profile.payeer_id);
if (!!user.profile.advcash_id)
msg = msg.replace('{advcash_id}', user.profile.advcash_id);
if (!!user.profile.email_paypal)
msg = msg.replace('{email_paypal}', user.profile.email_paypal);
if (!!user.profile.note_payment)
msg = msg.replace('{note_payment}', user.profile.note_payment);
} }
// const cl = getclTelegByidapp(user.idapp);
msg = msg.replace('{link_chathelp}', tools.HELP_CHAT);
if (!!mydata.flotta) { if (!!mydata.flotta) {
// SOSTITUISCI LE PAROLE CHIAVI // SOSTITUISCI LE PAROLE CHIAVI
@@ -1203,6 +1189,19 @@ module.exports = {
}, },
setVerifiedReg: async function (idapp, lang, usernameorig, usernameDest) {
try {
await User.setVerifiedByAportador(idapp, usernameDest, true);
await User.setFriendsCmd(idapp, usernameorig, usernameDest,
shared_consts.FRIENDSCMD.SETFRIEND);
const msgDest = printf(getstr(lang, 'MSG_APORTADOR_CONFIRMED'), `${usernameDest}`);
await local_sendMsgTelegram(idapp, usernameorig, msgDest);
}catch (e) {
console.log('e', e);
}
},
askConfirmationUserRegistration: async function(idapp, myfunc, myuser, userDest = '', langdest = '') { askConfirmationUserRegistration: async function(idapp, myfunc, myuser, userDest = '', langdest = '') {
const cl = getclTelegByidapp(idapp); const cl = getclTelegByidapp(idapp);
@@ -1236,8 +1235,13 @@ module.exports = {
// INvia Msg // INvia Msg
const teleg_id = await User.TelegIdByUsername(idapp, userDest); const teleg_id = await User.TelegIdByUsername(idapp, userDest);
const notask_verif = await User.notAsk_VerifByUsername(idapp, userDest);
await this.sendMsgTelegramByIdTelegram(myuser.idapp, teleg_id, domanda, await this.sendMsgTelegramByIdTelegram(myuser.idapp, teleg_id, domanda,
undefined, undefined, true, keyb); undefined, undefined, true, keyb);bot
if (notask_verif) {
this.setVerifiedReg(myuser.idapp, myuser.lang, userDest, myuser.username);
}
} catch (e) { } catch (e) {
console.error('Error askConfirmationUserRegistration', e); console.error('Error askConfirmationUserRegistration', e);
@@ -1438,6 +1442,37 @@ class Telegram {
'\n\nI miei colleghi umani ti aiuteranno a risolvere !'; '\n\nI miei colleghi umani ti aiuteranno a risolvere !';
} }
convertSpecialTags(user, msg) {
try {
if (!!user) {
msg = msg.replace('{username}', user.username);
msg = msg.replace('{name}', user.name ? user.name : user.username);
msg = msg.replace('{surname}', user.surname ? user.surname : '');
if (!!user.profile.link_payment)
msg = msg.replace('{link_paypalme}', user.profile.link_payment);
if (!!user.profile.revolut)
msg = msg.replace('{revolut}', user.profile.revolut);
if (!!user.profile.payeer_id)
msg = msg.replace('{payeer_id}', user.profile.payeer_id);
if (!!user.profile.advcash_id)
msg = msg.replace('{advcash_id}', user.profile.advcash_id);
if (!!user.profile.email_paypal)
msg = msg.replace('{email_paypal}', user.profile.email_paypal);
if (!!user.profile.note_payment)
msg = msg.replace('{note_payment}', user.profile.note_payment);
}
// const cl = getclTelegByidapp(user.idapp);
msg = msg.replace('{link_chathelp}', tools.HELP_CHAT);
}catch (e) {
console.log(e);
}
return msg;
}
async IsTesto(msg) { async IsTesto(msg) {
let risp = ''; let risp = '';
@@ -1526,7 +1561,7 @@ class Telegram {
if (risp === '') { if (risp === '') {
if (menusite) { if (menusite) {
risp = this.getValueMenu(this.idapp, testo, lang); risp = this.getValueMenu(this.idapp, rec, msg, testo, lang);
noanswer = true; noanswer = true;
} else if (MsgBot.CIAO.includes(testo.replace('!', ''))) { } else if (MsgBot.CIAO.includes(testo.replace('!', ''))) {
risp = 'Ciao '; risp = 'Ciao ';
@@ -1663,6 +1698,8 @@ class Telegram {
} }
} }
risp = this.convertSpecialTags(rec.user, risp);
let keyboard = null; let keyboard = null;
if (contastiera) { if (contastiera) {
@@ -1711,7 +1748,7 @@ class Telegram {
return risp !== ''; return risp !== '';
} }
async isMenuNotVerified(rec, msg) { async isMenuNotVerified(rec, msg, notlast) {
if (this.isSelMenu(msg, msg.text, 'ASSISTENZA')) { if (this.isSelMenu(msg, msg.text, 'ASSISTENZA')) {
await this.menuAssistenza(msg); await this.menuAssistenza(msg);
} else if (msg.text === Menu.LANG_IT) { } else if (msg.text === Menu.LANG_IT) {
@@ -1733,7 +1770,7 @@ class Telegram {
} else if (this.isSelMenu(msg, msg.text, 'ZOOM') || } else if (this.isSelMenu(msg, msg.text, 'ZOOM') ||
MsgBot.PROSSIMO_ZOOM.find((rec) => msg.text.indexOf(rec) > -1)) { MsgBot.PROSSIMO_ZOOM.find((rec) => msg.text.indexOf(rec) > -1)) {
await this.menuZoom(msg); await this.menuZoom(msg);
} else if (await this.IsTesto(msg)) { } else if (!notlast && await this.IsTesto(msg)) {
// OK // OK
} else { } else {
await this.msgScegliMenu(msg); await this.msgScegliMenu(msg);
@@ -1761,14 +1798,14 @@ class Telegram {
return trovato; return trovato;
} }
async isMenu(rec, msg) { async isMenu(rec, msg, testo, notlast) {
if (!msg) if (!msg)
return; return;
if (msg.text === undefined) if (testo === undefined)
return; return;
const arrtext = msg.text.split(' '); const arrtext = testo.split(' ');
let cmd2 = ''; let cmd2 = '';
let cmd1 = arrtext[0]; let cmd1 = arrtext[0];
if (arrtext.length > 1) if (arrtext.length > 1)
@@ -1776,56 +1813,56 @@ class Telegram {
let oldusername = rec.msgall_username_specifico; let oldusername = rec.msgall_username_specifico;
if ((this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) || if ((this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) ||
(this.isSelMenu(msg, msg.text, 'INDIETRO'))) { (this.isSelMenu(msg, testo, 'INDIETRO'))) {
rec.msgall_username_specifico = ''; rec.msgall_username_specifico = '';
} else { } else {
if (rec.msgall_username_specifico !== '') { if (rec.msgall_username_specifico !== '') {
await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico, await this.SendMsgToUser(msg, rec, rec.msgall_username_specifico,
msg.text); testo);
return true; return true;
} }
} }
if (this.isSelMenu(msg, msg.text, 'LAVAGNA') || if (this.isSelMenu(msg, testo, 'LAVAGNA') ||
MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) { MsgBot.LAVAGNA.find((rec) => testo.indexOf(rec) > -1)) {
await this.menuLavagna(msg); await this.menuLavagna(msg);
} else if (this.isSelMenu(msg, msg.text, 'ACCEDI')) { } else if (this.isSelMenu(msg, testo, 'ACCEDI')) {
await this.menuAccedi(msg); await this.menuAccedi(msg);
} else if (this.isSelMenu(msg, msg.text, 'LINK_CONDIVIDERE')) { } else if (this.isSelMenu(msg, testo, 'LINK_CONDIVIDERE')) {
await this.menuLinkCondividere(msg); await this.menuLinkCondividere(msg);
} else if (msg.text === Menu.EXIT_TELEGRAM) { } else if (testo === Menu.EXIT_TELEGRAM) {
await this.menuExitToTelegram(msg); await this.menuExitToTelegram(msg);
} else if (msg.text === Menu.ADMIN) { } else if (testo === Menu.ADMIN) {
await this.menuAdmin(msg); await this.menuAdmin(msg);
} else if (msg.text === Menu.LANG) { } else if (testo === Menu.LANG) {
await this.menuLang(msg); await this.menuLang(msg);
} else if (msg.text === Menu.MSGATUTTI) { } else if (testo === Menu.MSGATUTTI) {
await this.menumsgAll(msg); await this.menumsgAll(msg);
} else if (msg.text === Menu.MSGSTAFF) { } else if (testo === Menu.MSGSTAFF) {
await this.menumsgStaff(msg); await this.menumsgStaff(msg);
} else if (msg.text === Menu.MSGPAOLO) { } else if (testo === Menu.MSGPAOLO) {
await this.menumsgPaolo(msg); await this.menumsgPaolo(msg);
} else if (msg.text === Menu.MSG_NO_7_REQ) { // } else if (testo === 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) { // } else if (testo === 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) { // } else if (testo === Menu.NESSUN_IMBARCO_7REQ) {
await this.menumsgGenerico(msg, Destin.NESSUN_IMBARCO_7REQ); // await this.menumsgGenerico(msg, Destin.NESSUN_IMBARCO_7REQ);
} else if (cmd1 === Menu.MSG_TO_NAVE) { // } 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) { // } else if (testo === 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) { } else if (cmd1.toLowerCase() === Menu.MSG_TO_USER) {
await this.menumsg_A_Utente(msg); await this.menumsg_A_Utente(msg);
} else if (this.isSelMenu(msg, msg.text, 'INDIETRO') || } else if (this.isSelMenu(msg, testo, 'INDIETRO') ||
(msg.text === Menu.it.INDIETRO)) { (testo === Menu.it.INDIETRO)) {
await this.msgScegliMenu(msg); await this.msgScegliMenu(msg);
} else if (this.isSelMenu(msg, msg.text, 'ESCI_DA_CHAT')) { } else if (this.isSelMenu(msg, testo, 'ESCI_DA_CHAT')) {
await this.sendMsg(msg.chat.id, 'Uscito dalla Chat con ' + oldusername); await this.sendMsg(msg.chat.id, 'Uscito dalla Chat con ' + oldusername);
rec.msgall_username_specifico = ''; rec.msgall_username_specifico = '';
} else { } else {
await this.isMenuNotVerified(rec, msg); await this.isMenuNotVerified(rec, msg, notlast);
} }
} }
@@ -2235,18 +2272,25 @@ class Telegram {
} }
} }
permitSendMsg(user) {
return User.isAdmin(user.perm)
}
async menumsgGenerico(msg, dest, username, extraparam) { async menumsgGenerico(msg, dest, username, extraparam) {
const rec = this.getRecInMem(msg); const rec = this.getRecInMem(msg);
if (rec.user) { if (rec.user) {
rec.msgall_status = StatusMSGALL.ASK;
rec.msgall_achi = dest; if (this.permitSendMsg(rec.user)) {
rec.extraparam = extraparam; rec.msgall_status = StatusMSGALL.ASK;
if (!!username) { rec.msgall_achi = dest;
rec.msgall_username_specifico = username; rec.extraparam = extraparam;
if (!!username) {
rec.msgall_username_specifico = username;
}
const mystr = 'Scrivi qui un Messaggio da inviare a' + ' [' +
this.getDestinStr(msg, dest, rec) + ']:';
await this.sendMsg(msg.chat.id, mystr, MenuSend);
} }
const mystr = 'Scrivi qui un Messaggio da inviare a' + ' [' +
this.getDestinStr(msg, dest, rec) + ']:';
await this.sendMsg(msg.chat.id, mystr, MenuSend);
} }
} }
@@ -2843,10 +2887,10 @@ class Telegram {
if (normale) { if (normale) {
// Check Menu // Check Menu
await this.isMenu(rec, msg); await this.isMenu(rec, msg, msg.text, false);
} }
} else { } else {
await this.isMenuNotVerified(rec, msg); await this.isMenuNotVerified(rec, msg, false);
} }
} }
@@ -2984,11 +3028,9 @@ class Telegram {
// Check if you are Admin // Check if you are Admin
const user = await User.UserByIdTelegram(idapp, id); const user = await User.UserByIdTelegram(idapp, id);
let isAdmin = user ? user.profile.manage_telegram && user.username === let isAdmin = user ? user.profile.manage_telegram && user.username === 'paoloar77' : false;
'paoloar77' : false;
const isManager = user ? user.profile.manage_telegram : false; const isManager = user ? user.profile.manage_telegram : false;
const isVerified = user ? user.profile.teleg_id > 0 && const isVerified = user ? user.profile.teleg_id > 0 && user.verified_by_aportador : false;
user.verified_email && user.verified_by_aportador : false;
this.menuDb = await MyBot.findAllIdApp(idapp); this.menuDb = await MyBot.findAllIdApp(idapp);
@@ -2999,29 +3041,34 @@ class Telegram {
let lang = ''; let lang = '';
for (const rec of this.menuDb) { for (const rec of this.menuDb) {
if (rec.active && rec.main && rec.page === this.pagenow rec.active_mem = false;
if (rec.active && rec.page === this.pagenow
&& ((isAdmin && tools.isBitActive(rec.visibility, && ((isAdmin && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_ADMIN)) shared_consts.VISIB_ONLY_ADMIN))
|| (isManager && tools.isBitActive(rec.visibility, || (isManager && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_MANAGER)) shared_consts.VISIB_ONLY_MANAGER))
|| (isVerified && tools.isBitActive(rec.visibility, || (isVerified && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLYIF_LOGGED)) shared_consts.VISIB_ONLYIF_VERIFIED))
|| (rec.visibility === 0)) || (rec.visibility === 0))
) { )
lang = rec.lang; {
if (!arrlang[rec.lang]) rec.active_mem = true;
arrlang[rec.lang] = {menu: []}; if (rec.main) {
lang = rec.lang;
if (!arrlang[rec.lang])
arrlang[rec.lang] = {menu: []};
if (riga !== rec.riga) { if (riga !== rec.riga) {
if (arrtemp.length > 0) if (arrtemp.length > 0)
arrlang[rec.lang].menu.push(arrtemp); arrlang[rec.lang].menu.push(arrtemp);
riga = rec.riga; riga = rec.riga;
arrtemp = []; arrtemp = [];
}
arrtemp.push(rec.label);
} }
arrtemp.push(rec.label);
} }
} }
@@ -3051,9 +3098,11 @@ class Telegram {
} }
for (const rec of this.menuDb) { for (const rec of this.menuDb) {
if (rec.idapp === idapp && rec.lang === lang && if (rec.active_mem) {
rec.label.toLowerCase() === testo) { if (rec.idapp === idapp && rec.lang === lang &&
return true; rec.label.toLowerCase() === testo) {
return true;
}
} }
} }
} catch (e) { } catch (e) {
@@ -3062,22 +3111,31 @@ class Telegram {
return false; return false;
} }
getValueMenu(idapp, testo, lang) { getValueMenu(idapp, rec, msg, testo, lang) {
try { try {
for (const rec of this.menuDb) { for (const recdb of this.menuDb) {
if (rec.idapp === idapp && rec.lang === lang && if (recdb.active_mem) {
rec.label.toLowerCase() === testo) { if (recdb.idapp === idapp && recdb.lang === lang &&
if (rec.type === shared_consts.BOTTYPE_TEXT) { recdb.label.toLowerCase() === testo) {
return rec.value; if (recdb.type === shared_consts.BOTTYPE_TEXT) {
} return recdb.value;
if (rec.type === shared_consts.BOTTYPE_PAGE) { } else if (recdb.type === shared_consts.BOTTYPE_LINK) {
if (tools.isNumber(rec.value)) { //++TODO: Link diretto !?
this.pagenow = parseInt(rec.value); return recdb.value;
this.pageChange = true; } else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
this.pagenow = parseInt(recdb.value);
this.pageChange = true;
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true);
return '';
}
} }
return '';
}
}
} }
} }
return ''; return '';

View File

@@ -2425,6 +2425,7 @@ module.exports = {
code = str.charCodeAt(i); code = str.charCodeAt(i);
if (!(code > 47 && code < 58) && // numeric (0-9) if (!(code > 47 && code < 58) && // numeric (0-9)
!(code > 63 && code < 91) && // upper alpha (A-Z) // e @ !(code > 63 && code < 91) && // upper alpha (A-Z) // e @
(code !== 46) && // . (punto)
(code !== 95) && // _ (code !== 95) && // _
(code !== 45) && // - (code !== 45) && // -
!(code > 96 && code < 123)) { // lower alpha (a-z) !(code > 96 && code < 123)) { // lower alpha (a-z)

View File

@@ -153,6 +153,7 @@ module.exports = {
BOTTYPE_PAGE: 1, BOTTYPE_PAGE: 1,
BOTTYPE_LINK: 2, BOTTYPE_LINK: 2,
BOTTYPE_TEXT: 3, BOTTYPE_TEXT: 3,
BOTTYPE_MENU: 4,
CashType: { CashType: {
None: 0, None: 0,