313 lines
14 KiB
PHP
313 lines
14 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
@date_default_timezone_set('UTC');
|
|
|
|
require_once __DIR__ . '/includes/app.php';
|
|
|
|
ensure_tables();
|
|
|
|
$phpVersion = PHP_VERSION;
|
|
$now = date('Y-m-d H:i:s');
|
|
|
|
$settings = get_settings();
|
|
$formErrors = [];
|
|
$values = [
|
|
'guild_name' => '',
|
|
'requester_name' => '',
|
|
'query_text' => '',
|
|
'source_type' => 'search',
|
|
'voice_channel' => '',
|
|
'notes' => '',
|
|
];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'create_request') {
|
|
$values['guild_name'] = trim((string)($_POST['guild_name'] ?? ''));
|
|
$values['requester_name'] = trim((string)($_POST['requester_name'] ?? ''));
|
|
$values['query_text'] = trim((string)($_POST['query_text'] ?? ''));
|
|
$values['source_type'] = trim((string)($_POST['source_type'] ?? 'search'));
|
|
$values['voice_channel'] = trim((string)($_POST['voice_channel'] ?? ''));
|
|
$values['notes'] = trim((string)($_POST['notes'] ?? ''));
|
|
|
|
if ($values['guild_name'] === '') {
|
|
$formErrors[] = 'Server/Guild name is required.';
|
|
}
|
|
if ($values['requester_name'] === '') {
|
|
$formErrors[] = 'Requester name is required.';
|
|
}
|
|
if ($values['query_text'] === '') {
|
|
$formErrors[] = 'Song title or URL is required.';
|
|
}
|
|
if (!in_array($values['source_type'], ['search', 'url'], true)) {
|
|
$formErrors[] = 'Source type is invalid.';
|
|
}
|
|
|
|
if (!$formErrors) {
|
|
$stmt = db()->prepare('INSERT INTO music_requests (guild_name, requester_name, query_text, source_type, voice_channel, notes, status) VALUES (:guild_name, :requester_name, :query_text, :source_type, :voice_channel, :notes, :status)');
|
|
$stmt->execute([
|
|
':guild_name' => $values['guild_name'],
|
|
':requester_name' => $values['requester_name'],
|
|
':query_text' => $values['query_text'],
|
|
':source_type' => $values['source_type'],
|
|
':voice_channel' => $values['voice_channel'],
|
|
':notes' => $values['notes'],
|
|
':status' => 'queued',
|
|
]);
|
|
|
|
$newId = (int)db()->lastInsertId();
|
|
header('Location: request.php?id=' . $newId . '&created=1');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$recentRequests = db()->query('SELECT id, guild_name, requester_name, query_text, source_type, status, created_at FROM music_requests ORDER BY created_at DESC LIMIT 6')->fetchAll();
|
|
$recentLogs = db()->query('SELECT user_name, action, created_at FROM bot_logs ORDER BY created_at DESC LIMIT 5')->fetchAll();
|
|
|
|
if (!$recentLogs) {
|
|
add_log('System', 'INITIALIZE', 'CMS Dashboard initialized successfully.');
|
|
add_log('Admin', 'CONFIG_UPDATE', 'Bot settings updated (prefix and volume).');
|
|
$recentLogs = db()->query('SELECT user_name, action, created_at FROM bot_logs ORDER BY created_at DESC LIMIT 5')->fetchAll();
|
|
}
|
|
|
|
// Check if worker is running
|
|
$workerPid = shell_exec("pgrep -f 'bot/worker.php'");
|
|
$isWorkerRunning = !empty($workerPid);
|
|
|
|
// Read project preview data from environment
|
|
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
|
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
$projectName = $_SERVER['PROJECT_NAME'] ?? 'Discord Music Bot Control Center';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title><?= h($projectName) ?></title>
|
|
<?php if ($projectDescription): ?>
|
|
<meta name="description" content="<?= h($projectDescription) ?>" />
|
|
<meta property="og:description" content="<?= h($projectDescription) ?>" />
|
|
<meta property="twitter:description" content="<?= h($projectDescription) ?>" />
|
|
<?php endif; ?>
|
|
<?php if ($projectImageUrl): ?>
|
|
<meta property="og:image" content="<?= h($projectImageUrl) ?>" />
|
|
<meta property="twitter:image" content="<?= h($projectImageUrl) ?>" />
|
|
<?php endif; ?>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?= (int)time() ?>">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg sticky-top app-navbar">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">EchoLift</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navMenu" aria-controls="navMenu" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navMenu">
|
|
<div class="navbar-nav ms-auto">
|
|
<a class="nav-link active" href="index.php">Dashboard</a>
|
|
<a class="nav-link" href="requests.php">Queue</a>
|
|
<a class="nav-link" href="logs.php">Logs</a>
|
|
<a class="nav-link" href="settings.php">Settings</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="app-shell">
|
|
<section class="container py-4 py-lg-5">
|
|
<div class="row align-items-center gy-4">
|
|
<div class="col-lg-7">
|
|
<p class="eyebrow">Stable Discord music operations</p>
|
|
<h1 class="display-5">Manage play requests, queue health, and bot settings in one restrained console.</h1>
|
|
<p class="lead text-muted">Submit a song by URL or search query, track status per server, and keep moderation settings consistent across communities.</p>
|
|
<div class="d-flex gap-2">
|
|
<a class="btn btn-primary" href="#request-form">Create a request</a>
|
|
<a class="btn btn-outline-secondary" href="requests.php">View queue</a>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-5">
|
|
<div class="card app-card">
|
|
<div class="card-body">
|
|
<h2 class="h5">Bot status</h2>
|
|
<div class="status-grid">
|
|
<div>
|
|
<p class="label">Auto-reconnect</p>
|
|
<p class="value"><?= $settings['auto_reconnect'] ? 'Enabled' : 'Disabled' ?></p>
|
|
</div>
|
|
<div>
|
|
<p class="label">Command prefix</p>
|
|
<p class="value"><?= h($settings['prefix']) ?></p>
|
|
</div>
|
|
<div>
|
|
<p class="label">Max volume</p>
|
|
<p class="value"><?= h((string)$settings['max_volume']) ?>%</p>
|
|
</div>
|
|
<div>
|
|
<p class="label">Log level</p>
|
|
<p class="value"><?= h($settings['log_level']) ?></p>
|
|
</div>
|
|
<div>
|
|
<p class="label">Worker Status</p>
|
|
<p class="value <?= $isWorkerRunning ? 'text-success' : 'text-danger' ?>">
|
|
<?= $isWorkerRunning ? 'Always-on' : 'Stopped' ?>
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<p class="label">Discord link</p>
|
|
<p class="value <?= $settings['discord_token'] ? 'text-success' : 'text-danger' ?>">
|
|
<?= $settings['discord_token'] ? 'Connected' : 'Missing token' ?>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<a class="btn btn-sm btn-outline-secondary mt-3" href="settings.php">Adjust settings</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="container pb-5">
|
|
<div class="row g-4">
|
|
<div class="col-lg-7">
|
|
<div class="card app-card" id="request-form">
|
|
<div class="card-body">
|
|
<h2 class="h5">New play request</h2>
|
|
<p class="text-muted">Create a queue item that the bot will pick up and process in the voice channel.</p>
|
|
|
|
<?php if ($formErrors): ?>
|
|
<div class="alert alert-warning" role="alert">
|
|
<?= h(implode(' ', $formErrors)) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" action="index.php" class="row g-3">
|
|
<input type="hidden" name="action" value="create_request">
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="guild_name">Server / Guild</label>
|
|
<input class="form-control" id="guild_name" name="guild_name" required value="<?= h($values['guild_name']) ?>" placeholder="Aurora Community">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="requester_name">Requester</label>
|
|
<input class="form-control" id="requester_name" name="requester_name" required value="<?= h($values['requester_name']) ?>" placeholder="@luna">
|
|
</div>
|
|
<div class="col-md-8">
|
|
<label class="form-label" for="query_text">Song title or URL</label>
|
|
<input class="form-control" id="query_text" name="query_text" required value="<?= h($values['query_text']) ?>" placeholder="Search title or paste URL">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="source_type">Source</label>
|
|
<select class="form-select" id="source_type" name="source_type">
|
|
<option value="search" <?= $values['source_type'] === 'search' ? 'selected' : '' ?>>Search</option>
|
|
<option value="url" <?= $values['source_type'] === 'url' ? 'selected' : '' ?>>Direct URL</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="voice_channel">Voice channel</label>
|
|
<input class="form-control" id="voice_channel" name="voice_channel" value="<?= h($values['voice_channel']) ?>" placeholder="#lofi-room">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="notes">Notes</label>
|
|
<input class="form-control" id="notes" name="notes" value="<?= h($values['notes']) ?>" placeholder="Priority, mood, or DJ note">
|
|
</div>
|
|
<div class="col-12 d-flex gap-2">
|
|
<button class="btn btn-primary" type="submit">Submit to queue</button>
|
|
<button class="btn btn-outline-secondary" type="reset">Clear</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-5">
|
|
<div class="card app-card">
|
|
<div class="card-body">
|
|
<h2 class="h5">Recent queue activity</h2>
|
|
<p class="text-muted">Latest submissions across all servers.</p>
|
|
|
|
<?php if (!$recentRequests): ?>
|
|
<div class="empty-state">
|
|
<p class="mb-1">No requests yet.</p>
|
|
<p class="text-muted small">Submit the first play request to start the queue.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="list-group list-group-flush">
|
|
<?php foreach ($recentRequests as $request): ?>
|
|
<a class="list-group-item list-group-item-action" href="request.php?id=<?= (int)$request['id'] ?>">
|
|
<div class="d-flex justify-content-between">
|
|
<div>
|
|
<p class="mb-1 fw-semibold"><?= h($request['query_text']) ?></p>
|
|
<p class="mb-0 small text-muted"><?= h($request['guild_name']) ?> • <?= h($request['requester_name']) ?></p>
|
|
</div>
|
|
<span class="badge status-badge status-<?= h($request['status']) ?>"><?= h(ucfirst($request['status'])) ?></span>
|
|
</div>
|
|
<p class="small text-muted mt-2 mb-0"><?= h($request['source_type']) ?> • <?= h($request['created_at']) ?></p>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<a class="btn btn-link mt-3 px-0" href="requests.php">Open full queue</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card app-card mt-4">
|
|
<div class="card-body">
|
|
<h2 class="h5">Recent audit logs</h2>
|
|
<p class="text-muted">Security and operational events.</p>
|
|
<?php if (!$recentLogs): ?>
|
|
<div class="empty-state">
|
|
<p class="text-muted small">No logs recorded yet.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="list-group list-group-flush small">
|
|
<?php foreach ($recentLogs as $log): ?>
|
|
<div class="list-group-item px-0">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<span class="fw-semibold"><?= h($log['action']) ?></span>
|
|
<span class="text-muted tiny"><?= h($log['created_at']) ?></span>
|
|
</div>
|
|
<div class="text-muted">by <?= h($log['user_name']) ?></div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<a class="btn btn-link btn-sm mt-3 px-0" href="logs.php">View all logs</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card app-card mt-4">
|
|
<div class="card-body">
|
|
<h3 class="h6">Slash command coverage</h3>
|
|
<div class="command-grid">
|
|
<span>/play</span>
|
|
<span>/search</span>
|
|
<span>/queue</span>
|
|
<span>/skip</span>
|
|
<span>/pause</span>
|
|
<span>/resume</span>
|
|
<span>/stop</span>
|
|
<span>/loop</span>
|
|
<span>/shuffle</span>
|
|
<span>/volume</span>
|
|
<span>/nowplaying</span>
|
|
</div>
|
|
<p class="small text-muted mt-3">Commands map to the request queue and playback service.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<footer class="app-footer py-4">
|
|
<div class="container d-flex flex-column flex-md-row justify-content-between">
|
|
<span class="text-muted small">Runtime PHP <?= h($phpVersion) ?> • UTC <?= h($now) ?></span>
|
|
<span class="text-muted small">Next step: connect the bot worker to process queued requests.</span>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
|
<script src="assets/js/main.js?v=<?= (int)time() ?>"></script>
|
|
</body>
|
|
</html>
|