fix ajuda

Signed-off-by: Rodrigo B. de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
rodrigo committed 2025-08-08 10:30:47 -03:00
1 parent d0d99063e2
commit 25827aa049
4 files changed
+464 -27

No files matched your search

+131 -26
View File
@@ -37,7 +37,14 @@ class BotHandler {
// Verificar autorização
if (!this.isAuthorized(userId)) {
await this.bot.sendMessage(chatId, '❌ Você não tem permissão para usar este bot.');
await this.bot.sendMessage(chatId,
`🚫 **Acesso Negado**\n\n` +
`❌ Você não tem permissão para usar este bot.\n` +
`🆔 Seu ID: \`${userId}\`\n\n` +
`📞 Entre em contato com o administrador para solicitar acesso.`,
{ parse_mode: 'Markdown' }
);
console.log(`🚫 Acesso negado para usuário ${msg.from.first_name} (${userId})`);
return;
}
@@ -114,6 +121,20 @@ class BotHandler {
await this.handleListUsers(chatId, target);
break;
case 'admin':
case 'administracao':
await this.handleAdmin(chatId);
break;
case 'usuarios_autorizados':
await this.handleListAuthorizedUsers(chatId);
break;
case 'meu_id':
case 'meu_user_id':
await this.handleMyId(chatId, userId);
break;
case 'ver_sinal':
console.log(`🔍 Executando handleVerSinal com target: ${target}`);
await this.handleVerSinal(chatId, target);
@@ -169,7 +190,7 @@ class BotHandler {
const welcomeMessage = `
🤖 *Bem-vindo ao Bot de Ajuda!*
Olá ${user.first_name}! Eu sou um bot multifuncional que pode te ajudar com:
Olá ${user.first_name}! Agora você não precisa mandar mensagem pro Rodrigo ou no grupo da ID pra ficar vendo coisas triviais:
🔐 *Conexões SSH* - Acesso remoto a equipamentos
🌐 *Status de rede* - Verificação de conectividade
@@ -191,59 +212,58 @@ Digite /help para ver todos os comandos disponíveis!
* Comando /help
*/
async handleHelp(chatId) {
const helpMessage = `
📋 *Comandos Disponíveis:*
const helpMessage = `📋 COMANDOS DISPONÍVEIS:
*Comandos básicos:*
🔧 COMANDOS BÁSICOS:
/start - Inicia o bot
/help - Mostra esta ajuda
/equipamentos - Lista equipamentos
*SSH e Conexões:*
🔐 SSH E CONEXÕES:
/ssh <equipamento> - Conecta via SSH
• "ssh juniper"
• "acessar concentrador"
*Juniper - Gerenciar Usuários:*
👥 JUNIPER - GERENCIAR USUÁRIOS:
• "desconectar cliente USUARIO"
• "kick usuário USUARIO"
• "remover cliente USUARIO"
• "listar usuários conectados"
*OLT - Verificar Sinal de ONU:*
📡 OLT - VERIFICAR SINAL DE ONU:
• "ver sinal DACM91569513"
• "verificar sinal ABCD12345678"
• "sinal SERIAL_NUMBER"
*OLT - Adicionar ONU:*
➕ OLT - ADICIONAR ONU:
• "adicionar onu DACM91569513"
• "cadastrar ABCD12345678"
• "add onu SERIAL_NUMBER"
*OLT - Remover ONU:*
🗑️ OLT - REMOVER ONU:
• "remover onu DACM91569513"
• "deletar ABCD12345678"
• "remover SERIAL_NUMBER"
*OLT - Reiniciar ONU:*
🔄 OLT - REINICIAR ONU:
• Após verificar o sinal, use o botão "🔌 Reiniciar ONU"
• Comando confirma antes de reiniciar
• Processo automático com confirmação
*OLT - Atualizar Firmware ONU:*
⬆️ OLT - ATUALIZAR FIRMWARE ONU:
• Após verificar o sinal, use o botão "⬆️ Atualizar ONU"
• Detecta automaticamente o modelo (DM986-100/DM986-414)
• Oferece opções de firmware específicas para cada modelo
• Processo seguro com confirmação
*Status e Monitoramento:*
📊 STATUS E MONITORAMENTO:
/status <equipamento> - Verifica status
• "verificar concentrador"
• "status do juniper"
*Linguagem Natural:*
🗣️ LINGUAGEM NATURAL:
• "Conectar no concentrador"
• "Desconectar cliente joao123"
• "Desconectar cliente joao123"
• "Ver sinal DACM91569513"
• "Adicionar onu DACM91569513"
• "Remover onu DACM91569513"
@@ -251,24 +271,32 @@ Digite /help para ver todos os comandos disponíveis!
• "Reiniciar juniper"
• "Ping 131.0.192.254"
*Exemplos Práticos:*
✅ "desconectar cliente user123"
✅ "ver sinal DACM91569513"
✅ "adicionar onu DACM91569513"
✅ "remover onu DACM91569513"
✅ "listar clientes conectados"
✅ "verificar status concentrador"
✅ EXEMPLOS PRÁTICOS:
• "desconectar cliente user123"
• "ver sinal DACM91569513"
• "adicionar onu DACM91569513"
• "remover onu DACM91569513"
• "listar clientes conectados"
• "verificar status concentrador"
*OLTs Disponíveis:*
🏢 OLTs DISPONÍVEIS:
• OLT DITO (192.168.190.7)
• OLT COLMEIA (192.168.190.8)
• OLT CANAA (192.168.190.9)
• OLT CANAA 2 (192.168.190.10)
• OLT PEDRO AFONSO 1 (192.168.100.2)
• OLT CANAVIEIRAS (192.168.100.4)
`;
🛡️ COMANDOS ADMINISTRATIVOS:
• "admin" - Painel administrativo
• "usuarios autorizados" - Ver usuários com acesso
• "meu id" - Ver seu ID do Telegram
🔒 SEGURANÇA:
🛡️ Bot restrito a usuários autorizados
🆔 Para solicitar acesso, forneça seu ID`;
await this.bot.sendMessage(chatId, helpMessage, { parse_mode: 'Markdown' });
await this.bot.sendMessage(chatId, helpMessage);
}
/**
@@ -762,7 +790,8 @@ Digite /help para ver todos os comandos disponíveis!
// Verificar autorização
if (!this.isAuthorized(userId)) {
await this.bot.answerCallbackQuery(callbackQuery.id, 'Sem permissão');
await this.bot.answerCallbackQuery(callbackQuery.id, '🚫 Acesso negado');
console.log(`🚫 Callback negado para usuário (${userId})`);
return;
}
@@ -1935,6 +1964,82 @@ Digite /help para ver todos os comandos disponíveis!
);
}
}
/**
* Painel administrativo
*/
async handleAdmin(chatId) {
const userId = chatId; // Para chats individuais, chatId = userId
// Verificar se é usuário autorizado
if (!this.isAuthorized(userId)) {
await this.bot.sendMessage(chatId, '🚫 Acesso negado ao painel administrativo.');
return;
}
await this.bot.sendMessage(chatId,
`🛡️ **Painel Administrativo**\n\n` +
`👥 **Gestão de Usuários:**\n` +
`• \`usuarios autorizados\` - Ver lista de usuários\n` +
`• \`meu id\` - Ver seu ID do Telegram\n\n` +
`📊 **Sistema:**\n` +
`• \`status\` - Status do bot\n` +
`• \`equipamentos\` - Lista de equipamentos\n\n` +
`🔧 **Comandos disponíveis:**\n` +
`• Ver sinal, adicionar ONU, remover ONU\n` +
`• Resetar ONU, atualizar firmware\n` +
`• Gerenciar usuários Juniper`,
{ parse_mode: 'Markdown' }
);
}
/**
* Listar usuários autorizados
*/
async handleListAuthorizedUsers(chatId) {
const userId = chatId;
if (!this.isAuthorized(userId)) {
await this.bot.sendMessage(chatId, '🚫 Acesso negado.');
return;
}
const authorizedUsers = config.bot.allowedUsers;
if (authorizedUsers.length === 0) {
await this.bot.sendMessage(chatId,
`👥 **Usuários Autorizados**\n\n` +
`⚠️ Nenhuma restrição configurada\n` +
`🌐 Bot está aberto para todos os usuários\n\n` +
`💡 Configure ALLOWED_USERS no .env para restringir`
);
} else {
const userList = authorizedUsers.map((id, index) =>
`${index + 1}. ID: \`${id}\``
).join('\n');
await this.bot.sendMessage(chatId,
`👥 **Usuários Autorizados**\n\n` +
`📊 Total: ${authorizedUsers.length} usuário(s)\n\n` +
`${userList}\n\n` +
`🆔 Seu ID: \`${userId}\``,
{ parse_mode: 'Markdown' }
);
}
}
/**
* Exibir ID do usuário
*/
async handleMyId(chatId, userId) {
await this.bot.sendMessage(chatId,
`🆔 **Sua Identificação**\n\n` +
`👤 User ID: \`${userId}\`\n` +
`💬 Chat ID: \`${chatId}\`\n\n` +
`📋 Use estes IDs para configurar permissões`,
{ parse_mode: 'Markdown' }
);
}
}
module.exports = BotHandler;