- aggiornata la grafica della Home di RISO

- Profilo Completition
- Email Verificata
- Invita un Amico (invio di email)
This commit is contained in:
Surya Paolo
2025-11-15 19:38:55 +01:00
parent 26a42b1f30
commit adf1aac10f
312 changed files with 12061 additions and 81773 deletions

View File

@@ -0,0 +1,70 @@
// telegram/handlers/groupHandler.js
const shared_consts = require('../../tools/shared_nodejs');
const tools = require('../../tools/general');
const { User } = require('../../models/user');
const InlineConferma = { RISPOSTA_SI: 'SI_', RISPOSTA_NO: 'NO_' };
/**
* Gestisce conferma/rifiuto a richieste di GRUPPO
* Payload data:
* - action
* - username (mittente originale)
* - userDest (destinatario/utente da aggiungere)
* - groupId (id o path del gruppo)
* - groupname (nome del gruppo)
*/
async function handleGroup({ bot, cl, idapp, msg, data, user, userDest, username_action }) {
let notifyText = '';
// SI → accetta richiesta d'ingresso nel gruppo
if (data.action === InlineConferma.RISPOSTA_SI + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
// Se lapp ha funzioni di persistenza specifiche, usale se esistono
// (non assumo nomi rigidi per non rompere il deploy)
if (typeof User.setGroupCmd === 'function') {
try {
await User.setGroupCmd(idapp, data.userDest || data.username, data.groupId, shared_consts.GROUPCMD.ADDUSERTOGROUP, 1, username_action, { groupname: data.groupname });
} catch (e) {
console.warn('handleGroup:setGroupCmd non eseguito:', e.message);
}
}
// Messaggi di conferma
await cl.sendMsg(msg.chat.id, `${data.userDest || data.username} è stato aggiunto al gruppo ${data.groupname || data.groupId}.`);
// Notifica anche lutente interessato
const targetUsername = data.userDest || data.username;
const teleg_id = await User.TelegIdByUsername(idapp, targetUsername);
if (teleg_id) {
await cl.sendMsg(teleg_id, `👥 Sei stato aggiunto al gruppo: ${data.groupname || data.groupId}`);
}
notifyText = 'Gruppo: aggiunta OK';
return notifyText;
}
// NO → rifiuta/annulla richiesta
if (data.action === InlineConferma.RISPOSTA_NO + shared_consts.CallFunz.RICHIESTA_GRUPPO) {
if (typeof User.setGroupCmd === 'function') {
try {
await User.setGroupCmd(idapp, data.userDest || data.username, data.groupId, shared_consts.GROUPCMD.REMOVEUSERFROMGROUP, 0, username_action, { groupname: data.groupname });
} catch (e) {
console.warn('handleGroup:setGroupCmd non eseguito:', e.message);
}
}
await cl.sendMsg(msg.chat.id, '🚫 Richiesta gruppo rifiutata.');
// Avvisa il richiedente
const targetUsername = data.userDest || data.username;
const teleg_id = await User.TelegIdByUsername(idapp, targetUsername);
if (teleg_id) {
await cl.sendMsg(teleg_id, `❌ La tua richiesta per il gruppo ${data.groupname || data.groupId} è stata rifiutata.`);
}
notifyText = 'Gruppo: rifiutata';
return notifyText;
}
return 'OK';
}
module.exports = { handleGroup };