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>
104 lines
4.6 KiB
PHP
104 lines
4.6 KiB
PHP
<?php
|
|
/** Formulare von Verwaltung -> Discord-Bot (admin/bot.php). */
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
require_once __DIR__ . '/../includes/discord_bot.php';
|
|
require_permission('bot.manage');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
redirect('/admin/bot.php');
|
|
}
|
|
verify_csrf();
|
|
|
|
/**
|
|
* Kanal-ID aus dem Formular, wenn der Bot dort posten darf - sonst null.
|
|
*
|
|
* @param array<int, array<string, mixed>> $channels
|
|
*/
|
|
function bot_channel_input(string $raw, array $channels): ?int
|
|
{
|
|
foreach ($channels as $channel) {
|
|
if ((string) ($channel['channel_id'] ?? '') === $raw && !empty($channel['can_post'])) {
|
|
return (int) $raw;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
$action = (string) ($_POST['action'] ?? '');
|
|
try {
|
|
if ($action === 'channels') {
|
|
$before = discord_bot_settings();
|
|
$channels = fetch_guild_channels();
|
|
$changes = [];
|
|
$logFields = [];
|
|
foreach (DISCORD_BOT_CHANNELS as $key => [$label]) {
|
|
$raw = trim((string) ($_POST[$key] ?? ''));
|
|
if ($raw === '' || $raw === ($before[$key] ?? '')) {
|
|
continue; // leer lassen = unveraendert (den Kanal abwaehlen kennt der Bot nicht)
|
|
}
|
|
$channelId = bot_channel_input($raw, $channels);
|
|
if ($channelId === null) {
|
|
throw new RuntimeException($label . ': In diesem Kanal darf der Bot nicht posten.');
|
|
}
|
|
$changes[$key] = $channelId;
|
|
$logFields[$label] = admin_log_change(event_log_channel($before[$key] ?? '') ?: 'keiner', event_log_channel($channelId));
|
|
}
|
|
if (empty($changes)) {
|
|
set_flash('info', 'Keine Änderungen.');
|
|
} else {
|
|
discord_bot_save_channels($changes);
|
|
admin_log('🤖 Discord-Bot: Kanäle geändert', $logFields);
|
|
set_flash('success', 'Kanäle gespeichert.');
|
|
}
|
|
} elseif ($action === 'panel') {
|
|
$kind = (string) ($_POST['kind'] ?? '');
|
|
if (!isset(DISCORD_BOT_PANELS[$kind])) {
|
|
throw new RuntimeException('Unbekannte Übersicht.');
|
|
}
|
|
$channelId = bot_channel_input(trim((string) ($_POST['channel_id'] ?? '')), fetch_guild_channels());
|
|
if ($channelId === null) {
|
|
throw new RuntimeException('Bitte einen Kanal wählen, in dem der Bot posten darf.');
|
|
}
|
|
$roles = [];
|
|
$logFields = ['Kanal' => event_log_channel($channelId)];
|
|
if ($kind === 'reports') {
|
|
// Rollen des Melde-Panels: nur solche, die es auf dem Server gibt ('' = keine)
|
|
$knownRoles = array_map(static fn (array $r): string => (string) ($r['role_id'] ?? ''), fetch_guild_roles());
|
|
foreach (['ping_role_id' => 'Ping', 'lead_role_id' => 'Leitung im Text'] as $field => $fieldLabel) {
|
|
$raw = trim((string) ($_POST[$field] ?? ''));
|
|
if ($raw !== '' && !in_array($raw, $knownRoles, true)) {
|
|
throw new RuntimeException($fieldLabel . ': Diese Rolle gibt es auf dem Discord-Server nicht (mehr).');
|
|
}
|
|
$roles[$field] = $raw !== '' ? (int) $raw : null;
|
|
$logFields[$fieldLabel] = $raw !== '' ? '<@&' . $raw . '>' : 'keine';
|
|
}
|
|
}
|
|
discord_bot_post_panel($kind, $channelId, $roles);
|
|
$label = DISCORD_BOT_PANELS[$kind][0];
|
|
admin_log('🤖 ' . $label . ' im Discord gepostet', $logFields, 'success');
|
|
set_flash('success', $label . ' ist gepostet.');
|
|
} elseif ($action === 'resync') {
|
|
$result = discord_bot_resync_raids();
|
|
$reposted = array_map(static fn (array $r): string => (string) ($r['title'] ?? ''), $result['reposted']);
|
|
$failed = array_map(static fn (array $r): string => (string) ($r['title'] ?? '') . ' (' . (string) ($r['error'] ?? '') . ')', $result['failed']);
|
|
admin_log('🔄 Raid-Nachrichten abgeglichen', [
|
|
'Aktualisiert' => (string) $result['updated'],
|
|
'Neu gepostet' => implode(', ', $reposted),
|
|
'Fehlgeschlagen' => implode(', ', $failed),
|
|
]);
|
|
$message = $result['updated'] . ' Raid-Nachricht' . ($result['updated'] === 1 ? '' : 'en') . ' aktualisiert';
|
|
if ($reposted) {
|
|
$message .= ', neu gepostet: ' . implode(', ', $reposted);
|
|
}
|
|
set_flash('success', $message . '.');
|
|
if ($failed) {
|
|
set_flash('error', 'Nicht abgeglichen: ' . implode(', ', $failed));
|
|
}
|
|
} else {
|
|
throw new RuntimeException('Unbekannte Aktion.');
|
|
}
|
|
} catch (Throwable $e) {
|
|
set_flash('error', $e->getMessage());
|
|
}
|
|
|
|
redirect('/admin/bot.php');
|