SubAccounts

This commit is contained in:
Paolo Arena
2020-05-10 21:07:51 +02:00
parent 7d0538f7ae
commit ae77637d33
17 changed files with 1535 additions and 499 deletions

View File

@@ -492,29 +492,33 @@ module.exports = {
},
sendMsgTelegramToTheManagers: async function (idapp, text) {
const usersmanagers = await User.getusersManagers(idapp);
// console.log('usersmanagers', usersmanagers);
sendMsgTelegramToTheManagers: async function (idapp, text, onlyintofile) {
tools.writeManagersLog(text);
if (usersmanagers) {
for (const rec of usersmanagers) {
await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, emo.ROBOT_FACE + '[BOT-STAFF]' + emo.ADMIN + ': ' + text, undefined, undefined, true);
await tools.snooze(300)
if (!onlyintofile) {
const usersmanagers = await User.getusersManagers(idapp);
if (usersmanagers) {
for (const rec of usersmanagers) {
await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, emo.ROBOT_FACE + '[BOT-STAFF]' + emo.ADMIN + ': ' + text, undefined, undefined, true);
await tools.snooze(300)
}
}
}
return true
},
getMsgByTipoMsg: function (mydata, lang, user) {
getMsgByTipoMsg: function (mydata, lang, user, sonosognatore) {
if (!!mydata.msgextra) {
return mydata.msgextra;
}
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
return printf(tools.gettranslate('SEND_LINK_CHAT_DONATORI', lang), user.name, mydata.msgpar1);
if (sonosognatore)
return printf(tools.gettranslate('SEND_LINK_CHAT_SOGNATORE', lang), user.name, mydata.navemediatore.riga + '.' + mydata.navemediatore.col, mydata.msgpar1);
else
return printf(tools.gettranslate('SEND_LINK_CHAT_DONATORI', lang), user.name, mydata.navemediatore.riga + '.' + mydata.navemediatore.col, mydata.msgpar1);
} else if (mydata.tipomsg === tools.TipoMsg.SEND_MSG || mydata.tipomsg === tools.TipoMsg.SEND_MSG_SINGOLO) {
let mymsg = '';
if (!!mydata.username_mitt) {
@@ -533,19 +537,17 @@ module.exports = {
try {
const arrnavi = await Nave.getusersByNave(idapp, mydata.navemediatore);
// console.log('usersmanagers', usersmanagers);
tools.writeManagersLog('sendMsgTelegramToNave');
if (arrnavi) {
tools.writeManagersLog('sendMsgTelegramToNave', mydata.navemediatore.riga + '.' + mydata.navemediatore.col);
for (const nave of arrnavi) {
const user = await User.findByIndOrder(idapp, nave.ind_order);
if (!!user) {
const lang = user.lang;
const idteleg = user.profile.teleg_id;
const mymsg = this.getMsgByTipoMsg(mydata, lang, user);
const mymsg = this.getMsgByTipoMsg(mydata, lang, user, false);
if (!!idteleg) {
strout += '\n' + user.name + ' ' + user.surname + ':';
@@ -568,6 +570,31 @@ module.exports = {
}
}
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
const usersognatore = await Nave.getSognatoreByRigaColMediatore(idapp, mydata.navemediatore);
console.log('Sognatore: ', usersognatore.username);
if (!!usersognatore) {
const lang = usersognatore.lang;
const idteleg = usersognatore.profile.teleg_id;
const mymsg = this.getMsgByTipoMsg(mydata, lang, usersognatore, true);
// Invia Msg al Sognatore !
if (mydata.inviareale) {
await this.sendMsgTelegramByIdTelegram(idapp, idteleg, mymsg, undefined, undefined, true);
await tools.snooze(300);
nummsgsent++;
strout += '\n' + usersognatore.name + ' ' + usersognatore.surname + ':';
strout += ' -> MSG INVIATO';
} else {
strout += ' (Pronto da Inviare)';
}
}
}
if (nummsgsent > 0) {
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
const fields_to_update = {
@@ -887,8 +914,12 @@ class Telegram {
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 + '\nLang: ' + rec.user.lang;
const myrec = await User.getUserShortDataByUsername(this.idapp, rec.user.username);
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 + '\nLang: ' + rec.user.lang + tools.ACAPO;
risp += 'Num Invitati: ' + myrec.numinvitati + tools.ACAPO;
risp += 'Num Invitati Attivi: ' + myrec.numinvitatiattivi + tools.ACAPO;
} else {
risp = 'Ancora non ti sei Attivato su AYNI BOT';
}
@@ -965,6 +996,7 @@ class Telegram {
if (contastiera) {
keyboard = {
"parse_mode": "HTML",
"reply_markup": {
"resize_keyboard": true,
"keyboard": await this.getKeyboard(id, undefined, this.getlang(msg))
@@ -1209,7 +1241,7 @@ class Telegram {
tuttie9 = dashboard.myself.qualified && (numpersone >= 2) && invitati_attivi >= 2;
mystrnave = await Nave.getNaveByUser(this.idapp, user.ind_order, user.lang, true);
mystrnave = await Nave.getNaveByUser(this.idapp, user.username, user.lang, true);
if (mystrnave === '' && tuttie9) {
mystr += tools.gettranslate('NO_PROG', user.lang);
@@ -1305,7 +1337,7 @@ class Telegram {
if (!rec.user)
return "";
let ind_order_to_check = rec.user.ind_order;
let username_to_check = rec.user.username;
let arrstringa = msg.text.split(" ");
if (!!arrstringa) {
@@ -1317,7 +1349,7 @@ class Telegram {
}
}
mystr = await Nave.getNaveByUser(this.idapp, ind_order_to_check, rec.user.lang, true);
mystr = await Nave.getNaveByUser(this.idapp, username_to_check, rec.user.lang, true);
if (!!mystr)
await this.sendMsg(msg.chat.id, mystr);
@@ -1484,9 +1516,46 @@ class Telegram {
}
}
getlink(qualelink) {
if (qualelink === 'website') {
return 'https://ayni.gifteconomy.app'
} else if (qualelink === 'biblio') {
return 'https://t.me/joinchat/AAAAAFMDe8b5lB1X7vOYng';
} else if (qualelink === 'help') {
return 'https://t.me/joinchat/AL2qKE80rxDkgbeMGO-0bw';
} else if (qualelink === 'faq') {
return 'https://ayni.gifteconomy.app/faq';
} else if (qualelink === 'empower') {
return "ITA 🇮🇹: https://t.me/joinchat/C741mkx5QYXu-kyYCYvA8g" + tools.ACAPO +
"SLO 🇸🇮: https://t.me/aynislovenija" + tools.ACAPO +
"ESP 🇪🇸 - PRT 🇵🇹: https://t.me/joinchat/AL2qKBqJRuIEuc2FivgAzg" + tools.ACAPO +
"ENG 🇬🇧: https://t.me/joinchat/AL2qKBYX0yVvOJ6Ssf9hKg" + tools.ACAPO +
"FRA 🇫🇷: https://t.me/joinchat/Kz0wtxieJjzoC3L_DsrdZw";
}
}
async menuAssistenza(msg) {
const mytext = tools.get__('TESTO_ASSISTENZA', this.getlang(msg));
const sito = this.getlink('website');
const empower = this.getlink('empower');
const biblio = this.getlink('biblio');
const faq = this.getlink('faq');
let help = "";
let helpaperta = true;
if (tools.isMonToSat() && tools.isBetweenTwoTime('8:00:00', '19:50:00')) {
help = '✅ ' + this.getlink('help');
} else {
help = "🔴 [ORA CHIUSA - NOW CLOSED]";
helpaperta = false;
}
let mytext = "";
if (this.getlang(msg) === 'it')
mytext = printf(tools.get__('TESTO_ASSISTENZA', this.getlang(msg)), sito, empower, biblio, faq, help);
else
mytext = printf(tools.get__('TESTO_ASSISTENZA', this.getlang(msg)), sito, empower, biblio, help);
let menu = null;
const rec = this.getRecInMem(msg);
@@ -1544,8 +1613,8 @@ class Telegram {
if (conmsg) {
await this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERRORE_USERNAME_NOT_FOUND'), MenuNoLogin);
const lang = this.getlang(msg);
const textman = msg.chat.first_name + ' ' + msg.chat.last_name + ' sta tentando di autenticarsi con il BOT (lang=' + lang + ') (username che scrive: ' + msg.text + ') ';
await local_sendMsgTelegramToTheManagers(this.idapp, textman, msg);
// const textman = msg.chat.first_name + ' ' + msg.chat.last_name + ' sta tentando di autenticarsi con il BOT (lang=' + lang + ') (username che scrive: ' + msg.text + ') ';
// await local_sendMsgTelegramToTheManagers(this.idapp, textman, msg);
rec.username_bo = '';
}
} else {
@@ -1615,7 +1684,7 @@ class Telegram {
if (recuser) {
let name = recuser.name;
this.sendMsg(msg.from.id, printf(getstr(recuser.lang, 'MSG_VERIFY_OK'), name));
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);
} else {
this.sendMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_ERR_UNKNOWN_VERIFY_CODE'));
}
@@ -1724,8 +1793,8 @@ class Telegram {
} else if (destin === Destin.MSG_TO_NAVE) {
invia = !await Nave.findDonatoreByNave(this.idapp, rec.extraparam);
} else if (destin === Destin.SI_INVITATI_NO_7REQ_INVITATI) {
const numinvitati = await User.getnumInvitati(this.idapp, utente.username);
const numinvitatiattivi = await User.getnumInvitatiAttivi(this.idapp, utente.username);
const numinvitati = await ListaIngresso.getnumInvitati(this.idapp, utente.username);
const numinvitatiattivi = await ListaIngresso.getnumInvitatiAttivi(this.idapp, utente.username);
invia = (numinvitati >= 2) && (numinvitatiattivi < 2);
}
if (invia) {
@@ -2021,6 +2090,7 @@ class Telegram {
try {
if (!form) {
form = {
"parse_mode": "HTML",
"message_id": msg_id,
"reply_markup": {
"resize_keyboard": true,
@@ -2116,6 +2186,7 @@ class Telegram {
async msgScegliMenu(msg) {
// const rec = this.getRecInMem(msg);
this._inviaMsg(msg.from.id, getstr(this.getlang(msg), 'MSG_SCEGLI_MENU'), {
"parse_mode": "HTML",
"reply_markup": {
"resize_keyboard": true,
"keyboard": await this.getKeyboard(msg.from.id, undefined, this.getlang(msg))