LuminaWebsite/admin/bot_action.php
Maaxxs 8b59cb503b DACH Elyos: the Consilium Elyseum is now called DACH Elyos across the website
Asked for: "das consilium elyseum wurde umbenannt zu DACH Elyos. pass das bitte an auf der website".

- CONSILIUM_NAME is 'DACH Elyos', and every visible text follows it: sidebar, the alliance page, member tab, raid
  area, calendar audience and badge, iCal note, map live sessions and share buttons, admin pages (Verwaltung ->
  DACH Elyos, Discord-Bot, Berechtigungsgruppen), flash messages, log entries, permission descriptions (synced to
  the database by schema_sync_core_permissions()) and the privacy page.
- The name takes no article, so the sentences around it changed too: "von DACH Elyos", "in DACH Elyos", "für DACH
  Elyos" instead of "des Consiliums", "im Consilium", "für das Consilium". The bot channel label is now
  "Raid-Kanal DACH Elyos".
- Internal names stay "consilium": permission keys, tables, settings, files and URLs (?bereich=consilium,
  ?tab=consilium), so nothing in the database or in existing links changes. includes/consilium.php says so.
- README: section renamed to "DACH Elyos" (anchor #dach-elyos).
- No patch note (alliance topics stay out of them). The bot's two "Consilium" error texts in live_tactics.py never
  reach the page - the map only reads the status code - so the bot needs no update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 14:15:10 +02:00

140 lines
6.6 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
/** 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();
// Consilium-Raids: Kanal auf dem Server des Consiliums, sobald einer eingetragen ist
require_once __DIR__ . '/../includes/consilium.php';
$consiliumGuild = consilium_guild_id();
$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, $key === 'consilium_raid_channel' && $consiliumGuild !== ''
? fetch_guild_channels($consiliumGuild) : $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 === 'consilium_guild') {
// Server des Consilium Elyseum (includes/consilium.php) - leer = keiner
require_once __DIR__ . '/../includes/consilium.php';
$raw = trim((string) ($_POST['consilium_guild_id'] ?? ''));
$before = consilium_guild_id();
if ($raw !== '' && preg_match('/^[0-9]{5,20}$/', $raw) !== 1) {
throw new RuntimeException('Die Server-ID besteht nur aus Ziffern.');
}
if ($raw !== '' && $raw === discord_guild_id()) {
throw new RuntimeException('Das ist der Server der Legion – hier gehört der Server von ' . CONSILIUM_NAME . ' hin.');
}
if ($raw === $before) {
set_flash('info', 'Keine Änderungen.');
} else {
setting_set('consilium_guild_id', $raw);
// Alle beim naechsten Seitenaufruf mit Discord abgleichen (Gruppen des Consiliums)
db()->exec('UPDATE users SET discord_synced_at = NULL');
admin_log('🤖 Discord-Bot: Server von ' . CONSILIUM_NAME . ' geändert', [
'Server' => admin_log_change($before !== '' ? $before : 'keiner', $raw !== '' ? $raw : 'keiner'),
]);
$botThere = true;
if ($raw !== '') {
try {
fetch_guild_channels($raw);
} catch (Throwable $e) {
$botThere = false;
}
}
set_flash($botThere ? 'success' : 'info', $botThere
? 'Server gespeichert.'
: 'Server gespeichert – der Bot ist aber noch nicht darauf. Bitte einladen, sonst gibt es dort keine Raids von ' . CONSILIUM_NAME . '.');
}
} 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');