VERSIONE 0.3.3: RISO:

"RISO.APP
alla fine copiare la cartella upload di insiemesipuo.app in riso.app"
Corretto BOT Menu
Altre sistemazioni (idShippings)
This commit is contained in:
paoloar77
2022-03-02 20:18:29 +01:00
parent 310eefba14
commit 94a2a073e5
6 changed files with 126 additions and 72 deletions

View File

@@ -2247,7 +2247,8 @@ UserSchema.statics.getUsersTelegALL = async function(idapp, username) {
const User = this; const User = this;
if (!!username) { if (!!username) {
return User.find({idapp, username, 'profile.teleg_id': {$gt: 0}}). return User.find({idapp, username, 'profile.teleg_id': {$gt: 0}})
.lean()
then((arrrec) => { then((arrrec) => {
return (!!arrrec) ? arrrec : null; return (!!arrrec) ? arrrec : null;
}). }).
@@ -2256,6 +2257,7 @@ UserSchema.statics.getUsersTelegALL = async function(idapp, username) {
}); });
} else { } else {
return User.find({idapp, 'profile.teleg_id': {$gt: 0}}). return User.find({idapp, 'profile.teleg_id': {$gt: 0}}).
lean().
then((arrrec) => { then((arrrec) => {
return (!!arrrec) ? arrrec : null; return (!!arrrec) ? arrrec : null;
}). }).
@@ -2340,7 +2342,8 @@ UserSchema.statics.getFieldsForSearch = function() {
{field: 'profile.revolut', type: tools.FieldType.string}, {field: 'profile.revolut', type: tools.FieldType.string},
{field: 'profile.link_payment', type: tools.FieldType.string}, {field: 'profile.link_payment', type: tools.FieldType.string},
{field: 'profile.teleg_id', type: tools.FieldType.number}, {field: 'profile.teleg_id', type: tools.FieldType.number},
{field: 'profile.username_telegram', type: tools.FieldType.string} {field: 'profile.username_telegram', type: tools.FieldType.string},
{field: 'ipaddr', type: tools.FieldType.string}
]; ];
//{field: 'aportador_solidario', type: tools.FieldType.string} //{field: 'aportador_solidario', type: tools.FieldType.string}
}; };

View File

