diff --git a/.directory b/.directory index d717a63..adcb477 100644 --- a/.directory +++ b/.directory @@ -1,6 +1,6 @@ [Dolphin] -Timestamp=2018,10,26,14,54,10 +SortOrder=1 +SortRole=modificationtime +Timestamp=2020,2,18,17,19,21 Version=4 - -[Settings] -HiddenFilesShown=true +ViewMode=1 diff --git a/emails/registration_ayni/fr/html.pug b/emails/registration_ayni/fr/html.pug new file mode 100644 index 0000000..f9d1dc2 --- /dev/null +++ b/emails/registration_ayni/fr/html.pug @@ -0,0 +1,43 @@ +p Bienvenue #{name} sur le portail de #{nomeapp} ! +p Vos identifiants de connexion à retenir sont : +span Username:  + strong #{username}
+span avez-vous oublié votre mot de passe ? :  + strong Essayez ici
+span Email:  + strong #{emailto}
+p Cliquez sur le bouton pour confirmer votre inscription : +div.divbtn + button.btn.btn-lg Vérifier l'enregistrement + +p Vous pouvez ensuite accéder à votre espace personnel en entrant votre nom d'utilisateur et votre mot de passe et en cliquant sur   + strong ENTREZ
+ +p Donc, une fois que vous avez vérifié votre inscription, connectez-vous au site et   + strong COMPLÉTER TOUTES LES ÉTAPES   + de la portée du "Guide pas-à-pas" via ce lien:
+ span #{strlinksito} + + +style(type="text/css"). + html, body { + padding: 0; + margin: 0; + } + + .divbtn { + display: flex; + align-items: center; + justify-content: center; + } + + .btn-lg { + padding: 5px; + margin: 5px; + font-size: 26px; + cursor: pointer; + color: white; + background: #027be3 !important; + border-radius: 28px; + + } diff --git a/emails/registration_ayni/fr/subject.pug b/emails/registration_ayni/fr/subject.pug new file mode 100644 index 0000000..c27d42a --- /dev/null +++ b/emails/registration_ayni/fr/subject.pug @@ -0,0 +1 @@ +=`Confirmer l'inscription à ${nomeapp}` diff --git a/emails/registration_ayni/it/html.pug b/emails/registration_ayni/it/html.pug index 920f216..07eb332 100644 --- a/emails/registration_ayni/it/html.pug +++ b/emails/registration_ayni/it/html.pug @@ -10,8 +10,13 @@ p Per confermare la registrazione clicca sul bottone: div.divbtn button.btn.btn-lg Verifica Registrazione -p Potrai cosi' accedere alla tua area personale cliccando su LOGIN e compilando tutti i PASSI richiesti dalla :  - strong "Guida Passo Passo" !
+p Potrai cosi' accedere alla tua area personale inserendo lo username e la password e cliccando su   + strong ACCEDI
+ +p Pertanto una volta Verificata la Registrazione, accedi al sito e   + strong COMPLETA TUTTI I PASSI   + span della "Guida Passo Passo" tramite questo Link:
+ span #{strlinksito} style(type="text/css"). diff --git a/emails/registration_ayni/pt/html.pug b/emails/registration_ayni/pt/html.pug new file mode 100644 index 0000000..8f4fc74 --- /dev/null +++ b/emails/registration_ayni/pt/html.pug @@ -0,0 +1,43 @@ +p Bem-vindo #{nome} ao portal de #{nomeapp}! +p Os seus dados de login a lembrar são: +span Username:  + strong #{username}
+span você esqueceu sua senha? :  + strong Encontre-o aqui>br> +span Email:  + strong #{{emailto}
+p Clique no botão para confirmar o seu registo: +div.divbtn + button.btn.btn-lg Verificação de registro + +p Você pode então acessar sua área pessoal digitando seu nome de usuário e senha e clicando em   + strong ENTRAR
+ +p Então, uma vez verificada a sua inscrição, inicie a sessão no site e   + COMPLETA TODOS OS PASSOS   + do "Guia Passo a Passo" através deste link:
+ span #{strlinksito} + + +style(type="text/css"). + html, body { + padding: 0; + margin: 0; + } + + .divbtn { + display: flex; + align-items: center; + justify-content: center; + } + + .btn-lg { + padding: 5px; + margin: 5px; + font-size: 26px; + cursor: pointer; + color: white; + background: #027be3 !important; + border-radius: 28px; + + } diff --git a/emails/registration_ayni/pt/subject.pug b/emails/registration_ayni/pt/subject.pug new file mode 100644 index 0000000..8d538d6 --- /dev/null +++ b/emails/registration_ayni/pt/subject.pug @@ -0,0 +1 @@ +=`Confirme o registo em ${nomeapp}` diff --git a/emails/registration_ayni/si/html.pug b/emails/registration_ayni/si/html.pug new file mode 100644 index 0000000..a668540 --- /dev/null +++ b/emails/registration_ayni/si/html.pug @@ -0,0 +1,44 @@ +Dobrodošli # {name} na portalu # {nomeapp}! +p Vaši podatki za dostop so: +span Username:  + strong #{username}
+span ste pozabili geslo? :  + strong Poiščite tukaj
+span Email:  + strong #{emailto}
+p Za potrditev registracije kliknite na gumb: +div.divbtn + button.btn.btn-lg Preveri registracijo + +p Tako boste lahko dostopali do svojega osebnega območja, tako da vnesete uporabniško ime in geslo in kliknete   + strong PRIJAVA
+ + +p Potem ko je registracija preverjena, obiščite spletno mesto in   + strong IZPOLNITE VSE KORAKE   + span "Vodnika po korakih" prek te povezave:
+ span #{strlinksito} + + +style(type="text/css"). + html, body { + padding: 0; + margin: 0; + } + + .divbtn { + display: flex; + align-items: center; + justify-content: center; + } + + .btn-lg { + padding: 5px; + margin: 5px; + font-size: 26px; + cursor: pointer; + color: white; + background: #027be3 !important; + border-radius: 28px; + + } diff --git a/emails/registration_ayni/si/subject.pug b/emails/registration_ayni/si/subject.pug new file mode 100644 index 0000000..fba0ddb --- /dev/null +++ b/emails/registration_ayni/si/subject.pug @@ -0,0 +1 @@ +=`Potrdi registracijo za ${nomeapp}` diff --git a/emails/resetpwd/es/html.pug b/emails/resetpwd/es/html.pug new file mode 100644 index 0000000..4cc5f2a --- /dev/null +++ b/emails/resetpwd/es/html.pug @@ -0,0 +1,10 @@ +p Hola #{nombre}, +p #{nomeapp} recientemente recibió una solicitud de una contraseña olvidada. + +p Para cambiar la contraseña a #{nomeapp} +p Click HERE +p Si no pediste este cambio, no tienes que hacer nada. +p Este enlace expirará en 4 horas. + +Saludos cordiales +p Soporte #{nomeapp} diff --git a/emails/resetpwd/es/subject.pug b/emails/resetpwd/es/subject.pug new file mode 100644 index 0000000..90a18e0 --- /dev/null +++ b/emails/resetpwd/es/subject.pug @@ -0,0 +1 @@ +=`Olvidó la contraseña requerida` diff --git a/src/server/models/billettera.js b/src/server/models/billettera.js new file mode 100644 index 0000000..e8b5d09 --- /dev/null +++ b/src/server/models/billettera.js @@ -0,0 +1,412 @@ +const mongoose = require('mongoose'); +const _ = require('lodash'); + +const tools = require('../tools/general'); + +const { ListaIngresso } = require('./listaingresso'); +const { Settings } = require('./settings'); +const { User } = require('./user'); + +const { ObjectID } = require('mongodb'); + + +const telegrambot = require('../telegram/telegrambot'); + +const shared_consts = require('../tools/shared_nodejs'); + +mongoose.Promise = global.Promise; + +mongoose.level = "F"; +// Resolving error Unknown modifier: $pushAll +mongoose.plugin(schema => { + schema.options.usePushEach = true +}); + +mongoose.set('debug', process.env.DEBUG); + +const BilletteraSchema = new mongoose.Schema({ + idapp: { + type: String, + required: true, + }, + riga: { + type: Number, + }, + col: { + type: Number, + }, + indprimario: { + type: Number, + }, + parent_indprimario: { + type: Number, + }, + date_start: { + type: Date + }, + made_gift: { + type: Boolean, + default: false, + }, + received_gift: { + type: Boolean, + default: false, + }, + created: { + type: Date, + }, + num_tess: { // numero di tessitura + type: Boolean, + default: 1 + } + +}); + +BilletteraSchema.statics.getTotInLista = async function (idapp) { + const Billettera = this; + + const myfind = { idapp }; + + return await Billettera.count(myfind); +}; + +BilletteraSchema.statics.findByIndOrder = function (idapp, ind_order) { + const User = this; + + try { + return User.findOne({ + 'idapp': idapp, + 'ind_order': ind_order, + }); + } catch (e) { + + } +}; + + +BilletteraSchema.statics.getFieldsForSearch = function () { + return ['username', 'name', 'surname', 'ind_order'] +}; + +BilletteraSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); + return tools.executeQueryTable(this, idapp, params); +}; + +BilletteraSchema.statics.findAllIdApp = function (idapp) { + const Billettera = this; + + const myfind = { idapp }; + + return Billettera.find(myfind, (err, arrrec) => { + return arrrec + }); +}; + +BilletteraSchema.statics.findByRigaCol = function (idapp, riga, col) { + const Billettera = this; + + const myfind = { idapp, riga, col }; + + return Billettera.findOne(myfind, (err, arrrec) => { + return arrrec + }); +}; + +BilletteraSchema.statics.findRecByRigaColParent = async function (idapp, riga, col, numparentUp) { + const Billettera = this; + + const myfind = { idapp, riga, col }; + + let parentup = 0; + let myrec = null; + while (parentup < numparentUp) { + myrec = await Billettera.findOne(myfind); + + if (myrec.parent_indprimario === 0) + break; + } + + return myrec; + +}; + +function getlimiti(mypos) { + + if (mypos.col < 0) { + mypos.col = 0; + } + + if (mypos.riga < 0) { + mypos.riga = 0; + mypos.col = 0; + } + + return mypos; +} + +function getRigaColByPosUp(mypos) { + riga = riga - mypos.numup; + col = Math.ceil(col / (Math.pow(2, mypos.numup))); + if ((col % 2) !== 0) + col++; + +} + +function getRigaColGenerica(idapp, riga, col, numup) { + mypos = { + riga, + col, + numup + }; + + if (idapp === tools.AYNI) { + this.getRigaColByPosUp(mypos); + ris = this.getlimiti(mypos); + riga = ris.riga; + col = ris.col; + } + + return { riga, col }; +} + + +function getRigaColSognatoreByFuoco(idapp, riga, col) { + return this.getRigaColGenerica(idapp, riga, col, 6); +} + +function getRigaColMediatoreByFuoco(idapp, riga, col) { + return this.getRigaColGenerica(idapp, riga, col, 3); +} + + +BilletteraSchema.statics.findMediatoreByFuoco = function (idapp, riga, col) { + const Billettera = this; + + const myrigacol = getRigaColMediatoreByFuoco(idapp, riga, col); + + const myfind = { idapp, riga: myrigacol.riga, col: myrigacol.col }; + + return Billettera.findOne(myfind, (err, arrrec) => { + return arrrec + }); +}; + +function getQueryProj(myfilter) { + const query = [ + { $match: myfilter }, + { + $lookup: { + from: "users", + localField: "ind_order", + foreignField: "ind_order", // field in the user collection + as: "user" + } + }, + { + $replaceRoot: { newRoot: { $mergeObjects: [{ $arrayElemAt: ["$user", 0] }, "$$ROOT"] } } + }, + ]; + + return query; +} + +BilletteraSchema.statics.findSognatoreByFuoco = function (idapp, riga, col) { + const Billettera = this; + + const myrigacol = getRigaColSognatoreByFuoco(idapp, riga, col); + + const myquery = this.getQueryProj({ idapp, riga: myrigacol.riga, col: myrigacol.col }); + + return Billettera.find(myquery, (err, arrrec) => { + return arrrec + }); +}; + + +BilletteraSchema.statics.setRiga = async function (idapp, riga) { + const newrec = new Settings({ key: 'riga' }); + newrec._id = new ObjectID(); + newrec.idapp = idapp; + newrec.type = tools.FieldType.number; + newrec.value_num = riga; + + await newrec.save(); +}; + +BilletteraSchema.statics.getRiga = async function (idapp) { + const ret = await Settings.findOne({ key: 'riga', idapp }); + if (!!ret) { + return ret.value_num; + } else { + return 1; + } +}; + +BilletteraSchema.statics.setCol = async function (idapp, col) { + const newrec = new Settings({ key: 'col' }); + newrec._id = new ObjectID(); + newrec.idapp = idapp; + newrec.type = tools.FieldType.number; + newrec.value_num = col; + + await newrec.save(); +}; + +BilletteraSchema.statics.getCol = async function (idapp) { + const ret = await Settings.findOne({ key: 'col', idapp }); + if (!!ret) { + return ret.value_num; + } else { + return 1; + } +}; + +function getmaxcol(riga) { + + let maxcol = 1; + if (riga === 1) { + maxcol = 1; + } else if (riga === 2) { + maxcol = 2; + } else { + maxcol = Math.pow(riga - 1, 2); + } + + return maxcol; +} + +function getPrimoFuocoByIndCol(col) { + return Math.ceil(col / 8) + (col % 8); +} + +function getusertextbyrec(myrec, symbol) { + return symbol + ' ' + recfuoco.ind_order + ' (' + recfuoco.name + ' ' + recfuoco.surname + ')'; +} + +BilletteraSchema.statics.getPlaccaByFuoco = async function (idapp, riga, col) { + const Billettera = this; + + try { + let recsognatore = await Billettera.findSognatoreByFuoco(idapp, riga, col); + let recmediatore = await Billettera.findMediatoreByFuoco(idapp, riga, col); + + let primofuoco = this.getPrimoFuocoByIndCol(col); + + mystr = '🌈 Dreamer ' + this.getusertextbyrec(recsognatore, '🔥') + tools.ACAPO; + mystr = '🌈 Mediator ' + this.getusertextbyrec(recmediatore, '🔥') + tools.ACAPO; + + mystr = '🔥🌏💦💨🔥🌏💦💨' + tools.ACAPO; + + for (let indcol = primofuoco; indcol < primofuoco + 8; indcol++) { + let recfuoco = await Billettera.findByRigaCol(idapp, riga, indcol); + mystr += this.getusertextbyrec(recfuoco, '🔥') + tools.ACAPO; + } + } catch (e) { + console.error(e); + } + +} + +function Fuochi8Completati(idapp, riga, col) { + // Inviare un msg al Mediatore che può aprire la Chat con gli 8 fuochi + + // Inviare un msg a questi 8 Fuochi, che la loro placca è Pronta ! + + txt = ''; + // Inviare la placca a Managers + telegrambot.sendMsgTelegramToTheManagers(idapp, txt); +} + +BilletteraSchema.statics.generaBillettera = async function (idapp) { + const Billettera = this; + + let riga = await Billettera.getRiga(idapp); + let col = await Billettera.getCol(idapp); + + let primavolta = (riga === 1) && (col === 1); + primavolta = false; + + const recfindFondo = await Billettera.findByRigaCol(idapp, 0, 0); + if (!recfindFondo) { + billettera = new Billettera({ idapp, indprimario: 0, riga: 0, col: 0 }); + billettera.created = new Date(); + await billettera.save(); + + const UserFondo = await User.findByIndOrder(idapp, 0); + if (!UserFondo) { + telegrambot.sendMsgTelegramToTheAdmin(idapp, 'Devi creare l\'utente FONDO , con ind_order = 0 ! '); + } + } + + + let maxcol = getmaxcol(riga); + + // Identifica il prossimo d'aggiungere + + arrlistaingresso = await ListaIngresso.find({ 'idapp': idapp, added: false }).sort({ indprimario: 1 }); + + let conta = 0; + let colparent = Math.ceil(col / 2); + let rigaparent = riga - 1; + + for (const reclista of arrlistaingresso) { + + billettera = new Billettera({ idapp, indprimario: reclista.indprimario, riga, col }); + billettera.created = new Date(); + + const recfind = await Billettera.findByRigaCol(idapp, rigaparent, colparent); + if (!!recfind) { + billettera.parent_indprimario = recfind.indprimario; + } else { + billettera.parent_indprimario = 0; + } + + await billettera.save() + .then(async (result) => { + let fields_to_update = { added: true }; + const ris = await ListaIngresso.findOneAndUpdate({ _id: reclista._id.toString() }, { $set: fields_to_update }, { new: false }); + + await Billettera.setRiga(idapp, riga); + await Billettera.getCol(idapp, col); + conta++; + + // Check if Billetera has Completed + if (idapp === tools.AYNI) { + if ((col % 8) === 0) { + // Completed 8 people + let text = 'Completata Billettera [riga=' + riga + ',col=' + col + ']'; + tools.writeBilletteraLog(text); + if (!primavolta) { + telegrambot.sendMsgTelegramToTheManagers(idapp, text); + this.Fuochi8Completati(idapp, riga, col); + } + } + } + + // Next + if (col === maxcol) { + riga++; + rigaparent = riga - 1; + col = 1; + maxcol = getmaxcol(riga); + } else { + col++; + } + + if ((col % 2) !== 0) + colparent++; + + }); + + } + +}; + + +const Billettera = mongoose.model('Billettera', BilletteraSchema); + + +module.exports = { Billettera }; + + diff --git a/src/server/models/calzoom.js b/src/server/models/calzoom.js index c23231b..1579b80 100644 --- a/src/server/models/calzoom.js +++ b/src/server/models/calzoom.js @@ -53,7 +53,7 @@ CalZoomSchema.statics.findAllIdApp = async function (idapp) { const myfind = { idapp, date_start: { $gt: tools.IncDateNow(-1000 * 60 * 60 * 3) } }; - return await CalZoom.find(myfind).sort({ date_start: 1 }); + return await CalZoom.find(myfind).sort({ date_start: 1 }).limit(4); }; CalZoomSchema.statics.getNextZoom = async function (idapp) { diff --git a/src/server/models/extralist.js b/src/server/models/extralist.js index c302a43..9b60398 100644 --- a/src/server/models/extralist.js +++ b/src/server/models/extralist.js @@ -145,10 +145,10 @@ ExtraListSchema.statics.findByCellAndNameSurname = function (idapp, cell_complet }; ExtraListSchema.statics.findByIndOrder = function (idapp, ind_order) { - const User = this; + const ExtraList = this; try { - return User.findOne({ + return ExtraList.findOne({ 'idapp': idapp, 'ind_order': ind_order, }); @@ -321,13 +321,6 @@ ExtraListSchema.statics.ImportData = async function (locale, idapp, strdata) { }; -if (tools.INITDB_FIRSTIME) { - console.log(' createIndex User Index...'); - // ExtraListSchema.index({ username: 'text', name: 'text', surname: 'text', email: 'text' }); - // ExtraListSchema.index({ name: 'name' }); - // ExtraListSchema.index({ name: 1 }); - // ExtraListSchema.index({ surname: 1 }); -} const ExtraList = mongoose.model('ExtraList', ExtraListSchema); diff --git a/src/server/models/listaingresso.js b/src/server/models/listaingresso.js new file mode 100644 index 0000000..f4d583f --- /dev/null +++ b/src/server/models/listaingresso.js @@ -0,0 +1,137 @@ +var bcrypt = require('bcryptjs'); +const mongoose = require('mongoose'); +const validator = require('validator'); +const jwt = require('jsonwebtoken'); +const _ = require('lodash'); + +const tools = require('../tools/general'); + +const shared_consts = require('../tools/shared_nodejs'); +const queryclass = require('../classes/queryclass'); + +mongoose.Promise = global.Promise; + +mongoose.level = "F"; +// Resolving error Unknown modifier: $pushAll +mongoose.plugin(schema => { + schema.options.usePushEach = true +}); + +mongoose.set('debug', process.env.DEBUG); + +const ListaIngressoSchema = new mongoose.Schema({ + idapp: { + type: String, + required: true, + }, + indprimario: { + type: Number, + }, + ind_order: { + type: Number, + }, + username: { + type: String, + }, + name: { + type: String, + }, + surname: { + type: String, + }, + added: { // Added into Programmation (Billettera) + type: Boolean, + default: false, + } + +}); + +ListaIngressoSchema.pre('save', async function (next) { + if (this.isNew) { + const myrec = await ListaIngresso.findOne().limit(1).sort({indprimario:-1}); + if (!!myrec) { + if (myrec._doc.indprimario === 0) + this.indprimario = 1; + else + this.indprimario = myrec._doc.indprimario + 10; + + } else { + this.indprimario = 10; + } + } + + next(); +}); + + +// ListaIngressoSchema.methods.toJSON = function () { +// const ListaIngresso = this; +// const userObject = ListaIngresso.toObject(); +// +// return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]); +// }; +// +ListaIngressoSchema.statics.findByUsername = function (idapp, username) { + const ListaIngresso = this; + + return ListaIngresso.findOne({ + 'idapp': idapp, + 'username': username, + }); +}; + +ListaIngressoSchema.statics.getTotInLista = async function (idapp) { + const ListaIngresso = this; + + const myfind = { idapp }; + + return await ListaIngresso.count(myfind); +}; + +ListaIngressoSchema.statics.getOrderedList = function (idapp) { + const ListaIngresso = this; + + return ListaIngresso.findOne({ idapp }).sort({ indprimario: -1 }) +}; + + +ListaIngressoSchema.statics.findByIndOrder = function (idapp, ind_order) { + const ListaIngresso = this; + + try { + return ListaIngresso.findOne({ + 'idapp': idapp, + 'ind_order': ind_order, + }); + } catch (e) { + + } +}; + + +ListaIngressoSchema.statics.getFieldsForSearch = function () { + return ['username', 'name', 'surname', 'ind_order'] +}; + +ListaIngressoSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); + return tools.executeQueryTable(this, idapp, params); +}; + +ListaIngressoSchema.statics.findAllIdApp = function (idapp) { + const ListaIngresso = this; + + const myfind = { idapp }; + + return ListaIngresso.find(myfind, (err, arrrec) => { + return arrrec + }); +}; + + +const ListaIngresso = mongoose.model('ListaIngresso', ListaIngressoSchema); + + +module.exports = { ListaIngresso }; + + diff --git a/src/server/models/user.js b/src/server/models/user.js index 377e0b2..5987b30 100644 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -7,8 +7,12 @@ const _ = require('lodash'); const tools = require('../tools/general'); const { Settings } = require('../models/settings'); +const { ListaIngresso } = require('../models/listaingresso'); +const { Billettera } = require('./billettera'); const { ExtraList } = require('../models/extralist'); +const { ObjectID } = require('mongodb'); + const shared_consts = require('../tools/shared_nodejs'); const queryclass = require('../classes/queryclass'); @@ -160,6 +164,9 @@ const UserSchema = new mongoose.Schema({ teleg_id: { type: Number }, + teleg_id_old: { + type: Number + }, teleg_checkcode: { type: Number }, @@ -178,6 +185,9 @@ const UserSchema = new mongoose.Schema({ saw_zoom_presentation: { type: Boolean }, + special_req: { + type: Boolean + }, sex: { type: Number, }, @@ -316,14 +326,24 @@ UserSchema.statics.findByCredentials = function (idapp, username, password) { }; -UserSchema.statics.findByUsername = function (idapp, username) { +UserSchema.statics.findByUsername = async function (idapp, username, alsoemail) { const User = this; - // /^bar$/i + const regexusername = new RegExp(["^", username, "$"].join(""), "i"); - return User.findOne({ + return await User.findOne({ 'idapp': idapp, - 'username': username, + 'username': regexusername, + }).then(async (ris) => { + if ((!ris) && (alsoemail)) { + regexemail = new RegExp(["^", username.toLowerCase(), "$"].join(""), "i"); + + return await User.findOne({ + 'idapp': idapp, + 'email': regexemail, + }); + } + return ris; }); }; @@ -360,6 +380,7 @@ UserSchema.statics.getUserShortDataByUsername = async function (idapp, username) }); if (myrec) { + myrec.qualified = await User.isUserQualified7(idapp, myrec.username); myrec.numinvitati = await User.getnumInvitati(idapp, myrec.username); myrec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, myrec.username); } @@ -395,6 +416,7 @@ UserSchema.statics.getDownlineByUsername = async function (idapp, username) { if (!!arrrec) { for (const rec of arrrec) { + rec._doc.qualified = await User.isUserQualified7(idapp, rec.username); rec._doc.numinvitati = await User.getnumInvitati(idapp, rec.username); rec._doc.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username); } @@ -411,9 +433,55 @@ UserSchema.statics.getnumInvitatiAttivi = function (idapp, username) { return User.count({ idapp, aportador_solidario: username, + verified_email: true, 'profile.teleg_id': { $gt: 1 }, + 'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED, 'profile.saw_zoom_presentation': true, - 'profile.saw_and_accepted': true, + 'profile.my_dream': { $exists: true }, + $and: [ + { "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } }, + { "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } } + ], + $where: "this.profile.paymenttypes.length >= 1", + 'profile.email_paypal': { $exists: true }, + }); +}; + +UserSchema.statics.isUserQualified7 = async function (idapp, username) { + const User = this; + + const myrec = await User.findOne({ + 'idapp': idapp, + 'username': username, + $or: [ + { + special_req: true + }, + { + verified_email: true, + 'profile.teleg_id': { $gt: 1 }, + 'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED, + 'profile.saw_zoom_presentation': true, + 'profile.my_dream': { $exists: true }, + 'profile.email_paypal': { $exists: true }, + $and: [ + { "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } }, + { "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } } + ], + $where: "this.profile.paymenttypes.length >= 1", + }] + }); + + return !!myrec; +}; + +UserSchema.statics.getnumPaymentOk = function (idapp) { + const User = this; + + return User.count({ + idapp, + $where: "this.profile.paymenttypes.length >= 1", + 'profile.email_paypal': { $exists: true }, }); }; @@ -488,6 +556,21 @@ UserSchema.statics.getLastUser = function (idapp) { return User.findOne({ idapp }).sort({ ind_order: -1 }) }; +UserSchema.statics.findByIndOrder = function (idapp, ind_order) { + const User = this; + + try { + return User.findOne({ + 'idapp': idapp, + 'ind_order': ind_order, + }); + } catch (e) { + + } +}; + + + UserSchema.pre('save', function (next) { const user = this; @@ -561,7 +644,7 @@ UserSchema.statics.TelegIdByUsername = async function (idapp, username) { }); }; -UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg_checkcode) { +UserSchema.statics.SetTelegramCheckCode = async function (idapp, id, teleg_checkcode) { const User = this; const fields_to_update = { @@ -569,25 +652,42 @@ UserSchema.statics.SetTelegramCheckCode = async function (idapp, username, teleg }; return await User.findOneAndUpdate({ - idapp, - username + _id: id }, { $set: fields_to_update }, { new: false }).then((record) => { return !!record; }); }; -UserSchema.statics.SetTelegramIdSuccess = async function (idapp, username, teleg_id) { +UserSchema.statics.SetTelegramIdSuccess = async function (idapp, id, teleg_id) { const User = this; const fields_to_update = { 'profile.teleg_id': teleg_id, + 'profile.teleg_id_old': 0, 'profile.teleg_checkcode': 0 }; return await User.findOneAndUpdate({ idapp, - username + _id: id + }, { $set: fields_to_update }, { new: false }).then((record) => { + return record; + }); + +}; + +UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) { + const User = this; + + const fields_to_update = { + 'profile.teleg_id_old': teleg_id, + 'profile.teleg_id': 0, + }; + + const ris = await User.findOneAndUpdate({ + idapp, + 'profile.teleg_id': teleg_id }, { $set: fields_to_update }, { new: false }).then((record) => { return record; }); @@ -609,7 +709,7 @@ UserSchema.statics.getNameSurnameByUsername = async function (idapp, username) { UserSchema.statics.getusersManagers = async function (idapp) { const User = this; - return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1 }) + return await User.find({ idapp, 'profile.manage_telegram': true }, { 'profile.teleg_id': 1, perm: 1 }) .then((arrrec) => { return (!!arrrec) ? arrrec : null; }).catch((e) => { @@ -620,11 +720,11 @@ UserSchema.statics.getusersManagers = async function (idapp) { UserSchema.statics.getUsersTelegALL = async function (idapp) { const User = this; - return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } }, { 'profile.teleg_id': 1, perm: 1 }) + return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } }) .then((arrrec) => { return (!!arrrec) ? arrrec : null; }).catch((e) => { - console.error('getusersManagers', e); + console.error('getUsersTelegALL', e); }); }; @@ -813,6 +913,58 @@ UserSchema.statics.getUsersRegistered = async function (idapp) { return await User.count(myfind); }; +UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) { + const User = this; + + const arrusers = await User.find({ + idapp, + $or: [ + { + special_req: true + }, + { + verified_email: true, + 'profile.teleg_id': { $gt: 0 }, + $where: "this.profile.paymenttypes.length >= 1", + 'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED, + 'profile.saw_zoom_presentation': true, + 'profile.my_dream': { $exists: true }, + $and: [ + { "$expr": { "$gt": [{ "$strLenCP": "$profile.my_dream" }, 10] } }, + { "$expr": { "$gt": [{ "$strLenCP": "$profile.email_paypal" }, 6] } } + ], + }] + + }, { + 'username': 1, + }); + + + if (numinvitati === 0) + return arrusers; // PRENDI TUTTI + + let arrris = []; + + for (const rec of arrusers) { + rec.numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username); + if (rec.numinvitatiattivi >= numinvitati) { + arrris.push(rec); + } + } + + return arrris + +}; + +UserSchema.statics.getNumUsersQualified = async function (idapp, numinvitati) { + + arrrec = await this.getUsersQualified(idapp, numinvitati); + + return arrrec.length + +}; + + UserSchema.statics.getEmailNotVerified = async function (idapp) { const User = this; @@ -964,6 +1116,47 @@ if (tools.INITDB_FIRSTIME) { // UserSchema.index({ surname: 1 }); } +async function addUtentiInLista(idapp, mode) { + let num = 0; + for (const rec of arrusers) { + let ok = false; + let qualified = await User.isUserQualified7(idapp, rec.username); + let numinvitatiattivi = await User.getnumInvitatiAttivi(idapp, rec.username); + + + if (mode === 1) { + // 9 punti qualificati + ok = qualified && (numinvitatiattivi >= 2); + } else if (mode === 2) { + // 7 punti qualificati + ok = qualified; + } else { + ok = true; + // // almeno telegram ID + // ok = user.profile.teleg_id > 0; + // } else { + // ok = true; + } + + if (ok) { + if (!await ListaIngresso.findByUsername(idapp, rec.username)) { + let listaingresso = new ListaIngresso({ + username: rec.username, + ind_order: rec.ind_order, + name: rec.name, + surname: rec.surname, + idapp, + _id: new ObjectID() + }); + + await listaingresso.save(); + num++; + } + } + } + return num; +} + UserSchema.statics.DbOp = async function (idapp, mydata) { const User = this; try { @@ -971,14 +1164,52 @@ UserSchema.statics.DbOp = async function (idapp, mydata) { arrusers = await User.find({ 'idapp': idapp }); let num = 0; for (const rec of arrusers) { - let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell); - await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } }) - num++; + // DISATTIVATO: ORA NON MI SERVE PIU + if (false) { + let mycell = tools.removespaces(rec.profile.intcode_cell + rec.profile.cell); + await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'profile.cell': mycell } }); + num++; + } } return { num }; // return await User.updateMany({ idapp }, { $set: { 'profile.cell': { $concat: ["$profile.intcode_cell", "$profile.cell"] } } }) + } else if (mydata.dbop === 'changeEmailLowerCase') { + arrusers = await User.find({ 'idapp': idapp }); + let num = 0; + for (const rec of arrusers) { + let myemail = rec.email.toLowerCase(); + if (myemail !== rec.email) { + await User.findOneAndUpdate({ _id: rec._id }, { $set: { 'email': myemail } }); + num++; + } + } + + return { num }; + + } else if (mydata.dbop === 'creaLista') { + + await ListaIngresso.remove({ idapp }); + + arrusers = await User.find({ 'idapp': idapp }).sort({ ind_order: 1 }); + let num = 0; + + num += await addUtentiInLista(idapp, 1); + num += await addUtentiInLista(idapp, 2); + // num += await addUtentiInLista(idapp, 3); + // num += await addUtentiInLista(idapp, 4); + + return { num }; + + } else if (mydata.dbop === 'creaBillettera') { + const num = await Billettera.generaBillettera(idapp); + + return { num }; + } else if (mydata.dbop === 'visuPlacca') { + const placca = await Billettera.getPlaccaByFuoco(idapp, riga, col); + + return { placca }; } } catch (e) { console.error(e); @@ -987,6 +1218,7 @@ UserSchema.statics.DbOp = async function (idapp, mydata) { }; + const User = mongoose.model('User', UserSchema); diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index e795791..b8e834f 100644 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -77,7 +77,7 @@ router.post(process.env.LINKVERIF_REG, (req, res) => { user.lasttimeonline = new Date(); user.save().then(() => { //console.log("TROVATOOOOOO!"); - res.send({ code: server_constants.RIS_CODE_EMAIL_VERIFIED, msg: tools.getres__('EMAIL_VERIF', res) }); + res.send({ code: server_constants.RIS_CODE_EMAIL_VERIFIED, msg: tools.getres__('EMAIL', res) + ' ' + tools.getres__('VERIF', res) }); }); } } @@ -130,7 +130,7 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => { const msg = "Richiesta Nuova Password: idapp= " + idapp + " email = " + email; console.log(msg); - telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg); + // telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg); User.findByLinkTokenforgot(idapp, email, tokenforgot).then((user) => { if (!user) { diff --git a/src/server/router/notevole_router.js b/src/server/router/notevole_router.js index 143e56a..1cb2775 100644 --- a/src/server/router/notevole_router.js +++ b/src/server/router/notevole_router.js @@ -29,6 +29,9 @@ router.post('/load', async (req, res) => { email_non_verif: await User.getEmailNotVerified(idapp), num_teleg_attivo: await User.getUsersTelegramAttivo(idapp), num_teleg_pending: await User.getUsersTelegramPending(idapp), + num_qualificati: await User.getNumUsersQualified(idapp, 2), + num_requisiti: await User.getNumUsersQualified(idapp, 0), + num_modalita_pagamento: await User.getnumPaymentOk(idapp), num_part_zoom: await User.getUsersZoom(idapp), num_part_accepted: await User.getSaw_and_Accepted(idapp), num_users_dream: await User.getUsersDreams(idapp), diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js index dcf645d..411d57e 100644 --- a/src/server/router/users_router.js +++ b/src/server/router/users_router.js @@ -49,6 +49,8 @@ router.post('/', async (req, res) => { const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile', 'aportador_solidario']); const user = new User(body); + body.email = body.email.toLowerCase(); + // tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp); user.linkreg = reg.getlinkregByEmail(body.idapp, body.email, body.username); @@ -104,16 +106,13 @@ router.post('/', async (req, res) => { let recextra = null; - recextra = await ExtraList.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname); - let nomeaportador_corretto = ""; - if (recextra) { - nomeaportador_corretto = recextra.aportador_solidario_name_surname; - if (nomeaportador_corretto === '') - nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname; - } - - - + // recextra = await ExtraList.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name, user.surname); + // let nomeaportador_corretto = ""; + // if (recextra) { + // nomeaportador_corretto = recextra.aportador_solidario_name_surname; + // if (nomeaportador_corretto === '') + // nomeaportador_corretto = recextra.aportador_solidario_originale_name_surname; + // } const lastuser = await User.getLastUser(user.idapp); const lastextra = await ExtraList.getLastUser(user.idapp); @@ -130,6 +129,27 @@ router.post('/', async (req, res) => { if (lastindorder > 0) user.ind_order = lastindorder + 1; + const numero = user.name.slice(-1); + if ((numero === '2') || (numero === '3') || (numero === '4')) { + recorig = await User.findByCellAndNameSurname(user.idapp, user.profile.cell, user.name.slice(0, -1), user.surname); + if (!!recorig) { + user.profile.teleg_id = recorig.profile.teleg_id; + user.profile.saw_zoom_presentation = recorig.profile.saw_zoom_presentation; + user.profile.saw_and_accepted = recorig.profile.saw_and_accepted; + user.profile.email_paypal = recorig.profile.email_paypal; + user.profile.paymenttypes = recorig.profile.paymenttypes; + let msgseconda = '!!! REGISTRATA '; + if (numero === '2') + msgseconda += 'SECONDA'; + else if (numero === '3') + msgseconda += 'TERZA'; + else if (numero === '4') + msgseconda += 'QUARTA'; + + msgseconda += ' UTENZA di ' + recorig.name + ' ' + recorig.surname + ' (' + recorig.username + ') : ' + user.name + ' ' + user.surname + ' (' + user.username + ') '; + telegrambot.sendMsgTelegramToTheManagers(user.idapp, msgseconda); + } + } namesurname_aportador_reg = await User.getNameSurnameByUsername(user.idapp, user.aportador_solidario); @@ -184,7 +204,7 @@ router.post('/', async (req, res) => { return await user.save() .then(async () => { - return await User.findByUsername(user.idapp, user.username) + return await User.findByUsername(user.idapp, user.username, false) .then((usertrovato) => { // tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato); @@ -228,7 +248,7 @@ router.get('/:idapp/:username', (req, res) => { var username = req.params.username; const idapp = req.params.idapp; - User.findByUsername(idapp, username).then((user) => { + User.findByUsername(idapp, username, false).then((user) => { if (!user) { return res.status(404).send(); } @@ -331,6 +351,7 @@ router.post('/login', (req, res) => { code: server_constants.RIS_CODE_OK, subsExistonDb: myris.subsExistonDb }); + // tools.mylog("TROVATOOO!"); // tools.mylog('FINE LOGIN') diff --git a/src/server/sendemail.js b/src/server/sendemail.js index 954c849..a3fa35b 100644 --- a/src/server/sendemail.js +++ b/src/server/sendemail.js @@ -162,6 +162,7 @@ module.exports = { dataemail: await this.getdataemail(idapp), locale: lang, nomeapp: tools.getNomeAppByIdApp(idapp), + strlinksito: tools.getHostByIdApp(idapp), strlinkreg: this.getlinkReg(idapp, idreg), username: user.username, name: user.name, diff --git a/src/server/server.js b/src/server/server.js index 30454c7..b95c20d 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -290,10 +290,23 @@ async function resetProcessingJob() { // console.log(`Server started at port ${port}`); //}); -telegrambot.sendMsgTelegram('7', telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`); -telegrambot.sendMsgTelegramByIdTelegram('7', telegrambot.ADMIN_IDTELEGRAM_SERVER, `Il Server ${process.env.DATABASE} è appena ripartito!`); +async function inizia() { + if (process.env.NODE_ENV === 'production') { + await telegrambot.sendMsgTelegram(tools.AYNI, telegrambot.ADMIN_USER_SERVER, `Ciao ${telegrambot.ADMIN_USER_NAME_SERVER}!`); + await telegrambot.sendMsgTelegramByIdTelegram(tools.AYNI, telegrambot.ADMIN_IDTELEGRAM_SERVER, `Il Server ${process.env.DATABASE} è appena ripartito!`); -telegrambot.sendMsgTelegramByIdTelegram('2', 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.AYNI, telegrambot.ADMIN_IDTELEGRAM_SERVER, testo); + + } + // testo = 'testo modificato'; + // myid = await telegrambot.sendMsgTelegramByIdTelegram('7', telegrambot.ADMIN_IDTELEGRAM_SERVER, testo, myid, telegrambot.ADMIN_IDTELEGRAM_SERVER); + +} + +inizia(); resetProcessingJob(); diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 3eb529e..7bf0fe1 100644 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -1,9 +1,9 @@ const tools = require('../tools/general'); -const appTelegram = ['7']; +const appTelegram = [tools.AYNI]; const appTelegramFinti = ['2']; -const appTelegramDest = ['7']; +const appTelegramDest = [tools.AYNI]; const printf = require('util').format; @@ -18,16 +18,22 @@ const i18n = require("i18n"); const Benvenuto = emoji.get('heartbeat') + emoji.get('heartbeat') + emoji.get('heartbeat') + ' Benvenuto!'; const emo = { + JOY: emoji.get('joy'), + JOY2: emoji.get('rolling_on_the_floor_laughing'), + DANCER: emoji.get('dancer'), STARS: emoji.get('stars'), FIRE: emoji.get('fire'), + SUN: emoji.get('sunrise'), TV: emoji.get('tv'), NEWSPAPER: emoji.get('newspaper'), + KISS: emoji.get('kiss'), PENCIL: emoji.get('pencil2'), DREAM: emoji.get('beach_with_umbrella'), EYES: emoji.get('eyes'), DIZZY: emoji.get('dizzy'), ONE_HUNDRED: emoji.get('100'), SMILE_STAR: emoji.get('star-struck'), + LEFT_FACING_FIST: emoji.get('left-facing_fist'), CHECK_VERDE: emoji.get('white_check_mark'), CHECK_GRIGIA: emoji.get('ballot_box_with_check'), CROSS_ROSSA: emoji.get('x'), @@ -44,6 +50,56 @@ const emo = { GIFT_HEART: emoji.get('gift_heart'), ROBOT_FACE: emoji.get('robot_face'), ADMIN: emoji.get('information_desk_person'), + MALE: emoji.get('man-tipping-hand'), + FEMALE: emoji.get('female-guard'), + INNOCENT: emoji.get('innocent'), + CREDIT_CARD: emoji.get('credit_card'), + PERSON: emoji.get('man-tipping-hand'), +}; + + +MsgBot = { + CIAO: ['ciao', 'ciaoo', 'hola', 'holaa', 'hey', 'salve', 'buongiorno', 'buondi'], + 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'], + 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'], + CHAT_EMPOWER: ['chat empower'], + 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😘'], + PRINCIPE_AZZURRO: ['principe azzurro'], + 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'], + COME_SI_CHIAMA: ['come si chiama'], + PROSSIMO_ZOOM: ['prossimo zoom', 'fare lo zoom', 'gli zoom', 'conferenz'], + LAVAGNA: ['lavagna', 'Lavagna', 'LAVAGNA'], + SEI_LIBERO: ['sei liber', 'sei sposat', 'sei fidanzat', 'sei single'], + AIUTO: ['ayni help', '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'], + UGUALE: ['👍🏻', '✨', '❤🏻', '⭐', '❤', '❤❤', '🤩'], + SI: ['si', 'yes'], + NO: ['no', 'noo'], + DONNA: ['donna', 'femmina'], + FARE_DOMANDA: ['fare una domanda', 'posso farti una domanda'], + DIVENTERO_RICCA: ['diventerò ricc'], + MA_ALLORA: ['ma allora'], + CHI_E_VISTAR: ['chi è vistar'], + CHI_E_PAOLO: ['chi è paolo'], +}; + +MsgRisp = { + 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) { @@ -70,12 +126,14 @@ function getemojibynumber(number) { } } + const Menu = { - LAVAGNA: emoji.get('om_symbol') + ' La tua Lavagna', + ACCEDI: emo.PERSON + ' Accedi', + LAVAGNA: emoji.get('om_symbol') + ' Lavagna (Requisiti)', LINK_CONDIVIDERE: emoji.get('link') + ' Link da condividere', ZOOM: emoji.get('information_source') + ' Zoom (Conferenze)', INFO: emoji.get('information_source') + ' Informazioni', - ASSISTENZA: emoji.get('open_hands') + ' Chat e Assistenza', + ASSISTENZA: emoji.get('open_hands') + ' Le Chat di AYNI', ADMIN: emoji.get('information_desk_person') + ' Admin', ALTRO: emoji.get('newspaper') + ' Altro', @@ -89,18 +147,25 @@ const Menu = { }; +const MenuNoLogin = [[Menu.ACCEDI], [Menu.ASSISTENZA]]; const MenuStandard = [[Menu.LAVAGNA, Menu.LINK_CONDIVIDERE], [Menu.ZOOM, Menu.ASSISTENZA]]; const MenuPerAdmin = [[Menu.LAVAGNA, Menu.LINK_CONDIVIDERE], [Menu.ZOOM, Menu.ASSISTENZA], [Menu.ADMIN, Menu.ALTRO]]; const MenuYesNo = [[Menu.SI, Menu.NO]]; -const MenuAdmin = [[Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.INDIETRO], ['', '']]; +const MenuAdmin = [[Menu.LAVAGNA, Menu.ZOOM], [Menu.MSGSTAFF, Menu.MSGATUTTI, Menu.INDIETRO], ['', '']]; const MenuYes = [[Menu.MSGSTAFF, Menu.INDIETRO], ['', '']]; +const Sex = { + MALE: 1, + FEMALE: -1, +}; + const Status = { NONE: 0, VERIFIED: 1, WAITFOR_USERNAME_BO: 102, WAITFOR_VERIFY_CODE: 103, + WAITFOR_RISPOSTA: 110, }; const StatusMSGALL = { @@ -112,24 +177,21 @@ const StatusMSGALL = { const txt = { 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 (20 caratteri massimo)', - MSG_ERRORE_USERNAME_NOT_FOUND: 'Attenzione! Username o email non trovata in archivio.\nVerifica che sia corretta e riscrivila nuovamente.', + 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 o la email con cui ti sei registrato sul sito di AYNI:', MSG_ERRORE_USERNAME_ANNULLA: 'Inserimento Annullato. Riprovare', MSG_OPERAZ_ANNULLATA: 'Operazione Annullata', MSG_ERRORE_VERIFY_CODE_MAXLEN: 'Attenzione! Devi inserire solo il codice a 6 cifre', - MSG_VERIFY_CODE: 'Copia il codice di Autenticazione che troverai visualizzato sul sito %s, ed incollalo qui sotto', - MSG_ERR_VERIFY_CODE: 'Codice di Verifica Errato! Controlla sul sito %s e riscrivi il nuovo codice di 6 cifre.', - MSG_VERIFY_OK: emoji.get('grinning') + ' Benvenuto %s! Sono AYNI BOT, il tuo assistente virtuale.\n' + - 'Clicca nei menu qui sotto, per accedere alle mie funzioni.', - - // ' - In "La tua Lavagna" puoi controllare se hai completato la lista dei requisiti per entrare in programmazione Bigliettera.\n' + - // ' - in "Zoom (Conferenze) troverai le date dei prossimi Zoom da condividere con i tuoi invitati.\n' + - // ' - in "Link da condividere" trovi i link ', + MSG_VERIFY_CODE: '1. Ora ritorna sul sito di AYNI:\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 AYNI BOT. ' + '\nSono il tuo assistente virtuale.\n' + + 'Continua la guida passo passo tornando sul sito di AYNI.\n\nQuesta chat 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_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 (n. %s)"\n(Invitato da %s)', MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !', + MSG_MSG_INCORSO: emoji.get('envelope') + ' messaggi in corso... Inviati attualmente', }; const TelegramBot = require('node-telegram-bot-api'); @@ -191,6 +253,21 @@ module.exports = { }, + sendMsgTelegramToTheAdmin: async function (idapp, text) { + const usersmanagers = await User.getusersManagers(idapp); + + if (usersmanagers) { + for (const rec of usersmanagers) { + if (User.isAdmin(rec.perm)) { + this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, emo.ROBOT_FACE + '[BOT-STAFF]' + emo.ADMIN + ': ' + text) + await tools.snooze(300) + } + } + } + return true + + }, + sendMsgTelegramToALL: async function (idapp, text) { const usersall = await User.getUsersTelegALL(idapp); @@ -212,19 +289,67 @@ module.exports = { }, - sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text) { + sendMsgTelegramByIdTelegram: async function (idapp, idtelegram, text, message_id, chat_id) { if (!idtelegram) return; const cl = getclTelegByidapp(idapp); if (cl && idtelegram) { - await cl.sendMsg(idtelegram, text) + let myform = null; + + return await cl.sendMsg(idtelegram, text, null, null, message_id, chat_id) } } }; +async function sendMsgTelegramToTheAdmin(idapp, text, msg) { + const usersmanagers = await User.getusersManagers(idapp); + + const username = msg.chat.username; + + 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) { + for (const rec of usersmanagers) { + if (User.isAdmin(rec.perm)) { + const idtelegram = rec.profile.teleg_id; + const cl = getclTelegByidapp(idapp); + if (cl && idtelegram) { + await cl.sendMsg(idtelegram, text) + } + await tools.snooze(300) + } + } + } + return true + +} + +async function local_sendMsgTelegramToTheManagers(idapp, text, msg) { + const usersmanagers = await User.getusersManagers(idapp); + + const username = msg.chat.username; + + text = emo.ROBOT_FACE + '[BOT-STAFF]' + emo.ADMIN + ': Da ' + msg.chat.first_name + ' ' + msg.chat.last_name + ' (' + username + '): \n' + text; + tools.writeEventsLog(text); + + if (usersmanagers) { + for (const rec of usersmanagers) { + const idtelegram = rec.profile.teleg_id; + const cl = getclTelegByidapp(idapp); + if (cl && idtelegram) { + await cl.sendMsg(idtelegram, text) + } + await tools.snooze(300) + } + } + return true + +} + function getstr(lang, text) { return text; @@ -240,7 +365,7 @@ class Telegram { async createIfNotExist(msg) { if (!await this.alreadyExist(msg)) { - if (this.insertIntoDB(msg)) { + if (await this.insertIntoDB(msg)) { let rec = this.getRecInMem(msg); if (rec.user) rec.status = Status.VERIFIED @@ -265,21 +390,227 @@ class Telegram { } + async IsTesto(msg) { + + let risp = ''; + const id = msg.chat.id; + let testo = msg.text.toLowerCase().trim(); + testo = testo.replace('!', ''); + testo = testo.replace('?', ''); + testo = testo.replace('é', 'è'); + let contastiera = false; + + let noanswer = false; + + const rec = this.getRecInMem(msg); + let myname = ''; + if (rec.user) { + myname = rec.user.name + ' ' + rec.user.surname + ' (n.' + rec.user.ind_order + ')'; + } + + 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; + } else if (rec.msgcodeprec === MsgBot.QUANTI_ANNI_HAI) { + const eta = testo.match(/\d+/g); + if (!eta) { + risp = 'Mmmh, non me lo vuoi dire...'; + } else { + if (eta < 20) { + risp = 'Woww! Sei molto giovane!'; + } else if ((eta > 20) && (eta < 30)) { + risp = 'Sei giovane anche tu!'; + } else if ((eta > 30) && (eta < 50)) { + risp = 'Sono i migliori anni questi !'; + } else if ((eta > 50) && (eta < 60)) { + risp = 'Complimenti !'; + } else if (eta > 60) { + risp = 'Però! Ti mantieni in forma!' + emo.SMILE_STAR; + } + + risp = 'Ah ' + eta + ' anni !\n' + risp; + } + } else if (rec.msgcodeprec === MsgBot.CHAT_EMPOWER) { + if (!MsgBot.SI.includes(testo)) { + risp = MsgRisp.CHAT_EMPOWER + } else { + risp = 'Bene ! Allora divertiti conoscendo persone nuove ! '; + } + } else if (rec.msgcodeprec === MsgBot.MASCHIO_FEMMINA) { + if (MsgBot.UOMO.includes(testo)) { + rec.sex = Sex.MALE; + risp = 'Ok, sarò il tuo uomo ' + emo.MALE; + } else { + rec.sex = Sex.FEMALE; + risp = 'Ok, sarò la tua donna ' + emo.ADMIN; + } + } + rec.statusmsg = 0; + } + + rec.msgcodeprec = ''; + + if (risp === '') { + if (MsgBot.CIAO.includes(testo.replace('!', ''))) { + risp = 'Ciao '; + if (rec) + if (rec.user) + risp += rec.user.name; + + risp += '!'; + } 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 + } else if (MsgBot.CHI_SONO_IO.includes(testo.replace('?', ''))) { + risp = 'Su Telegram ti chiami "' + msg.chat.first_name + ' ' + msg.chat.last_name + '"\n'; + if (!!rec.user) { + risp += '\nSul sito ti sei registrato come:\n\n[N. ' + rec.user.ind_order + ']: ' + rec.user.name + ' ' + rec.user.surname + '\nUsername: ' + rec.user.username + '\n' + 'Email: ' + rec.user.email; + } else { + risp = 'Ancora non ti sei Attivato su AYNI BOT'; + } + } else if (MsgBot.CI_SEI.includes(testo.replace('?', ''))) { + 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?'; + rec.statusmsg = Status.WAITFOR_RISPOSTA; + 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; + } 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 AYNI 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; + } else if (MsgBot.CHI_E_VISTAR.includes(testo)) { + risp = 'Vistar è un nomade che vive in Perù tra i selvaggi, filosofeggiando e cazzeggiando qua e la... Per questo è un Fico ed è adulato dalle ragazze di tutto il Globo ' + emo.JOY + emo.JOY + emo.JOY; + } else if (MsgBot.CHI_E_PAOLO.includes(testo)) { + risp = 'Paolo è il Programmatore Sborone di AYNI. Anche lui Fico quanto Vistar (ma chi è Vistar) ' + emo.JOY + ' che anzichè creare la Billettera cazzeggia su AYNI BOT, trovando risposte alle domande più assurde.' + emo.JOY2 + emo.JOY2; + } else if (MsgBot.COME_SI_CHIAMA.includes(testo)) { + risp = 'Eh non te lo posso dire! ' + emo.JOY; + } 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; + } 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 = '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 AYNI - HELP di Supporto\n' + 'https://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w' + '\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; + } 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)) { + 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; + } 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.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; + risp += '\n\n' + MsgRisp.CHAT_EMPOWER; + } else if (MsgBot.SORPRESA.find((rec) => testo.indexOf(rec) > -1) && testo.length < 15) { + risp = 'Siiiii ! Davvero! ' + emo.DREAM + '\nTi ricordo che nella CHAT EMPOWER si fa FESTA!\n\nChat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat:\n https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g'; + } 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 = emo.JOY + emo.JOY + emo.JOY; + } else { + noanswer = true; + risp = 'Non ti capisco... d\'altronde sono solo un Robot ' + emo.ROBOT_FACE + emo.JOY2 + '\n\n(Per AIUTO, contatta la Chat AYNI - HELP)'; + // risp += '\nClicca qui per entrare nella Chat AYNI - HELP di Supporto\n' + 'https://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w' + '\n\nI miei colleghi umani ti aiuteranno a risolvere !'; + await sendMsgTelegramToTheAdmin(this.idapp, testo, msg); + } + } + + let keyboard = {}; + + if (contastiera) { + keyboard = { + "reply_markup": { + "resize_keyboard": true, + "keyboard": await this.getKeyboard(id) + } + } + + } + + if (rec.numdomande > 3 && rec.msgcodeprec === '') { + if (rec.user) { + const dashboard = await User.getDashboard(this.idapp, rec.user.aportador_solidario, rec.user.username, rec.user.aportador_solidario_name_surname); + + risp += '\n\nNel frattempo ti ricordo che '; + if (dashboard.myself.numinvitati === 1) + risp += 'hai solo ' + dashboard.myself.numinvitati + ' invitato!'; + else if (dashboard.myself.numinvitati === 0) + risp += 'ancora non hai portato nessun Invitato! ' + emo.LEFT_FACING_FIST; + else if (dashboard.myself.numinvitati > 2) + risp += 'hai ' + dashboard.myself.numinvitati + ' invitati !' + emo.STARS; + + risp += '\n\nSei già entrato nella Chat di EMPOWER?'; + rec.msgcodeprec = MsgBot.CHAT_EMPOWER; + rec.statusmsg = Status.WAITFOR_RISPOSTA; + rec.numdomande = 0; + } + } + + if (risp !== '') { + rec.numdomande++; + await tools.snooze(600); + this._inviaMsg(id, '[AYNI BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp, keyboard); + + let strlog = 'USER [' + myname + ']: ' + testo + '\n'; + if (!noanswer) { + strlog += 'BOT: ' + risp + '\n'; + } + + tools.writelog(strlog); + } + + + return risp !== ''; + } + async isMenuNotVerified(rec, msg) { if (msg.text === Menu.ASSISTENZA) { await this.menuAssistenza(msg) } else if (msg.text === Menu.INFO) { await this.menuInformazioni(msg) - } else if (msg.text === Menu.ZOOM) { + } else if (msg.text === Menu.ZOOM || MsgBot.PROSSIMO_ZOOM.find((rec) => msg.text.indexOf(rec) > -1)) { await this.menuZoom(msg) + } else if (await this.IsTesto(msg)) { + // OK } else { await this.msgScegliMenu(msg); } } async isMenu(rec, msg) { - if (msg.text === Menu.LAVAGNA) { + if (!msg) + return; + + if (msg.text === undefined) + return; + + if (msg.text === Menu.LAVAGNA || MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) { await this.menuLavagna(msg) + } else if (msg.text === Menu.ACCEDI) { + await this.menuAccedi(msg) } else if (msg.text === Menu.LINK_CONDIVIDERE) { await this.menuLinkCondividere(msg) } else if (msg.text === Menu.EXIT_TELEGRAM) { @@ -321,65 +652,126 @@ class Telegram { return false } + ispayment(user) { + if (user) { + let ispaypal = false; + if (!!user.profile.paymenttypes) { + if (user.profile.paymenttypes.includes('paypal')) { + if (user.profile.email_paypal) { + ispaypal = true + } + } + if (!!user.profile) + if (!!user.profile.paymenttypes) { + return (user.profile.paymenttypes.length >= 1) && ispaypal; + } + + } + } + return false + } + + async menuAccedi(msg) { + let status = this.getstatusInMemory(msg); + if (status === Status.WAITFOR_USERNAME_BO) { + await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND, MenuNoLogin); + } + } + + async getLavagnaByUser(user, msg) { + + let mystr = ''; + + const dashboard = await User.getDashboard(this.idapp, user.aportador_solidario, user.username, user.aportador_solidario_name_surname); + + let numpersone = (dashboard.downline) ? dashboard.downline.length : 0; + let invitati_attivi = dashboard.myself.numinvitatiattivi; + mystr = ""; + // if (dashboard.aportador) { + // mystr = emoji.get('seedling') + ` Chi ti ha invitato: ${dashboard.aportador.username} (${dashboard.aportador.name} ${dashboard.aportador.surname})\n`; + // } else { + // mystr = 'Chi ti ha invitato: Sei il Primo! '; + // } + // mystr += `____________________________________________\n`; + + let tuttie9 = false; + + if (user) { + mystr += tools.get__('BENVENUTO', msg) + ' ' + user.name + ' (' + user.username + ') ' + emo.DIZZY + '\n\n'; + + tuttie9 = dashboard.myself.qualified && (numpersone >= 2) && invitati_attivi >= 2; + + if (!tuttie9) { + mystr += dashboard.myself.qualified ? emo.SMILE_STAR + tools.get__('HAI_I_7_REQUISITI', msg) + emo.SMILE_STAR : emo.EXCLAMATION_MARK + tools.get__('NON_HAI_I_7_REQUISITI', msg); + mystr += '\n\n'; + } + mystr += tuttie9 ? emo.SMILE_STAR + tools.get__('HAI_I_9_REQUISITI', msg) + emo.SMILE_STAR : emo.EXCLAMATION_MARK + tools.get__('NON_HAI_I_9_REQUISITI', msg); + mystr += '\n\n'; + + mystr += tools.get__('INFO_LA_MIA_LAVAGNA', msg); + + mystr += '\n' + '1. ' + this.getsymb(emo.ENVELOPE, user.verified_email); + mystr += tools.get__('EMAIL', msg) + ' '; + mystr += user.verified_email ? tools.get__('VERIF', msg) : tools.get__('EMAIL_NON_VERIF', msg); + + mystr += '\n2. ' + this.getsymb(emo.ROBOT_FACE, true) + tools.get__('BOT', msg) + ' '; + mystr += tools.get__('VERIF', msg); + + mystr += '\n3. ' + this.getsymb(emo.PENCIL, tools.isBitActive(user.profile.saw_and_accepted, shared_consts.Accepted.CHECK_READ_GUIDELINES)) + tools.get__('LINEE_GUIDA', 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', msg); + mystr += '\n5. ' + this.getsymb(emo.EYES, user.profile.saw_zoom_presentation) + tools.get__('ZOOM_PARTECIPATO', msg); + mystr += '\n6. ' + this.getsymb(emo.DREAM, this.isdreamset(user)) + tools.get__('SCRITTO_SOGNO', msg); + mystr += '\n7. ' + this.getsymb(emo.CREDIT_CARD, this.ispayment(user)) + tools.get__('PAYMENTS', msg); + + // } else{ + // mystr += tools.get__('TELEGRAM_NOT_CONNECTED', msg) + ' ' + emoji.get('e-mail'); + } + + // numpersone = 2; + + mystr += '\n8. ' + this.getsymb(emo.INVITATI, numpersone >= 2, numpersone, numpersone, numpersone >= 3) + tools.get__('INVITATI', msg); + mystr += '\n9. ' + this.getsymb(emo.INVITATI, invitati_attivi >= 2, invitati_attivi, invitati_attivi, invitati_attivi >= 3) + tools.get__('INVITATI_ATTIVI', msg) + '\n' + '\n'; + + if (numpersone > 0) { + mystr += tools.get__('INVITATI_LISTA') + ':\n'; + + let index = 1; + dashboard.downline.forEach((user) => { + mystr += emoji.get('star-struck') + ` ${index}°: `; + mystr += (user._doc.qualified) ? emo.CHECK_VERDE : emo.CROSS_ROSSA; + mystr += `${user.name} ${user.surname} (${user.username})\n`; + index++; + }); + } else { + mystr += tools.get__('NESSUN_INVITATO') + tools.ACAPO; + } + + + if (dashboard.downnotreg) { + if (dashboard.downnotreg.length > 0) { + mystr += '\n' + emo.QUESTION_MARK + ' ' + tools.get__('NONREG', msg) + ':' + emo.QUESTION_MARK + '\n'; + let index = 1; + dashboard.downnotreg.forEach((user) => { + mystr += ` - ${index}°: ${user.name} ${user.surname} (tel: ${user.cell_complete})\n`; + index++; + }); + } + } + + if (tuttie9) + mystr += '\n' + printf(tools.get__('INFO_LAVAGNA_SITO', msg)); + else + mystr += '\n' + printf(tools.get__('INFO_LAVAGNA_SITO_COMPLETARE', msg), tools.getHostByIdApp(this.idapp)); + + return mystr; + } + async menuLavagna(msg) { const rec = this.getRecInMem(msg); // console.log('rec', rec); let mystr = ''; if (rec.user) { - - const dashboard = await User.getDashboard(this.idapp, rec.user.aportador_solidario, rec.user.username, rec.user.aportador_solidario_name_surname); - - let numpersone = (dashboard.downline) ? dashboard.downline.length : 0; - mystr = ""; - // if (dashboard.aportador) { - // mystr = emoji.get('seedling') + ` Chi ti ha invitato: ${dashboard.aportador.username} (${dashboard.aportador.name} ${dashboard.aportador.surname})\n`; - // } else { - // mystr = 'Chi ti ha invitato: Sei il Primo! '; - // } - // mystr += `____________________________________________\n`; - - if (rec.user) { - mystr += tools.get__('BENVENUTO', msg) + ' ' + rec.user.name + ' (' + rec.user.username + ') ' + emo.DIZZY + '\n\n'; - mystr += tools.get__('INFO_LA_MIA_LAVAGNA', msg); - - mystr += '\n' + this.getsymb(emo.ENVELOPE, rec.user.verified_email); - mystr += rec.user.verified_email ? tools.get__('EMAIL_VERIF', msg) : tools.get__('EMAIL_NON_VERIF', msg); - - mystr += '\n' + '\n' + this.getsymb(emo.PENCIL, tools.isBitActive(rec.user.profile.saw_and_accepted, shared_consts.Accepted.CHECK_READ_GUIDELINES)) + tools.get__('LINEE_GUIDA', msg); - mystr += '\n' + '\n' + this.getsymb(emo.TV, tools.isBitActive(rec.user.profile.saw_and_accepted, shared_consts.Accepted.CHECK_SEE_VIDEO_PRINCIPI)) + tools.get__('VIDEO_INTRO', msg); - mystr += '\n' + '\n' + this.getsymb(emo.EYES, rec.user.profile.saw_zoom_presentation) + tools.get__('ZOOM_PARTECIPATO', msg); - mystr += '\n' + '\n' + this.getsymb(emo.DREAM, this.isdreamset(rec.user)) + tools.get__('SCRITTO_SOGNO', msg); - - // } else{ - // mystr += tools.get__('TELEGRAM_NOT_CONNECTED', msg) + ' ' + emoji.get('e-mail'); - } - - // numpersone = 2; - - mystr += '\n' + '\n' + this.getsymb(emo.INVITATI, numpersone >= 2, numpersone, numpersone, numpersone >= 3) + tools.get__('INVITATI', msg) + '\n'; - - if (numpersone > 0) { - let index = 1; - dashboard.downline.forEach((user) => { - mystr += emoji.get('star-struck') + ` ${index}°: ${user.name} ${user.surname} (${user.username})\n`; - index++; - }); - } - - - if (dashboard.downnotreg) { - if (dashboard.downnotreg.length > 0) { - mystr += '\n' + emo.QUESTION_MARK + ' ' + tools.get__('NONREG', msg) + ':' + emo.QUESTION_MARK + '\n'; - let index = 1; - dashboard.downnotreg.forEach((user) => { - mystr += ` - ${index}°: ${user.name} ${user.surname} (tel: ${user.cell_complete})\n`; - index++; - }); - } - } - - mystr += '\n' + printf(tools.get__('INFO_LAVAGNA_SITO', msg), tools.getHostByIdApp(this.idapp)); - + mystr = await this.getLavagnaByUser(rec.user, msg) } if (!!mystr) @@ -399,12 +791,14 @@ class Telegram { async menuExitToTelegram(msg) { const rec = this.getRecInMem(msg); if (rec.user) { - await User.SetTelegramIdSuccess(this.idapp, rec.user.username, 0).then((recuser) => { + await User.SetTelegramIdSuccess(this.idapp, rec.user._id, 0).then((recuser) => { if (recuser) { this.deleteRecInMem(msg); this.sendMsg(msg.chat.id, txt.MSG_EXIT_TELEGRAM); } }) + } else { + this.deleteRecInMem(msg); } } @@ -413,12 +807,12 @@ class Telegram { await this.sendMsg(msg.chat.id, mystr); } - async menuZoom(msg) { - let mystr = ''; + async getNextZoom() { const listazoom = await CalZoom.findAllIdApp(this.idapp); - const nextzoom = await CalZoom.getNextZoom(this.idapp); + let mystr = ''; + mystr += emo.STARS + tools.get__('ZOOM_CONFERENCE') + emo.STARS + '\n\n'; let index = 1; @@ -429,14 +823,14 @@ class Telegram { if (iniziata) { - mystr += emo.CHECK_VERDE + ' QUESTA CONFERENZA E\' INIZIATA! ' + emo.CHECK_VERDE + '\n'; + mystr += emo.CHECK_VERDE + ' ' + tools.get__('ZOOM_INIZIATO') + ' ' + emo.CHECK_VERDE + '\n'; } mystr += `${emo.EYES} ${tools.getstrDateTimeShort(evento.date_start)} ${emo.EYES}`; mystr += `\n${evento.title}\n(${evento.note})\n\n`; if (nextzoom) { if (iniziata) { - mystr += emo.FIRE + 'CLICCA QUI PER ENTRARE ! ' + emo.FIRE + '\n'; + mystr += emo.FIRE + tools.get__('CLICCA_ENTRA') + ' ' + emo.FIRE + '\n'; mystr += tools.getlinkzoom(evento.id_conf_zoom) + '\n\n'; } } @@ -446,15 +840,21 @@ class Telegram { }); if (!nextzoom && index > 1) { - mystr += "LINK ZOOM DA CONDIVIDERE :\n" + tools.getlinkzoom(listazoom[0].id_conf_zoom) + '\n\n'; + mystr += "✨✨✨✨✨✨✨✨✨✨✨✨\n" + + tools.get__('CLICCA_PER_ZOOM') + ':\n' + tools.getlinkzoom(listazoom[0].id_conf_zoom) + '\n' + "✨✨✨✨✨✨✨✨✨✨✨✨\n" + '\n'; } + return mystr + } + + async menuZoom(msg) { + let mystr = await this.getNextZoom(); await this.sendMsg(msg.chat.id, mystr); } async menuAdmin(msg) { - const mystr = 'scegli una voce:'; + const mystr = tools.get__('SCEGLI_VOCE'); await this.sendMsg(msg.chat.id, mystr, MenuAdmin); } @@ -483,8 +883,14 @@ class Telegram { const mytext = tools.get__('TESTO_ASSISTENZA', msg); + let menu = null; + const rec = this.getRecInMem(msg); + if (!rec.user) { + menu = MenuNoLogin + } + await - this.sendMsg(msg.chat.id, mytext); + this.sendMsg(msg.chat.id, mytext, menu); } existInMemory(msg) { @@ -508,50 +914,61 @@ class Telegram { return this.arrUsers.find((rec) => rec.id === msg.from.id); } + getRecInMemById(id) { + return this.arrUsers.find((rec) => rec.id === id); + } + deleteRecInMem(msg) { this.arrUsers = this.arrUsers.filter((rec) => rec.id !== msg.from.id); } + async getUser(msg, rec, conmsg) { + let myid = 0; + let ok = false; + const user = await User.findByUsername(this.idapp, msg.text.trim(), true); + if (!user) { + if (conmsg) { + await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND, MenuNoLogin); + const textman = msg.chat.first_name + ' ' + msg.chat.last_name + ' sta tentando di autenticarsi con il BOT (username che scrive: ' + msg.text + ') '; + await local_sendMsgTelegramToTheManagers(this.idapp, textman, msg); + rec.username_bo = ''; + } + } else { + rec.username_bo = user.username; + myid = user._id; + ok = true; + } + + return { rec, user, myid, ok }; + } + async setUsernameBo(msg) { try { - const rec = this.getRecInMem(msg); + let rec = this.getRecInMem(msg); if (msg.text === undefined) return false; console.log('msg.text', msg.text); const text = msg.text; - if (text.length < 20) { + if (text.length < 40) { if (rec) { - rec.username_bo = text.trim(); + let ris = await this.getUser(msg, rec, true); + rec = ris.rec; - // Check if username exist - const user = await User.findByUsername(this.idapp, rec.username_bo); - if (!user) { - rec.username_bo = text.toLowerCase().trim(); - const user = await User.findByEmail(this.idapp, rec.username_bo); - if (!user) { - await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND); - rec.username_bo = ''; - } - } else { - rec.user = user; - await - User.SetTelegramCheckCode(this.idapp, rec.username_bo, rec.code); + if (ris.ok) { + rec.user = ris.user; + await User.SetTelegramCheckCode(this.idapp, ris.myid.toString(), rec.code); rec.status = Status.WAITFOR_VERIFY_CODE; - await - this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_CODE, tools.getHostByIdApp(this.idapp))) - + await this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_CODE, tools.getHostByIdApp(this.idapp)), MenuNoLogin) } } } else if (text.length === 0) { if (rec) rec.status = Status.NONE; - await - this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA); + await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_ANNULLA); this.deleteRecInMem(msg) } else { - await - this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME) + await this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME) } } catch (e) { console.error('Error setUsernameBo:', e) @@ -560,31 +977,31 @@ class Telegram { async setVerifyCode(msg) { try { - const rec = this.getRecInMem(msg); - const user = await - User.findByUsername(this.idapp, rec.username_bo); const code = msg.text.toString().trim(); + const rec = this.getRecInMem(msg); + 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, txt.MSG_ERRORE_USERNAME_NOT_FOUND); + this.sendMsg(msg.from.id, txt.MSG_ERRORE_USERNAME_NOT_FOUND, MenuNoLogin); return } - if (msg.text.length < 7) { + 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, rec.username_bo, msg.from.id).then((recuser) => { - if (recuser) { - let name = recuser.name; - this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_OK, name)) - } else { - this.sendMsg(msg.from.id, txt.MSG_ERR_UNKNOWN_VERIFY_CODE); - } - }); + await User.SetTelegramIdSuccess(this.idapp, user._id, msg.from.id).then((recuser) => { + if (recuser) { + let name = recuser.name; + this.sendMsg(msg.from.id, printf(txt.MSG_VERIFY_OK, name)); + local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT!' + emo.STARS, msg); + } else { + this.sendMsg(msg.from.id, txt.MSG_ERR_UNKNOWN_VERIFY_CODE); + } + }); } else { if (rec.retry < 2) { rec.retry++; @@ -615,28 +1032,47 @@ class Telegram { async sendMsgToAll(rec, msg, texttosend, solostaff) { if (texttosend.length < 3) { } else { - const usersall = await - User.getUsersTelegALL(rec.user.idapp); + const usersall = await User.getUsersTelegALL(rec.user.idapp); let nummsgsent = 0; + let textdainviare = ""; + + if (texttosend === Menu.ZOOM) { + texttosend = await this.getNextZoom() + } + if (usersall) { - for (const rec of usersall) { + if (solostaff) + tools.writeEventsLog('[MSG_A_STAFF]: ' + texttosend); + else + tools.writeEventsLog('[MSG_A_TUTTI]: ' + texttosend); + + for (const utente of usersall) { + + if (texttosend === Menu.LAVAGNA) { + textdainviare = await this.getLavagnaByUser(utente, msg); + } else { + textdainviare = texttosend; + } let invia = true; if (solostaff) { - invia = User.isManager(rec.perm) + invia = User.isManager(utente.perm) } if (invia) { - await this.sendMsg(rec.profile.teleg_id, texttosend); + await this.sendMsg(utente.profile.teleg_id, textdainviare); nummsgsent++; - tools.snooze(300) + await tools.snooze(300) } + + if ((nummsgsent % 100) === 0) + myid = await this.sendMsg(msg.chat.id, nummsgsent + ' ' + getstr(msg.from.language_code, txt.MSG_MSG_INCORSO), null, { message_id: myid }); + // ++Todo: SLEEP ??? sleep(0.03) } } - await - this.sendMsg(msg.chat.id, nummsgsent + ' ' + getstr(msg.from.language_code, txt.MSG_MSG_SENT)); + await this.sendMsg(msg.chat.id, nummsgsent + ' ' + getstr(msg.from.language_code, txt.MSG_MSG_SENT)); } rec.start_write_msgall = false; } @@ -648,28 +1084,23 @@ class Telegram { async receiveMsg(msg) { let status = this.getstatusInMemory(msg); if (status === Status.NONE) { - await - this.start(msg); + await this.start(msg); let status = this.getstatusInMemory(msg); if (status !== Status.VERIFIED) return } else { - await - this.setUser(msg) + await this.setUser(msg) } const rec = this.getRecInMem(msg); status = this.getstatus(rec); if (status === Status.WAITFOR_USERNAME_BO && !this.selectMenuHelp(msg)) { - await - this.setUsernameBo(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); + await this.start(msg); } else if (status === Status.VERIFIED) { let normale = true; if (rec.msgall_status === StatusMSGALL.CONFIRM) { @@ -701,8 +1132,7 @@ class Telegram { if (normale) { // Check Menu - await - this.isMenu(rec, msg); + await this.isMenu(rec, msg); } } else { await @@ -714,11 +1144,10 @@ class Telegram { const rec = this.arrUsers.find((rec) => rec.id === msg.from.id); if (!rec) { - await - this.addUser(msg); + await this.addUser(msg); // await this.sendMsg(msg.chat.id, getstr(msg.from.language_code, printf(txt.MSG_ASK_USERNAME_BO, tools.getHostByIdApp(this.idapp)))); - await this.sendMsg(msg.chat.id, getstr(msg.from.language_code, printf(txt.MSG_ASK_USERNAME_BO, tools.getNomeAppByIdApp(this.idapp)))); + await this.sendMsg(msg.chat.id, getstr(msg.from.language_code, printf(txt.MSG_ASK_USERNAME_BO, tools.getNomeAppByIdApp(this.idapp))), MenuNoLogin); return false; } @@ -741,8 +1170,7 @@ class Telegram { const id = msg.from.id; let rec = null; try { - const user = await - User.UserByIdTelegram(this.idapp, id); + const user = await User.UserByIdTelegram(this.idapp, id); let rec = this.arrUsers.find((rec) => rec.id === msg.from.id); if (user && !rec) { rec = this.addUser(msg); @@ -769,6 +1197,10 @@ class Telegram { code, lang, status: Status.WAITFOR_USERNAME_BO, + statusmsg: 0, + msgcodeprec: '', + sex: 0, + numdomande: 0, retry: 0, username_bo: '', msgall_status: StatusMSGALL.NONE, @@ -781,9 +1213,9 @@ class Telegram { } - insertIntoDB(msg) { + async insertIntoDB(msg) { - return this.askVerifiedCode(msg); + return await this.askVerifiedCode(msg); } @@ -801,32 +1233,76 @@ class Telegram { return keyb } - async sendMsg(id, text, menu) { - if (!text) - return; + modificaMsg(chatid, idmodif, text) { + const form = { + "chat_id": chatid, + "message_id": idmodif, + }; - this.bot.sendMessage(id, text, { - "reply_markup": { - "resize_keyboard": true, - "keyboard": await this.getKeyboard(id, menu) + try { + return this.bot.editMessageText(text, form); + } catch (e) { + console.log('Err Telegram: ' + e); + } + + } + + async _inviaMsg(id, text, form, menu, msg_id, chat_id) { + if (!text) + return 0; + + if (!!msg_id) { + return this.modificaMsg(chat_id, msg_id, text); + } + + try { + if (!form) { + form = { + "message_id": msg_id, + "reply_markup": { + "resize_keyboard": true, + "keyboard": await this.getKeyboard(id, menu) + } + }; } - }) - ; + const res = 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); + } + return 0; + }); + + return res; + } catch (e) { + return 0 + } + } + + async sendMsg(id, text, menu, form, msg_id, chat_id) { + + return this._inviaMsg(id, text, form, menu, msg_id, chat_id); + } async msgBenvenuto(id) { - - this.bot.sendMessage(id, Benvenuto, { + return this._inviaMsg(id, Benvenuto, { "reply_markup": { "resize_keyboard": true, "keyboard": await this.getKeyboard(id) } - }) - ; + }); } async ChiediSINO(msg, domanda) { - this.bot.sendMessage(msg.from.id, domanda, { + this._inviaMsg(msg.from.id, domanda, { "reply_markup": { "resize_keyboard": true, 'one_time_keyboard': true, @@ -838,7 +1314,7 @@ class Telegram { async msgScegliMenu(msg) { // const rec = this.getRecInMem(msg); - this.bot.sendMessage(msg.from.id, txt.MSG_SCEGLI_MENU, { + this._inviaMsg(msg.from.id, txt.MSG_SCEGLI_MENU, { "reply_markup": { "resize_keyboard": true, "keyboard": await this.getKeyboard(msg.from.id) diff --git a/src/server/tools/general.js b/src/server/tools/general.js index 538f884..b009db4 100644 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -22,6 +22,9 @@ const server_constants = require('./server_constants'); // SETTINGS WebPush Configuration const webpush = require('web-push'); +const FILELOG = 'filelog.txt'; +const FILEEVENTS = 'logevents.txt'; +const FILEBILLETTERA = 'logBillettera.txt'; const subject = process.env.URLBASE_APP1; const publicVapidKey = process.env.PUBLIC_VAPI_KEY; const privateVapidKey = process.env.PRIVATE_VAPI_KEY; @@ -45,13 +48,21 @@ textlang = { "Nuova Registrazione": "Nuova Registrazione", "Effettuata una Nuova Registrazione": "Effettuata una Nuova Registrazione", "partecipanti": "partecipanti", - 'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI-BiblioBacheca: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI Help & Support'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", + 'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat:\n https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g\n\nChat AYNI-BIBLIO: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI - HELP'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", 'BENVENUTO': "Benvenuto", - 'INFO_LA_MIA_LAVAGNA': 'In questa sezione puoi controllare se hai completato la lista dei requisiti per entrare in programmazione Bigliettera:\n', - 'INFO_LAVAGNA_SITO': 'Per accedere al menu completo vai sul sito %s, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "La tua Lavagna".\n', + 'HAI_I_7_REQUISITI': 'PRIMI PASSI OK!\nHai i Primi 7 Requisiti per Entrare in programmazione!', + 'NON_HAI_I_7_REQUISITI': 'Attenzione!\nAncora non hai i 7 Requisiti per Entrare in programmazione!', + 'HAI_I_9_REQUISITI': 'COMPLIMENTI!\nHai TUTTI i 9 Requisiti per poter effettuare e poi ricevere il tuo Dono!', + 'NON_HAI_I_9_REQUISITI': 'Attenzione!\nAncora non hai Tutti i 9 Requisiti per poter effettuare e poi ricevere il tuo Dono!', + 'INFO_LA_MIA_LAVAGNA': '✨ Lista dei Requisiti: ✨ \n', + 'INFO_LAVAGNA_SITO_COMPLETARE': 'Per completare tutti i requisiti vai sul sito:\n%s\nPer vedere lo stato dei tuoi invitati, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "Lavagna".\n', + 'INFO_LAVAGNA_SITO': 'Per vedere lo stato dei tuoi invitati, sul sito AYNI, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "Lavagna".\n', 'INFO_LINK_DA_CONDIVIDERE': 'Link da condividere ai tuoi invitati per farli registrare al sito di Ayni:\n%s\n\nLink da condividere per partecipare allo Zoom (Conferenza OnLine):\n%s', 'ZOOM_CONFERENCE': 'Qui trovi le date di programmazione agli Zoom:', - 'EMAIL_VERIF': "Email Verificata", + "NON_VERIF": "Non Verificata", + "VERIF": "Verificata", + 'EMAIL': "Email", + 'BOT': "AYNI BOT", 'EMAIL_NON_VERIF': "Email Non Verificata\nleggi la tua casella email e trova **\"Confermare la Registrazione a Ayni\"**
e clicca sul bottone **\"Verifica Registrazione\"**", 'TELEGRAM_NOT_CONNECTED': "Telegram non associato al tuo account!", 'NESSUN_INVITATO': 'Non hai invitato nessuno', @@ -59,22 +70,36 @@ textlang = { 'LINEE_GUIDA': 'Accettato le Linee Guida', 'VIDEO_INTRO': 'Visto il Video di AYNI', 'SCRITTO_SOGNO': 'Hai scritto il tuo Sogno', + 'PAYMENTS': 'Modalità di Pagamento', 'INVITATI': 'persone registrate che hai invitato', + 'INVITATI_ATTIVI': 'Invitati con i 7 Requisiti', 'NONREG': 'Invitati non Registrati', + 'CLICCA_PER_ZOOM': 'AL GIORNO E ORA INDICATA, PER ENTRARE NELLA VIDEO-CONFERENZA, CLICCA QUI', + 'CLICCA_ENTRA': 'CLICCA QUI PER ENTRARE !', + 'ZOOM_INIZIATO': 'QUESTA CONFERENZA E\' INIZIATA!', + 'SCEGLI_VOCE': 'scegli una voce:', + 'INVITATI_LISTA': 'I Tuoi Invitati (in verde con almeno i primi 7 Requisiti)', }, es: { "L'Email è già stata Verificata": "L'Email è già stata Verificata", "Nuova Registrazione": "Nuevo Registro", "Effettuata una Nuova Registrazione": "Se ha realizado un nuevo registro", "partecipanti": "participantes", - - 'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI-BiblioBacheca: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI Help & Support'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", + 'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat:\n https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g\n\nChat AYNI-BIBLIO: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI - HELP'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", 'BENVENUTO': "Benvenuto", - 'INFO_LA_MIA_LAVAGNA': 'In questa sezione puoi controllare se hai completato la lista dei requisiti per entrare in programmazione Bigliettera:\n', - 'INFO_LAVAGNA_SITO': 'Per accedere al menu completo vai sul sito %s, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "La tua Lavagna".\n', + 'HAI_I_7_REQUISITI': 'PRIMI PASSI OK!\nHai i Primi 7 Requisiti per Entrare in programmazione!', + 'NON_HAI_I_7_REQUISITI': 'Attenzione!\nAncora non hai i 7 Requisiti per Entrare in programmazione!', + 'HAI_I_9_REQUISITI': 'COMPLIMENTI!\nHai TUTTI i 9 Requisiti per poter effettuare e poi ricevere il tuo Dono!', + 'NON_HAI_I_9_REQUISITI': 'Attenzione!\nAncora non hai Tutti i 9 Requisiti per poter effettuare e poi ricevere il tuo Dono!', + 'INFO_LA_MIA_LAVAGNA': '✨ Lista dei Requisiti: ✨ \n', + 'INFO_LAVAGNA_SITO_COMPLETARE': 'Per completare tutti i requisiti vai sul sito:\n%s\nPer vedere lo stato dei tuoi invitati, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "Lavagna".\n', + 'INFO_LAVAGNA_SITO': 'Per vedere lo stato dei tuoi invitati, sul sito AYNI, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "Lavagna".\n', 'INFO_LINK_DA_CONDIVIDERE': 'Link da condividere ai tuoi invitati per farli registrare al sito di Ayni:\n%s\n\nLink da condividere per partecipare allo Zoom (Conferenza OnLine):\n%s', 'ZOOM_CONFERENCE': 'Qui trovi le date di programmazione agli Zoom:', - 'EMAIL_VERIF': "Email Verificata", + "NON_VERIF": "Non Verificata", + "VERIF": "Verificata", + 'EMAIL': "Email", + 'BOT': "AYNI BOT", 'EMAIL_NON_VERIF': "Email Non Verificata\nleggi la tua casella email e trova **\"Confermare la Registrazione a Ayni\"**
e clicca sul bottone **\"Verifica Registrazione\"**", 'TELEGRAM_NOT_CONNECTED': "Telegram non associato al tuo account!", 'NESSUN_INVITATO': 'Non hai invitato nessuno', @@ -82,18 +107,33 @@ textlang = { 'LINEE_GUIDA': 'Accettato le Linee Guida', 'VIDEO_INTRO': 'Visto il Video di AYNI', 'SCRITTO_SOGNO': 'Hai scritto il tuo Sogno', + 'PAYMENTS': 'Modalità di Pagamento', 'INVITATI': 'persone registrate che hai invitato', + 'INVITATI_ATTIVI': 'Invitati con i 7 Requisiti', 'NONREG': 'Invitati non Registrati', + 'CLICCA_PER_ZOOM': 'AL GIORNO E ORA INDICATA, PER ENTRARE NELLA VIDEO-CONFERENZA, CLICCA QUI', + 'CLICCA_ENTRA': 'CLICCA QUI PER ENTRARE !', + 'ZOOM_INIZIATO': 'QUESTA CONFERENZA E\' INIZIATA!', + 'SCEGLI_VOCE': 'scegli una voce:', + 'INVITATI_LISTA': 'I Tuoi Invitati (in verde con almeno i primi 7 Requisiti)', }, us: { "partecipanti": "participants", - 'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI-BiblioBacheca: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI Help & Support'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", + 'TESTO_ASSISTENZA': "Per entrare nel Sito AYNI:\nhttps://ayni.gifteconomy.app\n\nHai dimenticato la Password per accedere al sito?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\nChat AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\nChat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat:\n https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g\n\nChat AYNI-BIBLIO: https://t.me/joinchat/AL2qKExZKvenLgpVhOyefQ \n\nChat di Aiuto e Supporto: 'AYNI - HELP'\nhttps://t.me/joinchat/C741mlVmB_RMcOUpNqWC8w\n1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", 'BENVENUTO': "Benvenuto", - 'INFO_LA_MIA_LAVAGNA': 'In questa sezione puoi controllare se hai completato la lista dei requisiti per entrare in programmazione Bigliettera:\n', - 'INFO_LAVAGNA_SITO': 'Per accedere al menu completo vai sul sito %s, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "La tua Lavagna".\n', + 'HAI_I_7_REQUISITI': 'PRIMI PASSI OK!\nHai i Primi 7 Requisiti per Entrare in programmazione!', + 'NON_HAI_I_7_REQUISITI': 'Attenzione!\nAncora non hai i 7 Requisiti per Entrare in programmazione!', + 'HAI_I_9_REQUISITI': 'COMPLIMENTI!\nHai TUTTI i 9 Requisiti per poter effettuare e poi ricevere il tuo Dono!', + 'NON_HAI_I_9_REQUISITI': 'Attenzione!\nAncora non hai Tutti i 9 Requisiti per poter effettuare e poi ricevere il tuo Dono!', + 'INFO_LA_MIA_LAVAGNA': '✨ Lista dei Requisiti: ✨ \n', + 'INFO_LAVAGNA_SITO_COMPLETARE': 'Per completare tutti i requisiti vai sul sito:\n%s\nPer vedere lo stato dei tuoi invitati, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "Lavagna".\n', + 'INFO_LAVAGNA_SITO': 'Per vedere lo stato dei tuoi invitati, sul sito AYNI, clicca sulle 3 linee in alto a sinistra ed accedi alla voce "Lavagna".\n', 'INFO_LINK_DA_CONDIVIDERE': 'Link da condividere ai tuoi invitati per farli registrare al sito di Ayni:\n%s\n\nLink da condividere per partecipare allo Zoom (Conferenza OnLine):\n%s', 'ZOOM_CONFERENCE': 'Qui trovi le date di programmazione agli Zoom:', - 'EMAIL_VERIF': "Email Verificata", + "NON_VERIF": "Non Verificata", + "VERIF": "Verificata", + 'EMAIL': "Email", + 'BOT': "AYNI BOT", 'EMAIL_NON_VERIF': "Email Non Verificata\nleggi la tua casella email e trova **\"Confermare la Registrazione a Ayni\"**
e clicca sul bottone **\"Verifica Registrazione\"**", 'TELEGRAM_NOT_CONNECTED': "Telegram non associato al tuo account!", 'NESSUN_INVITATO': 'Non hai invitato nessuno', @@ -101,17 +141,27 @@ textlang = { 'LINEE_GUIDA': 'Accettato le Linee Guida', 'VIDEO_INTRO': 'Visto il Video di AYNI', 'SCRITTO_SOGNO': 'Hai scritto il tuo Sogno', + 'PAYMENTS': 'Modalità di Pagamento', 'INVITATI': 'persone registrate che hai invitato', + 'INVITATI_ATTIVI': 'Invitati con i 7 Requisiti', 'NONREG': 'Invitati non Registrati', + 'CLICCA_PER_ZOOM': 'AL GIORNO E ORA INDICATA, PER ENTRARE NELLA VIDEO-CONFERENZA, CLICCA QUI', + 'CLICCA_ENTRA': 'CLICCA QUI PER ENTRARE !', + 'ZOOM_INIZIATO': 'QUESTA CONFERENZA E\' INIZIATA!', + 'SCEGLI_VOCE': 'scegli una voce:', + 'INVITATI_LISTA': 'I Tuoi Invitati (in verde con almeno i primi 7 Requisiti)', } }; module.exports = { INITDB_FIRSTIME: true, + ACAPO: '\n', LANGADMIN: 'it', + AYNI: '7', + APORTADOR_NONE: '------', TYPE_PROJECT: 1, @@ -602,6 +652,8 @@ module.exports = { $exists: false } }); + if (params.filterand.includes(shared_consts.FILTER_USER_TELEGRAM_BLOCKED)) + filtriadded.push({ 'profile.teleg_id_old': { $gt: 1 } }); } @@ -720,7 +772,7 @@ module.exports = { return myval }, - snooze(ms) { + async snooze(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }, @@ -830,6 +882,30 @@ module.exports = { StrToBool(mystr) { return (mystr === '-1') ? true : false }, + + writelogfile(mystr, filename) { + // fs.appendFile(FILELOG, mystr, function (err) { + // if (err) throw err; + // console.log('Saved!'); + // }); + + const stream = fs.createWriteStream(filename, {flags:'a'}); + stream.write(mystr); + stream.end(); + }, + + writelog(mystr) { + this.writelogfile(mystr, FILELOG); + }, + + writeEventsLog(mystr) { + this.writelogfile(mystr, FILEEVENTS); + }, + + writeBilletteraLog(mystr) { + this.writelogfile(mystr, FILEBILLETTERA); + }, + move(oldPath, newPath, callback) { fs.rename(oldPath, newPath, function (err) { diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js index 4545252..8a20690 100644 --- a/src/server/tools/shared_nodejs.js +++ b/src/server/tools/shared_nodejs.js @@ -17,6 +17,7 @@ module.exports = { FILTER_USER_NO_EMAIL_VERIFICATA: 128, FILTER_USER_NO_DREAM: 256, FILTER_EXTRALIST_DELETED: 512, + FILTER_USER_TELEGRAM_BLOCKED: 1024, Permissions: { Admin: 1, @@ -30,7 +31,7 @@ module.exports = { }, fieldsUserToChange() { - return ['_id', 'username', 'email', 'name', 'surname', 'perm', 'date_reg', 'date_temp_reg', 'verified_email', 'ipaddr', 'lasttimeonline', 'profile', 'calcstat', 'news_on', 'aportador_solidario', 'made_gift', 'ind_order', 'numinvitati', 'numinvitatiattivi'] + return ['_id', 'username', 'email', 'name', 'surname', 'perm', 'date_reg', 'date_temp_reg', 'verified_email', 'ipaddr', 'lasttimeonline', 'profile', 'calcstat', 'news_on', 'aportador_solidario', 'made_gift', 'ind_order', 'numinvitati', 'numinvitatiattivi', 'qualified'] } };