Bot Discord - Commit completo con todos los cambios
This commit is contained in:
148
config/config.php
Executable file
148
config/config.php
Executable file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
// config/config.php
|
||||
|
||||
// Cargar variables de entorno
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Verificar si estamos en un contenedor Docker
|
||||
$is_docker = (getenv('DOCKER_CONTAINER') === '1') || ($_SERVER['DOCKER_CONTAINER'] ?? null) === '1';
|
||||
|
||||
if ($is_docker) {
|
||||
// Docker: cargar archivo .env creado por el entrypoint
|
||||
$dotenv = null;
|
||||
if (file_exists(dirname(__DIR__) . '/.env')) {
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
||||
try {
|
||||
$dotenv->load();
|
||||
} catch (Exception $e) {
|
||||
die('Error al cargar el archivo de entorno en Docker: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Entorno local: cargar archivo .env según APP_ENVIRONMENT
|
||||
$env = getenv('APP_ENVIRONMENT') ?: ($_SERVER['APP_ENVIRONMENT'] ?? null);
|
||||
$envFile = '.env';
|
||||
if ($env) {
|
||||
$envFile = '.env.' . $env;
|
||||
}
|
||||
|
||||
$dotenv = null;
|
||||
if (file_exists(dirname(__DIR__) . '/' . $envFile)) {
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__), $envFile);
|
||||
} elseif (file_exists(dirname(__DIR__) . '/.env')) {
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
||||
}
|
||||
|
||||
if ($dotenv) {
|
||||
try {
|
||||
$dotenv->load();
|
||||
} catch (Exception $e) {
|
||||
die('Error al cargar el archivo de entorno: ' . $e->getMessage());
|
||||
}
|
||||
$dotenv->required([
|
||||
'DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS',
|
||||
'JWT_SECRET', 'APP_URL'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Environment Configuration
|
||||
define('ENVIRONMENT', $_ENV['APP_ENV'] ?? $_SERVER['APP_ENV'] ?? 'production');
|
||||
|
||||
// Detectar si se ejecuta desde la línea de comandos
|
||||
$is_cli = (php_sapi_name() === 'cli' || defined('STDIN'));
|
||||
|
||||
// Helper function to get env vars
|
||||
function getEnvVar($name, $default = null) {
|
||||
return $_ENV[$name] ?? $_SERVER[$name] ?? getenv($name) ?? $default;
|
||||
}
|
||||
|
||||
// Configurar la URL base y el protocolo
|
||||
if ($is_cli) {
|
||||
define('BOT_BASE_URL', getEnvVar('APP_URL'));
|
||||
$protocol = 'http';
|
||||
} else {
|
||||
$protocol = 'http';
|
||||
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
|
||||
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
|
||||
(!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] === 'on') ||
|
||||
(!empty($_SERVER['HTTP_CF_VISITOR']) && strpos($_SERVER['HTTP_CF_VISITOR'], 'https') !== false)) {
|
||||
$protocol = 'https';
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
$_SERVER['SERVER_PORT'] = 443;
|
||||
}
|
||||
$app_url = getEnvVar('APP_URL');
|
||||
if ($app_url) {
|
||||
define('BOT_BASE_URL', $app_url);
|
||||
} else {
|
||||
define('BOT_BASE_URL', $protocol . '://' . $_SERVER['HTTP_HOST']);
|
||||
}
|
||||
$_SERVER['REQUEST_SCHEME'] = $protocol;
|
||||
}
|
||||
define('BASE_PATH', dirname(__DIR__));
|
||||
|
||||
// Database Configuration
|
||||
define('DB_HOST', getEnvVar('DB_HOST'));
|
||||
define('DB_USER', getEnvVar('DB_USER'));
|
||||
define('DB_PASS', getEnvVar('DB_PASS'));
|
||||
define('DB_NAME', getEnvVar('DB_NAME'));
|
||||
define('DB_DIALECT', getEnvVar('DB_DIALECT'));
|
||||
define('DB_PORT', getEnvVar('DB_PORT'));
|
||||
|
||||
// Session Configuration
|
||||
define('SESSION_SECRET', getEnvVar('JWT_SECRET'));
|
||||
|
||||
// Discord API Configuration
|
||||
define('DISCORD_GUILD_ID', getEnvVar('DISCORD_GUILD_ID'));
|
||||
define('DISCORD_CLIENT_ID', getEnvVar('DISCORD_CLIENT_ID'));
|
||||
define('DISCORD_CLIENT_SECRET', getEnvVar('DISCORD_CLIENT_SECRET'));
|
||||
define('DISCORD_BOT_TOKEN', getEnvVar('DISCORD_BOT_TOKEN'));
|
||||
|
||||
// Telegram API Configuration
|
||||
define('TELEGRAM_BOT_TOKEN', getEnvVar('TELEGRAM_BOT_TOKEN'));
|
||||
define('TELEGRAM_WEBHOOK_TOKEN', getEnvVar('TELEGRAM_WEBHOOK_TOKEN'));
|
||||
|
||||
// LibreTranslate Configuration
|
||||
define('LIBRETRANSLATE_URL', getEnvVar('LIBRETRANSLATE_URL'));
|
||||
|
||||
// N8N Configuration
|
||||
define('N8N_URL', getEnvVar('N8N_URL'));
|
||||
define('N8N_TOKEN', getEnvVar('N8N_TOKEN'));
|
||||
define('N8N_PROCESS_QUEUE_WEBHOOK_URL', getEnvVar('N8N_PROCESS_QUEUE_WEBHOOK_URL'));
|
||||
define('N8N_IA_WEBHOOK_URL', getEnvVar('N8N_IA_WEBHOOK_URL'));
|
||||
define('N8N_IA_WEBHOOK_URL_DISCORD', getEnvVar('N8N_IA_WEBHOOK_URL_DISCORD'));
|
||||
define('INTERNAL_API_KEY', getEnvVar('INTERNAL_API_KEY'));
|
||||
|
||||
// Error Reporting
|
||||
switch (ENVIRONMENT) {
|
||||
case 'development':
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('log_errors', '1');
|
||||
ini_set('error_log', dirname(__DIR__) . '/logs/php_errors.log');
|
||||
break;
|
||||
case 'production':
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
ini_set('display_errors', '0');
|
||||
ini_set('log_errors', '1');
|
||||
ini_set('error_log', dirname(__DIR__) . '/logs/php_errors.log');
|
||||
break;
|
||||
default:
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('log_errors', '1');
|
||||
ini_set('error_log', dirname(__DIR__) . '/logs/php_errors.log');
|
||||
break;
|
||||
}
|
||||
|
||||
// Helper function to get full URL
|
||||
function url($path = '') {
|
||||
$path = ltrim($path, '/');
|
||||
return BOT_BASE_URL . '/' . $path;
|
||||
}
|
||||
|
||||
// Helper function to get full asset URL
|
||||
function asset_url($path = '') {
|
||||
$path = ltrim($path, '/');
|
||||
return BOT_BASE_URL . '/assets/' . $path;
|
||||
}
|
||||
13
config/discordbot.conf
Executable file
13
config/discordbot.conf
Executable file
@@ -0,0 +1,13 @@
|
||||
# Configuración actualizada de Supervisor para Discord Bot
|
||||
# Usar: sudo cp config/discordbot_updated.conf /etc/supervisor/conf.d/discordbot.conf
|
||||
|
||||
[program:discordbot]
|
||||
command=/usr/bin/php /var/www/html/bot/discord/bot/discord_bot.php
|
||||
environment=APP_ENVIRONMENT="reod"
|
||||
directory=/var/www/html/bot/
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/www/html/bot/logs/discordbot.err.log
|
||||
stdout_logfile=/var/www/html/bot/logs/discordbot.out.log
|
||||
user=www-data
|
||||
redirect_stderr=false
|
||||
13
config/discordbot_updated.conf
Executable file
13
config/discordbot_updated.conf
Executable file
@@ -0,0 +1,13 @@
|
||||
# Configuración actualizada de Supervisor para Discord Bot
|
||||
# Usar: sudo cp config/discordbot_updated.conf /etc/supervisor/conf.d/discordbot.conf
|
||||
|
||||
[program:discordbot]
|
||||
command=/usr/bin/php /var/www/html/bot/discord/bot/discord_bot.php
|
||||
environment=APP_ENVIRONMENT="reod"
|
||||
directory=/var/www/html/bot/
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/www/html/bot/logs/discordbot.err.log
|
||||
stdout_logfile=/var/www/html/bot/logs/discordbot.out.log
|
||||
user=www-data
|
||||
redirect_stderr=false
|
||||
11
config/translation-worker.conf
Executable file
11
config/translation-worker.conf
Executable file
@@ -0,0 +1,11 @@
|
||||
[program:translation-worker]
|
||||
command=/usr/bin/php /var/www/html/bot/process_translation_queue.php
|
||||
directory=/var/www/html/bot/
|
||||
user=www-data
|
||||
autostart=true
|
||||
autorestart=true
|
||||
environment=APP_ENVIRONMENT="pruebas"
|
||||
stdout_logfile=/var/www/html/bot/logs/translation-worker.out.log
|
||||
stderr_logfile=/var/www/html/bot/logs/translation-worker.err.log
|
||||
redirect_stderr=true
|
||||
numprocs=1
|
||||
Reference in New Issue
Block a user