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;
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) => {
return (!!arrrec) ? arrrec : null;
}).
@@ -2256,6 +2257,7 @@ UserSchema.statics.getUsersTelegALL = async function(idapp, username) {
});
} else {
return User.find({idapp, 'profile.teleg_id': {$gt: 0}}).
lean().
then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).
@@ -2340,7 +2342,8 @@ UserSchema.statics.getFieldsForSearch = function() {
{field: 'profile.revolut', type: tools.FieldType.string},
{field: 'profile.link_payment', type: tools.FieldType.string},
{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}
};

View File

@@ -88,6 +88,12 @@ const shared_consts = require('../tools/shared_nodejs');
const globalTables = require('../tools/globalTables');
const UserCost = {
FIELDS_UPDATE_TELEGRAM_BOT: [
'profile.teleg_id',
'profile.manage_telegram',
'deleted',
],
FIELDS_REQUISITI: [
'verified_email',
'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 (shared_consts.KEY_TO_CRYPTED.includes(fieldsvalue.key)) {

View File

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

View File

@@ -1,9 +1,9 @@
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_DEVELOP = [tools.ISP];
const appTelegram_TEST = [tools.FREEPLANET, tools.PDNM, tools.RISO];
const appTelegram_DEVELOP = [tools.RISO];
const appTelegramFinti = ['2', tools.CNM];
const appTelegramDest = [tools.FREEPLANET, tools.FREEPLANET];
@@ -245,6 +245,7 @@ const Menu = {
EXIT_TELEGRAM: 'exittotelegram',
MSG_TO_USER: 'sendmsgto',
ADMIN: emoji.get('information_desk_person') + ' Admin',
AIUTO: '🔮 Help',
ALTRO: emoji.get('newspaper') + ' Altro',
SETPICPROFILE: '🖼 SetPicProfile',
// 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' +
'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.',
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_EXIT_TELEGRAM: 'L\'account è stato ora scollegato da questo Telegram BOT.',
MSG_APORTADOR_USER_REGISTERED: emo.FIRE +
@@ -1431,10 +1433,6 @@ class Telegram {
this.bot = bot;
this.token = bot.token;
this.arrUsers = [];
this.pagenow = 1;
this.pageChange = false;
this.menuDb = null;
this.menuSaved = {};
this.lastid = 0;
//++
}
@@ -1598,7 +1596,7 @@ class Telegram {
await User.setUsernameTelegram(this.idapp, rec.user._id,
msg.from.username || '', msg.from.first_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')));
} else {
if (!rec.user.profile.username_telegram) {
@@ -1610,7 +1608,7 @@ class Telegram {
if (risp === '') {
if (menusite) {
risp = this.getValueMenu(this.idapp, rec, msg, testo, lang);
risp = await this.getValueMenu(this.idapp, rec, msg, testo, lang);
noanswer = true;
} else if (MsgBot.CIAO.includes(testo.replace('!', ''))) {
risp = 'Ciao ';
@@ -1784,10 +1782,10 @@ class Telegram {
// }
}
if (risp !== '') {
if (risp !== '' && risp !== shared_consts.RIS_OK) {
rec.numdomande++;
if (!noanswer) {
await tools.snooze(600);
await tools.snooze(500);
risp = '[BOT' + emo.ROBOT_FACE + ' scrive]:\n' + risp;
}
this._inviaMsg(id, risp, keyboard);
@@ -1887,6 +1885,8 @@ class Telegram {
await this.menuExitToTelegram(msg);
} else if (testo === Menu.ADMIN) {
await this.menuAdmin(msg);
} else if (testo === Menu.AIUTO) {
await this.menuAiuto(msg);
} else if (testo === Menu.LANG) {
await this.menuLang(msg);
} else if (testo === Menu.MSGATUTTI) {
@@ -2246,6 +2246,10 @@ class Telegram {
await this.sendMsg(msg.chat.id, mystr);
}
async menuAiuto(msg) {
const mystr = this.getstrChatHelp();
await this.sendMsg(msg.chat.id, mystr);
}
async menuAdmin(msg) {
const mystr = tools.get__('SCEGLI_VOCE', this.getlang(msg));
await
@@ -2557,14 +2561,15 @@ class Telegram {
// let ris = await this.getUser(msg, rec, false);
rec.status = Status.VERIFIED;
rec.datemenu_updated = null;
rec.menuDb = null;
await User.SetTelegramIdSuccess(this.idapp, user._id,
msg.from.id).then((recuser) => {
if (recuser) {
this.setPhotoProfile(rec, msg);
let username = recuser.name;
this.sendMsg(msg.from.id,
printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username,
tools.getHostByIdApp(this.idapp)));
printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), username, tools.getHostByIdApp(this.idapp)));
this.checkIfUsernameTelegramSet(msg, recuser);
// 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) {
textdainviare = this.convertSpecialTags(utente, textdainviare);
if (destin === Destin.A_UTENTE) {
await this.sistemaRecDest(rec, msg);
await this.sendMsg(utente.profile.teleg_id,
@@ -3020,6 +3027,7 @@ class Telegram {
updateMenuBot() {
for (let rec of this.arrUsers) {
rec.menuDb = null;
rec.datemenu_updated = null;
}
}
@@ -3054,6 +3062,10 @@ class Telegram {
msg_wait: false,
lastmenu: null,
datemenu_updated: null,
pageChange: false,
menuSaved: {},
pagenow: 1,
menuDb: null,
};
this.arrUsers.push(rec);
@@ -3068,6 +3080,10 @@ class Telegram {
}
menuisVisible(idapp, menu) {
}
async loadMenuFromDb(idapp, id) {
try {
let load = false;
@@ -3079,10 +3095,12 @@ class Telegram {
load = true;
}
if (check) {
if (!(this.menuSaved[idapp]))
load = true;
if (recuser) {
if (!(recuser.menuSaved[idapp]))
load = true;
}
}
if (load || !this.menuDb || this.pageChange) {
if (load || !recuser.menuDb || recuser.pageChange) {
// Check if you are Admin
const user = await User.UserByIdTelegram(idapp, id);
@@ -3092,7 +3110,7 @@ class Telegram {
const isVerified = user ? user.profile.teleg_id > 0 &&
user.verified_by_aportador : false;
this.menuDb = await MyBot.findAllIdApp(idapp);
recuser.menuDb = await MyBot.findAllIdApp(idapp);
let arrlang = {};
@@ -3100,16 +3118,12 @@ class Telegram {
let arrtemp = [];
let lang = '';
for (const rec of this.menuDb) {
for (const rec of recuser.menuDb) {
rec.active_mem = false;
if (rec.active && rec.page === this.pagenow
&& ((isAdmin && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_ADMIN))
|| (isManager && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLY_MANAGER))
|| (isVerified && tools.isBitActive(rec.visibility,
shared_consts.VISIB_ONLYIF_VERIFIED))
|| (rec.visibility === 0))
if (rec.active && rec.page === recuser.pagenow
&& (tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_ADMIN, isAdmin) &&
tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLY_MANAGER, isManager) &&
tools.isBitAttivoESelez(rec.visibility, shared_consts.VISIB_ONLYIF_VERIFIED, isVerified))
) {
rec.active_mem = true;
if (rec.main) {
@@ -3137,10 +3151,10 @@ class Telegram {
if (recuser)
recuser.datemenu_updated = new Date();
this.pageChange = false;
this.menuSaved[idapp] = arrlang;
recuser.pageChange = false;
recuser.menuSaved[idapp] = arrlang;
}
return this.menuSaved[idapp];
return recuser.menuSaved[idapp];
} catch (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.idapp === idapp && rec.lang === lang &&
rec.label.toLowerCase() === testo) {
@@ -3170,30 +3184,33 @@ class Telegram {
return false;
}
getValueMenu(idapp, rec, msg, testo, lang) {
async getValueMenu(idapp, recuser, msg, testo, lang) {
try {
for (const recdb of this.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)) {
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 '';
}
}
if (recuser) {
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) {
return '';
}
return '';
}
async getKeyboard(id, menu, lang) {
@@ -3380,7 +3397,9 @@ class Telegram {
const idapp = this.idapp;
const bot = this.bot;
const username = rec.user.username;
const lang = rec.user.lang;
const token = this.token;
const editprofile = tools.getHostByIdApp(idapp, true) + '/editprofile';
let myfileprofile = tools.getdirByIdApp(idapp, true) +
server_constants.DIR_UPLOAD + '/profile/' + username +'/';
let user_profile = bot.getUserProfilePhotos(msg.from.id);
@@ -3391,16 +3410,21 @@ class Telegram {
file.then(function(result) {
const file_path = result.file_path;
const photo_url = 'https://api.telegram.org/file/bot' + token +
'/' + file_path;
let filename = tools.extractFileName(photo_url)
const photo_url = 'https://api.telegram.org/file/bot' + token + '/' + file_path;
console.log('photo_url', photo_url);
let filename = tools.extractFileName(photo_url);
myfileprofile += filename;
tools.downloadImage(photo_url, myfileprofile).
console.log('myfileprofile', myfileprofile);
return tools.downloadImage(photo_url, myfileprofile).
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');
});
// bot.sendMessage(chatId, photo_url);
});
}
});

View File

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

View File

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