@@ -88,6 +88,12 @@ const shared_consts = require('../tools/shared_nodejs');
const globalTables = require('../tools/globalTables'); const globalTables = require('../tools/globalTables');
const UserCost = { const UserCost = {
FIELDS_UPDATE_TELEGRAM_BOT: [
'profile.teleg_id',
'profile.manage_telegram',
'deleted',
],
FIELDS_REQUISITI: [ FIELDS_REQUISITI: [
'verified_email', 'verified_email',
'profile.teleg_id', 'profile.teleg_id',
@@ -587,7 +593,9 @@ router.patch('/chval', authenticate, async (req, res) => {
}); });
} }
tools.refreshAllTablesInMem(idapp, mydata.table); const updatebot = UserCost.FIELDS_UPDATE_TELEGRAM_BOT.includes(Object.keys(fieldsvalue)[0]);
tools.refreshAllTablesInMem(idapp, mydata.table, updatebot);
if (mydata.table === shared_consts.TAB_SETTINGS) { if (mydata.table === shared_consts.TAB_SETTINGS) {
if (shared_consts.KEY_TO_CRYPTED.includes(fieldsvalue.key)) { if (shared_consts.KEY_TO_CRYPTED.includes(fieldsvalue.key)) {

View File

@@ -243,7 +243,7 @@ async function myLoad() {
async function mystart() { async function mystart() {
await estraiTutteLeImmagini(); // await estraiTutteLeImmagini();
if (process.env.PROD !== 1) { if (process.env.PROD !== 1) {

View File

@@ -1,9 +1,9 @@
const tools = require('../tools/general'); const tools = require('../tools/general');
const appTelegram = [tools.FREEPLANET, tools.ISP]; const appTelegram = [tools.FREEPLANET, tools.RISO];
const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM, tools.ISP]; const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM, tools.RISO];
const appTelegram_DEVELOP = [tools.ISP]; const appTelegram_DEVELOP = [tools.RISO];
const appTelegramFinti = ['2', tools.CNM]; const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET]; const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
@@ -245,6 +245,7 @@ const Menu = {
EXIT_TELEGRAM: 'exittotelegram', EXIT_TELEGRAM: 'exittotelegram',
MSG_TO_USER: 'sendmsgto', MSG_TO_USER: 'sendmsgto',
ADMIN: emoji.get('information_desk_person') + ' Admin', ADMIN: emoji.get('information_desk_person') + ' Admin',
AIUTO: '🔮 Help',
ALTRO: emoji.get('newspaper') + ' Altro', ALTRO: emoji.get('newspaper') + ' Altro',
SETPICPROFILE: '🖼 SetPicProfile', SETPICPROFILE: '🖼 SetPicProfile',
// MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi', // MSG_TO_NAVE: emoji.get('incoming_envelope') + 'Msg_to_Navi',
@@ -487,6 +488,7 @@ const txt = {
MSG_SET_USERNAME_OK: '😄😄✅✅ Ottimo! Hai impostato lo Username Telegram!\n\n' + MSG_SET_USERNAME_OK: '😄😄✅✅ Ottimo! Hai impostato lo Username Telegram!\n\n' +
'Ora le persone potranno contattarti su Telegram, anche dalla APP visitando il tuo profilo e cliccando sull\'icona di Telegram, (senza dover pubblicare il proprio numero di cellulare).\n\n' + 'Ora le persone potranno contattarti su Telegram, anche dalla APP visitando il tuo profilo e cliccando sull\'icona di Telegram, (senza dover pubblicare il proprio numero di cellulare).\n\n' +
'Ora puoi proseguire sulla APP.', 'Ora puoi proseguire sulla APP.',
MSG_SET_PICPROFILE: '🖼 Abbiamo impostato <b>la tua foto del Profilo</b>, copiandola dalla foto profilo di Telegram. Potrai comunque cambiarla dalla APP (%s)',
MSG_ERR_UNKNOWN_VERIFY_CODE: 'Errore durante il salvataggio sul Server. Riprovare piú tardi', 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_EXIT_TELEGRAM: 'L\'account è stato ora scollegato da questo Telegram BOT.',
MSG_APORTADOR_USER_REGISTERED: emo.FIRE + MSG_APORTADOR_USER_REGISTERED: emo.FIRE +
@@ -1431,10 +1433,6 @@ class Telegram {
this.bot = bot; this.bot = bot;
this.token = bot.token; this.token = bot.token;
this.arrUsers = []; this.arrUsers = [];
this.pagenow = 1;
this.pageChange = false;
this.menuDb = null;
this.menuSaved = {};
this.lastid = 0; this.lastid = 0;
//++ //++
} }
@@ -1598,7 +1596,7 @@ class Telegram {
await User.setUsernameTelegram(this.idapp, rec.user._id, await User.setUsernameTelegram(this.idapp, rec.user._id,
msg.from.username || '', msg.from.first_name || '', msg.from.username || '', msg.from.first_name || '',
msg.from.last_name || ''); msg.from.last_name || '');
this.sendMsg(msg.from.id, await this.sendMsg(msg.from.id,
printf(getstr(rec.user.lang, 'MSG_SET_USERNAME_OK'))); printf(getstr(rec.user.lang, 'MSG_SET_USERNAME_OK')));
} else { } else {
if (!rec.user.profile.username_telegram) { if (!rec.user.profile.username_telegram) {
@@ -1610,7 +1608,7 @@ class Telegram {
if (risp === '') { if (risp === '') {
if (menusite) { if (menusite) {
risp = this.getValueMenu(this.idapp, rec, msg, testo, lang); risp = await this.getValueMenu(this.idapp, rec, msg, testo, lang);
noanswer = true; noanswer = true;
} else if (MsgBot.CIAO.includes(testo.replace('!', ''))) { } else if (MsgBot.CIAO.includes(testo.replace('!', ''))) {
risp = 'Ciao '; risp = 'Ciao ';
@@ -1784,10 +1782,10 @@ class Telegram {
// } // }
} }
if (risp !== '') { if (risp !== '' && risp !== shared_consts.RIS_OK) {
rec.numdomande++; rec.numdomande++;
if (!noanswer) { if (!noanswer) {
await tools.snooze(600); await tools.snooze(500);
risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp; risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp;
} }
this._inviaMsg(id, risp, keyboard); this._inviaMsg(id, risp, keyboard);
@@ -1887,6 +1885,8 @@ class Telegram {
await this.menuExitToTelegram(msg); await this.menuExitToTelegram(msg);
} else if (testo === Menu.ADMIN) { } else if (testo === Menu.ADMIN) {
await this.menuAdmin(msg); await this.menuAdmin(msg);
} else if (testo === Menu.AIUTO) {
await this.menuAiuto(msg);
} else if (testo === Menu.LANG) { } else if (testo === Menu.LANG) {
await this.menuLang(msg); await this.menuLang(msg);
} else if (testo === Menu.MSGATUTTI) { } else if (testo === Menu.MSGATUTTI) {
@@ -2246,6 +2246,10 @@ class Telegram {
await this.sendMsg(msg.chat.id, mystr); await this.sendMsg(msg.chat.id, mystr);
} }
async menuAiuto(msg) {
const mystr = this.getstrChatHelp();
await this.sendMsg(msg.chat.id, mystr);
}
async menuAdmin(msg) { async menuAdmin(msg) {
const mystr = tools.get__('SCEGLI_VOCE', this.getlang(msg)); const mystr = tools.get__('SCEGLI_VOCE', this.getlang(msg));
await await
@@ -2557,14 +2561,15 @@ class Telegram {
// let ris = await this.getUser(msg, rec, false); // let ris = await this.getUser(msg, rec, false);
rec.status = Status.VERIFIED; rec.status = Status.VERIFIED;
rec.datemenu_updated = null;
rec.menuDb = null;
await User.SetTelegramIdSuccess(this.idapp, user._id, await User.SetTelegramIdSuccess(this.idapp, user._id,
msg.from.id).then((recuser) => { msg.from.id).then((recuser) => {
if (recuser) { if (recuser) {
this.setPhotoProfile(rec, msg); this.setPhotoProfile(rec, msg);
let username = recuser.name; let username = recuser.name;
this.sendMsg(msg.from.id, this.sendMsg(msg.from.id,
printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp)));
tools.getHostByIdApp(this.idapp)));
this.checkIfUsernameTelegramSet(msg, recuser); this.checkIfUsernameTelegramSet(msg, recuser);
// local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg); // local_sendMsgTelegramToTheManagers(this.idapp, recuser.name + ' ' + recuser.surname + ' si è Verificato a Telegram BOT! (lang=' + recuser.lang + ')' + emo.STARS, msg);
@@ -2748,6 +2753,8 @@ class Telegram {
} }
if (inviaveramente) { if (inviaveramente) {
textdainviare = this.convertSpecialTags(utente, textdainviare);
if (destin === Destin.A_UTENTE) { if (destin === Destin.A_UTENTE) {
await this.sistemaRecDest(rec, msg); await this.sistemaRecDest(rec, msg);
await this.sendMsg(utente.profile.teleg_id, await this.sendMsg(utente.profile.teleg_id,
@@ -3020,6 +3027,7 @@ class Telegram {
updateMenuBot() { updateMenuBot() {
for (let rec of this.arrUsers) { for (let rec of this.arrUsers) {
rec.menuDb = null;
rec.datemenu_updated = null; rec.datemenu_updated = null;
} }
} }
@@ -3054,6 +3062,10 @@ class Telegram {
msg_wait: false, msg_wait: false,
lastmenu: null, lastmenu: null,
datemenu_updated: null, datemenu_updated: null,
pageChange: false,
menuSaved: {},
pagenow: 1,
menuDb: null,
}; };
this.arrUsers.push(rec); this.arrUsers.push(rec);
@@ -3068,6 +3080,10 @@ class Telegram {
} }
menuisVisible(idapp, menu) {
}
async loadMenuFromDb(idapp, id) { async loadMenuFromDb(idapp, id) {
try { try {
let load = false; let load = false;
@@ -3079,10 +3095,12 @@ class Telegram {
load = true; load = true;
} }
if (check) { if (check) {
if (!(this.menuSaved[idapp])) if (recuser) {
load = true; if (!(recuser.menuSaved[idapp]))
load = true;
}
} }
if (load || !this.menuDb || this.pageChange) { if (load || !recuser.menuDb || recuser.pageChange) {
// Check if you are Admin // Check if you are Admin
const user = await User.UserByIdTelegram(idapp, id); const user = await User.UserByIdTelegram(idapp, id);
@@ -3092,7 +3110,7 @@ class Telegram {
const isVerified = user ? user.profile.teleg_id > 0 && const isVerified = user ? user.profile.teleg_id > 0 &&
user.verified_by_aportador : false; user.verified_by_aportador : false;
this.menuDb = await MyBot.findAllIdApp(idapp); recuser.menuDb = await MyBot.findAllIdApp(idapp);
let arrlang = {}; let arrlang = {};
@@ -3100,16 +3118,12 @@ class Telegram {
let arrtemp = []; let arrtemp = [];
let lang = ''; let lang = '';
for (const rec of this.menuDb) { for (const rec of recuser.menuDb) {
rec.active_mem = false; rec.active_mem = false;
if (rec.active && rec.page === this.pagenow if (rec.active && rec.page === recuser.pagenow
&& ((isAdmin && tools.isBitActive(rec.visibility, && (tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_ADMIN, isAdmin) &&
shared_consts.VISIB_ONLY_ADMIN)) tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_MANAGER, isManager) &&
|| (isManager && tools.isBitActive(rec.visibility, tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLYIF_VERIFIED, isVerified))
shared_consts.VISIB_ONLY_MANAGER))
|| (isVerified && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLYIF_VERIFIED))
|| (rec.visibility === 0))
) { ) {
rec.active_mem = true; rec.active_mem = true;
if (rec.main) { if (rec.main) {
@@ -3137,10 +3151,10 @@ class Telegram {
if (recuser) if (recuser)
recuser.datemenu_updated = new Date(); recuser.datemenu_updated = new Date();
this.pageChange = false; recuser.pageChange = false;
this.menuSaved[idapp] = arrlang; recuser.menuSaved[idapp] = arrlang;
} }
return this.menuSaved[idapp]; return recuser.menuSaved[idapp];
} catch (e) { } catch (e) {
console.log('Err loadMenuFromDb: ' + e); console.log('Err loadMenuFromDb: ' + e);
} }
@@ -3156,7 +3170,7 @@ class Telegram {
} }
} }
for (const rec of this.menuDb) { for (const rec of recuser.menuDb) {
if (rec.active_mem) { if (rec.active_mem) {
if (rec.idapp === idapp && rec.lang === lang && if (rec.idapp === idapp && rec.lang === lang &&
rec.label.toLowerCase() === testo) { rec.label.toLowerCase() === testo) {
@@ -3170,30 +3184,33 @@ class Telegram {
return false; return false;
} }
getValueMenu(idapp, rec, msg, testo, lang) { async getValueMenu(idapp, recuser, msg, testo, lang) {
try { try {
for (const recdb of this.menuDb) { if (recuser) {
if (recdb.active_mem) {
if (recdb.idapp === idapp && recdb.lang === lang &&
recdb.label.toLowerCase() === testo) {
if (recdb.type === shared_consts.BOTTYPE_TEXT) {
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_LINK) {
//++TODO: Link diretto !?
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
this.pagenow = parseInt(recdb.value);
this.pageChange = true;
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true);
return '';
}
}
for (const recdb of recuser.menuDb) {
if (recdb.active_mem) {
if (recdb.idapp === idapp && recdb.lang === lang &&
recdb.label.toLowerCase() === testo) {
if (recdb.type === shared_consts.BOTTYPE_TEXT) {
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_LINK) {
//++TODO: Link diretto !?
return recdb.value;
} else if (recdb.type === shared_consts.BOTTYPE_PAGE) {
if (tools.isNumber(recdb.value)) {
recdb.pagenow = parseInt(recdb.value);
recdb.pageChange = true;
}
return '';
} else if (recdb.type === shared_consts.BOTTYPE_MENU) {
if (recdb.value) {
this.isMenu(rec, msg, recdb.value, true);
return shared_consts.RIS_OK;
}
}
}
} }
} }
} }
@@ -3201,7 +3218,7 @@ class Telegram {
} catch (e) { } catch (e) {
return ''; return '';
} }
return '';
} }
async getKeyboard(id, menu, lang) { async getKeyboard(id, menu, lang) {
@@ -3380,7 +3397,9 @@ class Telegram {
const idapp = this.idapp; const idapp = this.idapp;
const bot = this.bot; const bot = this.bot;
const username = rec.user.username; const username = rec.user.username;
const lang = rec.user.lang;
const token = this.token; const token = this.token;
const editprofile = tools.getHostByIdApp(idapp, true) + '/editprofile';
let myfileprofile = tools.getdirByIdApp(idapp, true) + let myfileprofile = tools.getdirByIdApp(idapp, true) +
server_constants.DIR_UPLOAD + '/profile/' + username +'/'; server_constants.DIR_UPLOAD + '/profile/' + username +'/';
let user_profile = bot.getUserProfilePhotos(msg.from.id); let user_profile = bot.getUserProfilePhotos(msg.from.id);
@@ -3391,16 +3410,21 @@ class Telegram {
file.then(function(result) { file.then(function(result) {
const file_path = result.file_path; const file_path = result.file_path;
const photo_url = 'https://api.telegram.org/file/bot' + token + const photo_url = 'https://api.telegram.org/file/bot' + token + '/' + file_path;
'/' + file_path; console.log('photo_url', photo_url);
let filename = tools.extractFileName(photo_url) let filename = tools.extractFileName(photo_url);
myfileprofile += filename; myfileprofile += filename;
tools.downloadImage(photo_url, myfileprofile). console.log('myfileprofile', myfileprofile);
return tools.downloadImage(photo_url, myfileprofile).
then((ris) => { then((ris) => {
User.setPicProfile(idapp, username, filename); console.log('setPicProfile ris', ris);
return User.setPicProfile(idapp, username, filename).then((ris) => {
console.log('sendMsg picprofile Copied !');
local_sendMsgTelegram(idapp, username, printf(getstr(lang, 'MSG_SET_PICPROFILE'), editprofile));
});
// console.log('scaricato'); // console.log('scaricato');
}); });
// bot.sendMessage(chatId, photo_url);
}); });
} }
}); });

View File

@@ -392,7 +392,7 @@ module.exports = {
AYNI: '7', AYNI: '7',
CNM: '10', CNM: '10',
PDNM: '12', PDNM: '12',
ISP: '13', RISO: '13',
HELP_CHAT: '', HELP_CHAT: '',
TYPECONF_ZOOM: 'zoom', TYPECONF_ZOOM: 'zoom',
@@ -1063,6 +1063,14 @@ module.exports = {
return ''; return '';
}, },
getLinkUserProfile: function (idapp, username) {
return tools.getHostByIdApp(idapp) + '/my/' + username;
},
getLinkEditUserProfile: function (idapp) {
return tools.getHostByIdApp(idapp) + '/editprofile';
},
getConfSiteOptionEnabledByIdApp: function(idapp, option) { getConfSiteOptionEnabledByIdApp: function(idapp, option) {
const myapp = this.getApps().find(item => item.idapp === idapp); const myapp = this.getApps().find(item => item.idapp === idapp);
@@ -1110,7 +1118,7 @@ module.exports = {
mypath = (myapp) ? myapp.dir : ''; mypath = (myapp) ? myapp.dir : '';
if (dirmain) { if (dirmain) {
if (this.sulServer() !== 1) { if (!this.sulServer()) {
mypath += '/public'; mypath += '/public';
} }
} }
@@ -1683,6 +1691,12 @@ module.exports = {
return ((bit & whattofind) === whattofind); return ((bit & whattofind) === whattofind);
}, },
isBitAttivoESelez(bit, whattofind, loSono) {
const abil = this.isBitActive(bit, whattofind);
return ((abil && loSono) || !abil);
},
SetBit(myval, bit) { SetBit(myval, bit) {
myval = myval & bit; myval = myval & bit;
return myval; return myval;
@@ -2594,10 +2608,10 @@ module.exports = {
return process.env.LOCALE !== '1'; return process.env.LOCALE !== '1';
}, },
refreshAllTablesInMem(idapp, table) { refreshAllTablesInMem(idapp, table, updatebot) {
const telegrambot = require('../telegram/telegrambot'); const telegrambot = require('../telegram/telegrambot');
if (table === shared_consts.TAB_MYBOTS) { if (table === shared_consts.TAB_MYBOTS || updatebot) {
telegrambot.reloadMenuBot(idapp); telegrambot.reloadMenuBot(idapp);
} else if (table === shared_consts.TAB_SITES) { } else if (table === shared_consts.TAB_SITES) {
telegrambot.reloadSites(); telegrambot.reloadSites();
@@ -2606,11 +2620,14 @@ module.exports = {
}, },
downloadImage(url, filepath) { downloadImage(url, filepath) {
try {
return download.image({ return download.image({
url, url,
dest: filepath dest: filepath
}); });
}catch (e) {
return false;
}
}, },

View File

@@ -155,6 +155,8 @@ module.exports = {
BOTTYPE_TEXT: 3, BOTTYPE_TEXT: 3,
BOTTYPE_MENU: 4, BOTTYPE_MENU: 4,
RIS_OK: '👍🏻 OK',
CashType: { CashType: {
None: 0, None: 0,
Incoming: 1, Incoming: 1,