Corretto le richieste di amicizie, aggiunto Accettazione sul BOT
This commit is contained in:
@@ -668,6 +668,8 @@ UserSchema.statics.getUserShortDataByUsername = async function(idapp, username)
|
||||
verified_by_aportador: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.firstname_telegram': 1,
|
||||
'profile.lastname_telegram': 1,
|
||||
// 'profile.saw_zoom_presentation': 1,
|
||||
'profile.ask_zoom_partecipato': 1,
|
||||
'profile.qualified': 1,
|
||||
@@ -1347,6 +1349,8 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
'profile.biografia': 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.firstname_telegram': 1,
|
||||
'profile.lastname_telegram': 1,
|
||||
'profile.intcode_cell': 1,
|
||||
'profile.cell': 1,
|
||||
'profile.website': 1,
|
||||
@@ -1378,6 +1382,8 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
||||
'profile.biografia': 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.firstname_telegram': 1,
|
||||
'profile.lastname_telegram': 1,
|
||||
'profile.intcode_cell': 1,
|
||||
'profile.cell': 1,
|
||||
'profile.website': 1,
|
||||
@@ -1544,7 +1550,7 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
'profile.friends': {
|
||||
$elemMatch: {username: {$eq: usernameDest}},
|
||||
},
|
||||
});
|
||||
}, {_id: 1}).lean();
|
||||
|
||||
if (!foundIfAlreadyFriend) {
|
||||
update = {
|
||||
@@ -1568,7 +1574,7 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
'profile.friends': {
|
||||
$elemMatch: {username: {$eq: usernameOrig}},
|
||||
},
|
||||
});
|
||||
}, {_id: 1}).lean();
|
||||
|
||||
if (!foundIfAlreadyFriend2) {
|
||||
update = {
|
||||
@@ -1582,10 +1588,11 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
ris = await User.updateOne({idapp, username: usernameDest}, update);
|
||||
|
||||
this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da me
|
||||
this.removeReqFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da te
|
||||
}
|
||||
if (ris) {
|
||||
//if (ris) {
|
||||
ris = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
}
|
||||
//}
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) {
|
||||
// Aggiungo la richiesta di Amicizia a me
|
||||
const foundIfAlreadyAskFriend = await User.findOne({
|
||||
@@ -1594,7 +1601,7 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
'profile.req_friends': {
|
||||
$elemMatch: {username: {$eq: usernameOrig}},
|
||||
},
|
||||
});
|
||||
}, {_id: 1}).lean();
|
||||
|
||||
if (value) {
|
||||
if (!foundIfAlreadyAskFriend) {
|
||||
@@ -1610,21 +1617,24 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
}
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona
|
||||
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true,
|
||||
usernameOrig);
|
||||
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
|
||||
}
|
||||
} else {
|
||||
if (foundIfAlreadyAskFriend) {
|
||||
ris = await this.removeFriend(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da me
|
||||
ris = await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da me
|
||||
}
|
||||
}
|
||||
|
||||
if (ris) {
|
||||
// if (ris) {
|
||||
ris = await User.getInfoAskFriendByUsername(idapp, usernameDest);
|
||||
}
|
||||
// }
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS) {
|
||||
|
||||
// Rimuovi anche le eventuali richieste di Amicizia !
|
||||
await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
await this.removeReqFriend(idapp, usernameOrig, usernameDest); // Rimuovo la Richiesta di Amicizia da me
|
||||
|
||||
await this.removeFriend(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da lui
|
||||
ris = await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
@@ -1635,6 +1645,9 @@ UserSchema.statics.setFriendsCmd = async function(idapp, usernameOrig, usernameD
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.BLOCK_USER) {
|
||||
|
||||
await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui
|
||||
await this.removeReqFriend(idapp, usernameOrig, usernameDest); // Rimuovo la Richiesta di Amicizia da me
|
||||
|
||||
await this.removeFriend(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da lui
|
||||
await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me
|
||||
|
||||
@@ -1784,6 +1797,8 @@ function getWhatToShow(idapp, username) {
|
||||
'profile.qualifica': 1,
|
||||
'profile.biografia': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.firstname_telegram': 1,
|
||||
'profile.lastname_telegram': 1,
|
||||
'profile.intcode_cell': 1,
|
||||
'profile.cell': 1,
|
||||
'profile.website': 1,
|
||||
|
||||
@@ -131,7 +131,7 @@ MsgBot = {
|
||||
HAHA: ['hahaha', 'ahah', '😂'],
|
||||
MI_AMI: ['mi ami'],
|
||||
TI_AMO: ['ti amo', 'ti adoro', 'ti lovvo'],
|
||||
PREGO: [ 'prego', 'Prego ! 💋💋💋'],
|
||||
PREGO: ['prego', 'Prego ! 💋💋💋'],
|
||||
GRAZIE: [
|
||||
'grazie ainy',
|
||||
'grazie',
|
||||
@@ -486,14 +486,14 @@ const txt = {
|
||||
' Si è appena Registrato "%s" (n. %s)\nInvitato da %s',
|
||||
MSG_APORTADOR_ASK_CONFIRM: '🆕💥 🧍♂️ Abilita Nuova Registrazione:',
|
||||
MSG_ACCEPT_NEWENTRY_INGROUP: '❇️👥 🧍♂️ Accetta Ingresso nel GRUPPO %s:',
|
||||
MSG_FRIENDS_ACCEPTED: '✅ %s ha accettato la tua richiesta di Amicizia !',
|
||||
MSG_FRIENDS_ACCEPTED_CONFIRMED: '✅ Hai accettato la richiesta di Amicizia di %s !',
|
||||
MSG_APORTADOR_CONFIRMED: '✅ %s è stato Abilitato correttamente (da %s)!',
|
||||
MSG_APORTADOR_DEST_CONFIRMED: '✅ Sei stato Abilitato correttamente da %s!\n' +
|
||||
'Vai sulla App oppure clicca qui per entrare\n👉🏻 %s',
|
||||
MSG_GROUP_CONFIRMED: '✅ Sei stato Aggiunto sul Gruppo %s!',
|
||||
MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK +
|
||||
'🚫 Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s.<br>Contattalo per farti abilitare !',
|
||||
MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK +
|
||||
'🚫 %s Non è stato Abilitato !',
|
||||
MSG_APORTADOR_DEST_NOT_CONFIRMED: emo.EXCLAMATION_MARK + '🚫 Ci dispiace ma non sei stato Verificato correttamente dal tuo invitante %s.<br>Contattalo per farti abilitare !',
|
||||
MSG_APORTADOR_NOT_CONFIRMED: emo.EXCLAMATION_MARK + '🚫 %s Non è stato Abilitato !',
|
||||
MSG_ISCRITTO_CONACREIS: emo.FIRE + ' Si è appena Iscritto al Conacreis "%s"',
|
||||
MSG_MSG_SENT: emoji.get('envelope') + ' Messaggi Inviati !',
|
||||
MSG_MSG_TOSENT: emoji.get('envelope') + ' Messaggi da Inviare',
|
||||
@@ -862,6 +862,47 @@ const MyTelegramBot = {
|
||||
|
||||
},
|
||||
|
||||
askConfirmationUserFriend: async function(idapp, myfunc, myuser, userDest = '', username = '') {
|
||||
|
||||
try {
|
||||
const cl = getclTelegByidapp(idapp);
|
||||
|
||||
const langdest = myuser.lang;
|
||||
const telegid = myuser.profile.teleg_id;
|
||||
|
||||
let keyb = null;
|
||||
let domanda = '';
|
||||
|
||||
const struserinfomsg = tools.getUserInfoMsg(idapp, myuser);
|
||||
|
||||
if (myfunc === shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
||||
|
||||
domanda = printf(tools.gettranslate('RICHIESTA_AMICIZIA', langdest), userDest) + '<br>' + struserinfomsg;
|
||||
|
||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||
{
|
||||
text: '✅👤 Accetta Amicizia',
|
||||
callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + userDest + tools.SEP + '',
|
||||
},
|
||||
{
|
||||
text: '🚫👤 Rifiuta Amicizia',
|
||||
callback_data: InlineConferma.RISPOSTA_NO + myfunc + tools.SEP + myuser.username + tools.SEP + userDest + tools.SEP + '',
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (domanda) {
|
||||
const teleg_id = await User.TelegIdByUsername(idapp, userDest);
|
||||
await this.local_sendMsgTelegramByIdTelegram(idapp, teleg_id, domanda, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error askConfirmationUser', e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
sendMsgTelegramToTheManagers: async function(
|
||||
idapp, text, onlyintofile = false, MyForm = null, nottousername = '') {
|
||||
|
||||
@@ -1556,7 +1597,7 @@ class Telegram {
|
||||
} else if (testo.length >= 10) {
|
||||
noanswer = true;
|
||||
let myfaq = this.geturlfaq();
|
||||
risp = 'Io sono solo un Robot ' + emo.ROBOT_FACE + emo.JOY2 +
|
||||
risp = 'Ciao {username}, Io mi chiamo BOT e sono il tuo assistente Virtuale ' + emo.ROBOT_FACE + emo.JOY2 + '\n';
|
||||
'Usa il menu qui sotto per interagire col BOT\n' +
|
||||
'\n\nPer AIUTO, clicca qui:\n👉🏻👉🏻<a href="' + myfaq +
|
||||
'">FAQ di AIUTO</a> (risposte alle domande più frequenti)\n\nSe non trovi risposta allora contatta la Chat HELP.\nGrazie';
|
||||
@@ -2353,7 +2394,7 @@ class Telegram {
|
||||
const msg = await MsgTemplate.getMsgByTitleAndLang(myuser.idapp, title, myuser.lang);
|
||||
const mytext = tools.convertSpecialTags(myuser, msg.body);
|
||||
return this.sendMsg(myuser.profile.teleg_id, mytext);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('ERR sendMsgByTemplate', e);
|
||||
}
|
||||
}
|
||||
@@ -3140,7 +3181,7 @@ class Telegram {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('textORIG', text);
|
||||
console.log('textORIG', text.substring(0, 100));
|
||||
text = text.replace(/<br>/g, '\n');
|
||||
text = text.replace(/<br\/>/g, '\n');
|
||||
text = text.replace(/<div>/g, '');
|
||||
@@ -3307,11 +3348,10 @@ class Telegram {
|
||||
resize(64, 64).
|
||||
withMetadata().
|
||||
toFile(resized_img_small);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('setPhotoProfile sharp', e);
|
||||
}
|
||||
|
||||
|
||||
// console.log('3) setPicProfile ris', ris);
|
||||
return User.setPicProfile(idapp, username, filename).
|
||||
then((ris) => {
|
||||
@@ -3590,7 +3630,8 @@ if (true) {
|
||||
|
||||
await User.setaportador_solidario(user.idapp, data.username, userDest.username);
|
||||
|
||||
const msgOrig = printf(getstr(userDest.lang, 'MSG_APORTADOR_DEST_CONFIRMED'), `${userDest.username}`, tools.getHostByIdApp(user.idapp));
|
||||
const msgOrig = printf(getstr(userDest.lang, 'MSG_APORTADOR_DEST_CONFIRMED'), `${userDest.username}`,
|
||||
tools.getHostByIdApp(user.idapp));
|
||||
const msgDest = printf(getstr(user.lang, 'MSG_APORTADOR_CONFIRMED'), `${user.username}`, `${userDest.username}`);
|
||||
|
||||
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
||||
@@ -3636,6 +3677,26 @@ if (true) {
|
||||
await User.setGroupsCmd(user.idapp, data.username, group.groupname, cmd);
|
||||
}
|
||||
|
||||
}
|
||||
} else if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_AMICIZIA) {
|
||||
|
||||
if (userDest) {
|
||||
cmd = shared_consts.FRIENDSCMD.SETFRIEND;
|
||||
const foundIfAlreadyFriend = await User.isMyFriend(user.idapp, data.username, data.userDest);
|
||||
|
||||
if (!foundIfAlreadyFriend) {
|
||||
// Aggiungilo nelle Amicizie
|
||||
const ris = await User.setFriendsCmd(user.idapp, data.username, data.userDest, cmd);
|
||||
if (ris) {
|
||||
const msgOrig = printf(getstr(userDest.lang, 'MSG_FRIENDS_ACCEPTED', data.userDest));
|
||||
const msgDest = printf(getstr(user.lang, 'MSG_FRIENDS_ACCEPTED_CONFIRMED'), data.username);
|
||||
|
||||
await local_sendMsgTelegram(user.idapp, data.username, msgOrig);
|
||||
await local_sendMsgTelegram(user.idapp, data.userDest, msgDest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ const textlang = {
|
||||
'NAVE': 'NAVE',
|
||||
'MSG_SEND_FROM': 'Msg Inviato da',
|
||||
'ZOOM_CONFERMATO': 'Sei stato confermato ad aver visto la Video Conferenza di Benvenuto!',
|
||||
'RICHIESTA_AMICIZIA': 'Richiesta d\'Amicizia da parte di %s',
|
||||
'RICHIESTA_AMICIZIA': '🌈 Richiesta d\'Amicizia da parte di %s',
|
||||
'ACCETTATO_SUL_GRUPPO': 'Sei stato accettato da %s a far parte del Gruppo %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': 'l\'utente %s è stato accettato a far parte del Gruppo %s',
|
||||
'RICHIESTA_GRUPPO': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
@@ -831,18 +831,21 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
sendNotificationByUsername: async function(
|
||||
idapp, username, cmd, telegram, usernameOrig) {
|
||||
sendNotificationByUsername: async function(idapp, username, cmd, telegram, usernameOrig) {
|
||||
|
||||
var {User} = require('../models/user');
|
||||
|
||||
const user = await User.findOne({idapp, username}, {_id: 1, lang: 1});
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const user = await User.findOne({idapp, username}, {_id: 1, username:1, lang: 1}).lean();
|
||||
if (!user)
|
||||
return;
|
||||
|
||||
let userId = user._id;
|
||||
let lang = user.lang;
|
||||
|
||||
let sendnotif = true;
|
||||
|
||||
let title = this.getNomeAppByIdApp(idapp);
|
||||
let descr = '';
|
||||
let openUrl = '/';
|
||||
@@ -853,6 +856,13 @@ module.exports = {
|
||||
descr = printf(this.get__('RICHIESTA_AMICIZIA', lang), usernameOrig);
|
||||
openUrl = '/my/' + usernameOrig;
|
||||
tag = 'reqfriends';
|
||||
|
||||
const userrecDest = await User.getUserShortDataByUsername(idapp, usernameOrig);
|
||||
|
||||
if (userrecDest) {
|
||||
sendnotif = false; // non lo rimandare 2 volte !
|
||||
telegrambot.askConfirmationUserFriend(idapp, shared_consts.CallFunz.RICHIESTA_AMICIZIA, userrecDest, username, usernameOrig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,8 +871,7 @@ module.exports = {
|
||||
actions);
|
||||
}
|
||||
|
||||
if (telegram) {
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
if (telegram && sendnotif) {
|
||||
|
||||
const idtelegram = await User.TelegIdByUsername(idapp, username);
|
||||
|
||||
@@ -2736,7 +2745,7 @@ module.exports = {
|
||||
let msg = '';
|
||||
try {
|
||||
const name = myuser.username +
|
||||
(myuser.name ? `(${myuser.name} + ' ' + ${myuser.surname})` : '');
|
||||
(myuser.name ? ` (${myuser.name} ${myuser.surname})` : '');
|
||||
const linkuserprof = this.getHostByIdApp(idapp) + '/my/' +
|
||||
myuser.username;
|
||||
|
||||
@@ -2751,7 +2760,7 @@ module.exports = {
|
||||
: surname_telegram;
|
||||
|
||||
if (u_tg) {
|
||||
msg += '<br>Profilo su Telegram [' + name_tg + ' ' + surname_tg + ']:<br>' + 'https://t.me/' + u_tg;
|
||||
msg += `<br>Profilo su Telegram [${name_tg} ${surname_tg}]:<br>https://t.me/${u_tg}`;
|
||||
}
|
||||
}catch (e) {
|
||||
console.error('getUserInfoMsg', e);
|
||||
|
||||
@@ -225,6 +225,7 @@ module.exports = {
|
||||
ZOOM_GIA_PARTECIPATO: 510,
|
||||
REGISTRATION: 6,
|
||||
RICHIESTA_GRUPPO: 10,
|
||||
RICHIESTA_AMICIZIA: 15,
|
||||
},
|
||||
|
||||
OrderStatus: {
|
||||
|
||||
Reference in New Issue
Block a user