<?php
// Script para verificar los Intents del bot
require_once __DIR__ . '/.env';

if (file_exists(__DIR__ . '/.env')) {
    $lines = file(__DIR__ . '/.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach ($lines as $line) {
        $line = trim($line);
        if ($line === '' || strpos($line, '#') === 0) continue;
        if (strpos($line, '=') === false) continue;
        list($key, $value) = explode('=', $line, 2);
        $_ENV[trim($key)] = trim($value);
    }
}

$token = $_ENV['DISCORD_BOT_TOKEN'] ?? '';
if (empty($token)) {
    die("ERROR: No se encontró DISCORD_BOT_TOKEN en .env\n");
}

// Obtener información de la aplicación
$ch = curl_init('https://discord.com/api/v10/applications/@me');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bot ' . $token,
        'Content-Type: application/json'
    ]
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode !== 200) {
    die("ERROR HTTP $httpCode: $response\n");
}

$app = json_decode($response, true);

echo "=== INFORMACIÓN DE LA APLICACIÓN ===\n";
echo "ID: " . $app['id'] . "\n";
echo "Nombre: " . $app['name'] . "\n";
echo "Owner ID: " . $app['owner']['id'] . "\n\n";

echo "=== PRIVILEGED INTENTS (en el Portal) ===\n";
echo "Por favor, ve al portal y verifica:\n";
echo "https://discord.com/developers/applications/{$app['id']}/bot\n\n";

echo "Debe estar activado:\n";
echo "  ✓ PRESENCE INTENT\n";
echo "  ✓ SERVER MEMBERS INTENT\n";
echo "  ✓ MESSAGE CONTENT INTENT ← **CRÍTICO**\n\n";

echo "=== INTENTS DEL CÓDIGO ===\n";
echo "El bot_daemon.php está solicitando:\n";
echo "  - GUILD_MESSAGES\n";
echo "  - DIRECT_MESSAGES\n";
echo "  - MESSAGE_CONTENT\n";
echo "  - GUILD_MEMBERS\n\n";

echo "Si MESSAGE CONTENT INTENT no está activado en el portal,\n";
echo "Discord BLOQUEARÁ todos los eventos MESSAGE_CREATE.\n";
