LuminaWebsite/admin/bot.php
Maaxxs f8beaebdcf Report panel: explains the rules with the real values, pings a chosen role, names the leadership
The report panel in Discord ("Mitglied melden", bot deployed with this change) now says what it is
for and how reports count: points per report (from the role weights, e.g. Veteranus 3), the mute
threshold, 48 hours on the "Stille Treppe" and that reports expire after 10 days. The bot updates
the panel by itself when the threshold or the role weights change here.

- Verwaltung -> Discord-Bot: when posting the report panel, pick the role that gets pinged
  ("Arieluma @Rolle!" above the panel - only that text pings) and the leadership role that is named
  in the text (without ping). Both are sent as ping_role_id / lead_role_id, stored by the bot and
  preselected next time; the audit log names them. Unknown roles are rejected.
- Texts say "Mitglied melden" instead of "Spieler melden"; the reports settings mention that the
  panel follows threshold and weights.
- README and patch notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 12:43:32 +02:00

154 lines
7.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Verwaltung -> Discord-Bot: Kanaele, Premade-Uebersicht und Melde-Panel, Raid-Nachrichten abgleichen
* (includes/discord_bot.php). Ersetzt die Slash-Befehle, die es im Bot seit dem Umbau (09/2026) nicht mehr gibt.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/discord_bot.php';
require_permission('bot.manage');
$settings = [];
$channels = [];
$guildRoles = [];
$apiError = null;
try {
$settings = discord_bot_settings();
$channels = fetch_guild_channels();
$guildRoles = fetch_guild_roles();
} catch (Throwable $e) {
$apiError = $e->getMessage();
}
/**
* Auswahl eines Textkanals. Kanaele, in denen der Bot nicht posten darf, sind ausgegraut.
*
* @param array<int, array<string, mixed>> $channels
*/
function bot_channel_select(string $name, string $id, array $channels, string $selected, string $placeholder): void
{
?>
<select name="<?= e($name) ?>" id="<?= e($id) ?>">
<option value=""<?= $selected === '' ? ' selected' : '' ?>><?= e($placeholder) ?></option>
<?php foreach ($channels as $channel): ?>
<?php $cid = (string) ($channel['channel_id'] ?? ''); ?>
<option value="<?= e($cid) ?>"<?= $cid === $selected ? ' selected' : '' ?><?= empty($channel['can_post']) && $cid !== $selected ? ' disabled' : '' ?>>
#<?= e((string) ($channel['name'] ?? '')) ?><?php if (!empty($channel['category'])): ?> (<?= e((string) $channel['category']) ?>)<?php endif; ?><?= empty($channel['can_post']) ? ' – Bot darf hier nicht posten' : '' ?>
</option>
<?php endforeach; ?>
</select>
<?php
}
/**
* Auswahl einer Rolle des Servers (fuer das Melde-Panel).
*
* @param array<int, array<string, mixed>> $roles
*/
function bot_role_select(string $name, string $id, array $roles, string $selected, string $placeholder): void
{
?>
<select name="<?= e($name) ?>" id="<?= e($id) ?>">
<option value=""<?= $selected === '' ? ' selected' : '' ?>><?= e($placeholder) ?></option>
<?php foreach ($roles as $role): ?>
<?php $rid = (string) ($role['role_id'] ?? ''); ?>
<option value="<?= e($rid) ?>"<?= $rid === $selected ? ' selected' : '' ?>>@<?= e((string) ($role['name'] ?? '')) ?></option>
<?php endforeach; ?>
</select>
<?php
}
$pageTitle = 'Discord-Bot';
include __DIR__ . '/../includes/header.php';
?>
<div class="panel">
<h1>Discord-Bot</h1>
<p class="text-muted">
Im Discord wird nichts mehr erstellt oder verwaltet – Raids, Premades, Events, Aktivitätschecks und
Reports laufen über die Website. Der Bot zeigt an, erinnert und nimmt Raid-Anmeldungen und Meldungen
entgegen. Hier legst du fest, wohin er postet.
</p>
</div>
<?php if ($apiError !== null): ?>
<div class="panel">
<div class="flash flash-error">Der Bot ist gerade nicht erreichbar: <?= e($apiError) ?></div>
</div>
<?php else: ?>
<div class="panel">
<h2>Kanäle</h2>
<form method="post" action="/admin/bot_action.php" class="bot-admin-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="channels">
<?php foreach (DISCORD_BOT_CHANNELS as $key => [$label, $hint]): ?>
<div>
<label for="bot-<?= e($key) ?>"><?= e($label) ?></label>
<?php bot_channel_select($key, 'bot-' . $key, $channels, $settings[$key] ?? '', '– nicht festgelegt –'); ?>
<div class="field-hint"><?= e($hint) ?></div>
</div>
<?php endforeach; ?>
<div class="actions">
<button type="submit">Kanäle speichern</button>
</div>
</form>
</div>
<div class="panel">
<h2>Übersichten im Discord</h2>
<p class="text-muted">
Der Bot merkt sich, wo sie stehen. Postest du sie neu, löscht er die bisherige. Was früher per
Befehl im Discord gepostet wurde, kennt er nicht – das nach dem Neu-Posten dort von Hand löschen.
</p>
<div class="bot-panels">
<?php foreach (DISCORD_BOT_PANELS as $kind => [$label, $path, $hint]): ?>
<?php $current = $settings[$kind === 'premades' ? 'premade_panel_channel' : 'report_panel_channel'] ?? ''; ?>
<form method="post" action="/admin/bot_action.php" class="bot-admin-form bot-panel">
<?= csrf_field() ?>
<input type="hidden" name="action" value="panel">
<input type="hidden" name="kind" value="<?= e($kind) ?>">
<h3><?= e($label) ?></h3>
<p class="text-muted"><?= e($hint) ?></p>
<p>
<?php if ($current !== ''): ?>
Steht in <strong><?= e(discord_bot_channel_label($current, $channels)) ?></strong>.
<?php else: ?>
<span class="text-muted">Noch nicht über die Website gepostet.</span>
<?php endif; ?>
</p>
<div>
<label for="bot-panel-<?= e($kind) ?>">Kanal</label>
<?php bot_channel_select('channel_id', 'bot-panel-' . $kind, $channels, $current, '– Kanal wählen –'); ?>
</div>
<?php if ($kind === 'reports'): ?>
<div>
<label for="bot-report-ping">Ping beim Posten</label>
<?php bot_role_select('ping_role_id', 'bot-report-ping', $guildRoles, $settings['report_panel_ping_role'] ?? '', '– niemand –'); ?>
<div class="field-hint">Über dem Panel steht „Arieluma @Rolle!“ – das pingt die Rolle einmal beim Posten, z.B. alle Mitglieder. Jedes Neu-Posten pingt wieder.</div>
</div>
<div>
<label for="bot-report-lead">Leitung im Text</label>
<?php bot_role_select('lead_role_id', 'bot-report-lead', $guildRoles, $settings['report_panel_lead_role'] ?? '', '– keine Rolle („die Legionsleitung“) –'); ?>
<div class="field-hint">Wird im Panel erwähnt, ohne Ping – z.B. „die @Sedes Luminis kümmern sich zeitnah um dein Anliegen“.</div>
</div>
<?php endif; ?>
<div class="actions">
<button type="submit" class="button-secondary"><?= $current !== '' ? 'Neu posten' : 'Posten' ?></button>
</div>
</form>
<?php endforeach; ?>
</div>
</div>
<div class="panel">
<h2>Raid-Nachrichten abgleichen</h2>
<p class="text-muted">
Bringt die Nachrichten aller aktiven Raids im Discord auf den Stand der Website und postet fehlende
neu – etwa wenn jemand eine Raid-Nachricht gelöscht hat.
</p>
<form method="post" action="/admin/bot_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="resync">
<button type="submit" class="button-secondary"><?= icon('restore') ?> Jetzt abgleichen</button>
</form>
</div>
<?php endif; ?>
<?php include __DIR__ . '/../includes/footer.php'; ?>