diff --git a/README.md b/README.md index fe3969a..141d8bf 100644 --- a/README.md +++ b/README.md @@ -1569,6 +1569,17 @@ Rolle hat, sieht auf der Website den Bereich Elyos Allianz; Mitglieder verbünde der Legion. Der angezeigte Name steht in `CONSILIUM_NAME` - im Code, in Rechten, Tabellen, Einstellungen und Adressen heißt alles weiter `consilium`. Code: `includes/consilium.php`, Verwaltung `admin/consilium.php`. +- **Siel, der Bot der Elyos Allianz** (seit 29.09.2026; Code `E:\DiscordBots\SielBot` → `/root/sielbot`, Verwaltung auf + https://bot.lumina-ascendens.de): postet die Raids der Elyos Allianz auf deren Server und liefert dessen Kanäle und + Rollen. Die Website spricht ihn über `config.php` → `siel_api` an (`url` = `https://bot.lumina-ascendens.de/website-api/raids`, + `key` = `WEBSITE_API_KEY` aus `/root/sielbot/.env`). Fehlt der Block, macht Nezekan alles wie vorher. + `raids_fetch_combined()` holt die Raids beider Bots (Feld `bot`: `nezekan`/`siel`, Raids von Siel sind immer + Elyos Allianz), `raid_backend_request()` schickt Anfragen zu einem Raid an den Bot, der ihn gepostet hat (bei 404 an + den anderen), `guilds_api_request()` fragt für den Server der Elyos Allianz Siel. Raids, die Nezekan noch gepostet + hat, laufen dort zu Ende. Premades gibt es bei Raids der Elyos Allianz nicht. Austritte und den 30-Minuten-Abgleich + (`bot_api.php`, `member_left`/`legion_sync`) meldet ebenfalls Siel - für beide Server, er ist dafür auch auf dem + Legionsserver (ohne Rechte, dort sonst ohne Funktion). + - **Zwei Discord-Server:** der der Legion (`config.php`) und der von Elyos Allianz (`settings.consilium_guild_id`, Verwaltung → Discord-Bot; `consilium_guild_id()`). Die Rolle einer Berechtigungsgruppe liegt auf einem von beiden (`roles.discord_guild_id`, NULL = Legion) und wird mit diesem Server abgeglichen - beim Login und alle paar Minuten diff --git a/admin/bot.php b/admin/bot.php index 1a8ff1a..3010c50 100644 --- a/admin/bot.php +++ b/admin/bot.php @@ -100,7 +100,7 @@ include __DIR__ . '/../includes/header.php';
-
⚠️ Die Kanäle des Servers von lassen sich nicht laden – ist der Bot dort Mitglied? ()
+
⚠️ Die Kanäle des Servers von lassen sich nicht laden – ist dort Mitglied? ()
@@ -115,8 +115,15 @@ include __DIR__ . '/../includes/header.php';

Der Server der verbündeten Legionen. Wer dort eine Rolle hat, kann sich auf der Website anmelden und sieht den Bereich – welche Gruppe zu welcher Rolle gehört, legst du unter - Berechtigungsgruppen fest. Der Bot muss auf dem Server sein (für die - Raids von und um zu bemerken, wer den Server verlässt). + Berechtigungsgruppen fest. + + Dort arbeitet Siel, der Bot der (Verwaltung auf + bot.lumina-ascendens.de): + Er postet die Raids von und bemerkt, wer einen der Server verlässt. + + Der Bot muss auf dem Server sein (für die Raids von und um zu bemerken, wer den + Server verlässt). +

diff --git a/admin/bot_action.php b/admin/bot_action.php index 3ae2379..17ddf35 100644 --- a/admin/bot_action.php +++ b/admin/bot_action.php @@ -84,7 +84,7 @@ try { } 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 . '.'); + : 'Server gespeichert – ' . (siel_api_config() !== null ? 'Siel ist' : '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'] ?? ''); diff --git a/admin/role_form.php b/admin/role_form.php index 37dc2bd..3834c9d 100644 --- a/admin/role_form.php +++ b/admin/role_form.php @@ -322,7 +322,7 @@ include __DIR__ . '/../includes/header.php'; -
Die Rollen des Servers von konnten nicht geladen werden () – ist der Bot dort Mitglied?
+
Die Rollen des Servers von konnten nicht geladen werden () – ist dort Mitglied?
diff --git a/bot_api.php b/bot_api.php index 083e955..142b7b9 100644 --- a/bot_api.php +++ b/bot_api.php @@ -17,7 +17,8 @@ * GET /bot_api.php?action=dues_reminders * POST /bot_api.php?action=dues_reminders_done {"results": [{"id": 1, "ok": true}, {"id": 2, "ok": false, "error": "..."}]} * - * Server verlassen (cogs/legion_members.py im Bot, includes/discord_auth.php): Es zaehlen der Server der Legion und + * Server verlassen (cogs/members.py in Siel, dem Bot der Elyos Allianz - bis 29.09.2026 cogs/legion_members.py in + * Nezekan; includes/discord_auth.php): Es zaehlen der Server der Legion und * der des Consilium Elyseum. Wer einen verlaesst (auch gekickt oder gebannt), verliert dessen Gruppen; ist er auf * keinem mehr, wird sein Konto deaktiviert, tritt er wieder bei, wartet es wieder auf Freischaltung. Dazu gleicht der * Bot regelmaessig ab, welche aktiven Konten auf keinem der Server mehr sind. Andere Server zaehlen nicht. diff --git a/config.example.php b/config.example.php index 5f4c695..96cecff 100644 --- a/config.example.php +++ b/config.example.php @@ -22,6 +22,12 @@ return [ ], // Gemeinsamer Schluessel fuer den Rueckkanal vom Bot (bot_api.php): im Bot als // WEBSITE_BOT_KEY in der .env eintragen. Mindestens 16 Zeichen, z.B. zufaellig erzeugt. + // Siel, der Bot der Elyos Allianz: postet deren Raids und kennt Kanaele/Rollen ihres Servers. Der Schluessel + // steht in /root/sielbot/.env (WEBSITE_API_KEY). Ohne diesen Block macht Nezekan (raids_api) alles wie frueher. + 'siel_api' => [ + 'url' => 'https://bot.lumina-ascendens.de/website-api/raids', + 'key' => 'schluessel-aus-siel', + ], 'bot_callback' => [ 'key' => 'langer-zufaelliger-schluessel', ], diff --git a/includes/discord_bot.php b/includes/discord_bot.php index b0b4e5e..ad94dbb 100644 --- a/includes/discord_bot.php +++ b/includes/discord_bot.php @@ -106,6 +106,18 @@ function discord_bot_post_panel(string $kind, int $channelId, array $roles = []) function discord_bot_resync_raids(): array { $data = discord_bot_request('POST', '/raids/resync'); + // Die Raids der Elyos Allianz gleicht Siel ab + if (siel_api_config() !== null) { + try { + $siel = raids_api_request('POST', '/resync', [], null, 30, 'siel'); + $data['updated'] = (int) ($data['updated'] ?? 0) + (int) ($siel['updated'] ?? 0); + $data['reposted'] = array_merge((array) ($data['reposted'] ?? []), (array) ($siel['reposted'] ?? [])); + $data['failed'] = array_merge((array) ($data['failed'] ?? []), (array) ($siel['failed'] ?? [])); + } catch (Throwable $e) { + $data['failed'] = array_merge((array) ($data['failed'] ?? []), + [['title' => 'Raids der ' . CONSILIUM_NAME, 'error' => $e->getMessage()]]); + } + } foreach ((array) ($data['reposted'] ?? []) as $moved) { raid_rename_id((int) ($moved['old'] ?? 0), (int) ($moved['new'] ?? 0)); } diff --git a/includes/events_api.php b/includes/events_api.php index b269675..c433d54 100644 --- a/includes/events_api.php +++ b/includes/events_api.php @@ -40,9 +40,14 @@ function events_api_request(string $method, string $path = '', array $queryParam */ function guilds_api_request(string $path, ?string $guildId = null): array { - $base = preg_replace('#/raids$#', '', raids_api_config()['url']); + // $guildId: ein anderer Server als der der Legion (der der Elyos Allianz) - den kennt Siel, falls eingerichtet + $siel = siel_api_config(); + if ($guildId !== null && $guildId !== (string) events_guild_id() && $siel !== null) { + $base = preg_replace('#/raids$#', '', $siel['url']); + return bot_api_request('GET', $base . '/guilds/' . $guildId . $path, [], null, 'Siel', $siel['key']); + } - // $guildId: ein anderer Server als der der Legion (der des Consilium Elyseum) + $base = preg_replace('#/raids$#', '', raids_api_config()['url']); return bot_api_request('GET', $base . '/guilds/' . ($guildId ?? events_guild_id()) . $path, [], null, 'Bot-API'); } @@ -56,7 +61,7 @@ function guilds_api_request(string $path, ?string $guildId = null): array * @return array * @throws RuntimeException */ -function bot_api_request(string $method, string $url, array $queryParams, ?array $jsonBody, string $label): array +function bot_api_request(string $method, string $url, array $queryParams, ?array $jsonBody, string $label, ?string $apiKey = null): array { if (!function_exists('curl_init')) { throw new RuntimeException('Die PHP-cURL-Erweiterung ist auf diesem Server nicht aktiviert.'); @@ -66,7 +71,7 @@ function bot_api_request(string $method, string $url, array $queryParams, ?array $url .= '?' . http_build_query($queryParams); } - $headers = ['X-API-Key: ' . raids_api_config()['key']]; + $headers = ['X-API-Key: ' . ($apiKey ?? raids_api_config()['key'])]; $ch = curl_init($url); $options = [ diff --git a/includes/raids_api.php b/includes/raids_api.php index 50b8439..b914b38 100644 --- a/includes/raids_api.php +++ b/includes/raids_api.php @@ -18,6 +18,38 @@ function bot_api_error_message(string $label, int $httpCode, $data): string return $detail !== '' ? $message . ' (' . $detail . ')' : $message; } +/** Abgelehnte Anfrage an einen Bot - mit dem HTTP-Status (404 = dieser Bot kennt den Raid nicht). */ +class BotApiException extends RuntimeException +{ + public int $httpCode; + + public function __construct(string $message, int $httpCode) + { + parent::__construct($message); + $this->httpCode = $httpCode; + } +} + +/** + * Siel, der Bot der Elyos Allianz (config.php: siel_api.url = https://bot.lumina-ascendens.de/website-api/raids, + * siel_api.key). Er postet die Raids der Elyos Allianz auf deren Discord-Server und kennt dessen Kanaele und Rollen. + * null = nicht eingerichtet - dann macht Nezekan (raids_api) weiter alles. + * + * @return array{url: string, key: string}|null + */ +function siel_api_config(): ?array +{ + static $cfg = false; + if ($cfg === false) { + $configPath = __DIR__ . '/../config.php'; + $config = file_exists($configPath) ? require $configPath : []; + $url = is_array($config) ? (string) ($config['siel_api']['url'] ?? '') : ''; + $key = is_array($config) ? (string) ($config['siel_api']['key'] ?? '') : ''; + $cfg = $url !== '' && $key !== '' ? ['url' => rtrim($url, '/'), 'key' => $key] : null; + } + return $cfg; +} + /** * @return array * @throws RuntimeException @@ -52,13 +84,18 @@ function raids_api_config(): array * @return array * @throws RuntimeException */ -function raids_api_request(string $method, string $path = '', array $queryParams = [], ?array $jsonBody = null, int $timeout = 10): array +function raids_api_request(string $method, string $path = '', array $queryParams = [], ?array $jsonBody = null, int $timeout = 10, string $backend = 'nezekan'): array { if (!function_exists('curl_init')) { throw new RuntimeException('Die PHP-cURL-Erweiterung ist auf diesem Server nicht aktiviert.'); } - $config = raids_api_config(); + // 'siel': der Bot der Elyos Allianz, sonst Nezekan (Legion) + $config = $backend === 'siel' ? siel_api_config() : raids_api_config(); + if ($config === null) { + throw new RuntimeException('Siel ist nicht eingerichtet (config.php: siel_api.url / siel_api.key fehlt).'); + } + $label = $backend === 'siel' ? 'Siel' : 'Raid-API'; $url = $config['url'] . $path; if (!empty($queryParams)) { $url .= '?' . http_build_query($queryParams); @@ -88,22 +125,102 @@ function raids_api_request(string $method, string $path = '', array $queryParams curl_close($ch); if ($response === false) { - throw new RuntimeException('Verbindung zur Raid-API fehlgeschlagen: ' . $curlError); + throw new RuntimeException('Verbindung zu ' . $label . ' fehlgeschlagen: ' . $curlError); } $data = json_decode($response, true); if ($httpCode < 200 || $httpCode >= 300) { - throw new RuntimeException(bot_api_error_message('Raid-API', $httpCode, $data)); + throw new BotApiException(bot_api_error_message($label, $httpCode, $data), $httpCode); } if (!is_array($data)) { - throw new RuntimeException('Unerwartetes Antwortformat der Raid-API.'); + throw new RuntimeException('Unerwartetes Antwortformat von ' . $label . '.'); } return $data; } +/** + * Raids beider Bots: Nezekan (Legion, aeltere Raids der Elyos Allianz) und Siel (Raids der Elyos Allianz). Jeder Raid + * bekommt "bot" ('nezekan' oder 'siel'). Ist Siel nicht erreichbar, fehlen nur dessen Raids (siel_raids_error()). + * + * @return array> + * @throws RuntimeException wenn Nezekan nicht antwortet + */ +function raids_fetch_combined(string $status, int $timeout = 10): array +{ + $data = raids_api_request('GET', '', ['status' => $status], null, $timeout); + if (($data['status'] ?? '') !== 'success' || !isset($data['raids']) || !is_array($data['raids'])) { + throw new RuntimeException('Unerwartetes Antwortformat der Raid-API.'); + } + $raids = array_map(static fn (array $raid): array => $raid + ['bot' => 'nezekan'], $data['raids']); + if (siel_api_config() !== null) { + try { + $siel = raids_api_request('GET', '', ['status' => $status], null, $timeout, 'siel'); + foreach ((array) ($siel['raids'] ?? []) as $raid) { + if (is_array($raid)) { + $raid['bot'] = 'siel'; + raid_backend_remember((int) ($raid['raid_id'] ?? 0), 'siel'); + $raids[] = $raid; + } + } + siel_raids_error(''); + } catch (Throwable $e) { + siel_raids_error($e->getMessage()); + } + usort($raids, static fn (array $a, array $b): int => (int) ($a['timestamp'] ?? 0) <=> (int) ($b['timestamp'] ?? 0)); + } + return $raids; +} + +/** Letzter Fehler beim Abruf der Raids von Siel ('' = alles gut) - lesen ohne, setzen mit Argument. */ +function siel_raids_error(?string $set = null): string +{ + static $error = ''; + if ($set !== null) { + $error = $set; + } + return $error; +} + +/** Merkt sich, welcher Bot einen Raid postet (fuer Anfragen per raid_id). Ohne Bot: lesen ('' = unbekannt). */ +function raid_backend_remember(int $raidId, ?string $backend = null): string +{ + static $known = []; + if ($backend !== null && $raidId > 0) { + $known[$raidId] = $backend; + } + return $known[$raidId] ?? ''; +} + +/** + * Anfrage zu einem bestimmten Raid - an den Bot, der ihn gepostet hat. Ist er unbekannt, zuerst Nezekan; kennt der + * gefragte Bot den Raid nicht (404), der andere. + * + * @return array + * @throws RuntimeException + */ +function raid_backend_request(int $raidId, string $method, string $path, ?array $jsonBody = null): array +{ + $order = raid_backend_remember($raidId) === 'siel' ? ['siel', 'nezekan'] : ['nezekan', 'siel']; + if (siel_api_config() === null) { + $order = ['nezekan']; + } + foreach ($order as $i => $backend) { + try { + $data = raids_api_request($method, $path, [], $jsonBody, 10, $backend); + raid_backend_remember($raidId, $backend); + return $data; + } catch (BotApiException $e) { + if ($e->httpCode !== 404 || $i === count($order) - 1) { + throw $e; + } + } + } + throw new RuntimeException('Raid nicht gefunden.'); +} + // Laengengrenzen der Raid-API (RaidCreate/RaidUpdate in api.py des Bots). const RAID_FIELD_LIMITS = [ 'title' => ['Titel', 60], @@ -138,18 +255,14 @@ function fetch_raids(string $status = 'active'): array $status = 'active'; } - $data = raids_api_request('GET', '', ['status' => $status]); - - if (($data['status'] ?? '') !== 'success' || !isset($data['raids']) || !is_array($data['raids'])) { - throw new RuntimeException('Unerwartetes Antwortformat der Raid-API.'); - } + $raids = raids_fetch_combined($status); // Die aktiven Raids stecken auch in "all" - so bleibt die Zahl in der Seitenleiste nebenbei aktuell if ($status !== 'archived') { - raids_nav_store($data['raids']); + raids_nav_store($raids); } - return raids_apply_display_names($data['raids']); + return raids_apply_display_names($raids); } // ---- Zwei Raid-Bereiche: Legion und Consilium Elyseum ---- @@ -164,9 +277,12 @@ function consilium_raid_channel(): int return (int) setting_get('consilium_raid_channel'); } -/** 'consilium' fuer Raids im Kanal der Consilium-Raids, sonst 'legion'. */ +/** 'consilium' fuer Raids von Siel und aeltere im Kanal der Consilium-Raids, sonst 'legion'. */ function raid_area(array $raid): string { + if (($raid['bot'] ?? '') === 'siel') { + return 'consilium'; + } $channel = consilium_raid_channel(); return $channel > 0 && (int) ($raid['channel_id'] ?? 0) === $channel ? 'consilium' : 'legion'; } @@ -303,10 +419,7 @@ function raids_nav_upcoming(?string $area = null): array raids_nav_cache(['fetched_at' => time(), 'raids' => $list, 'sig' => (string) ($cached['sig'] ?? ''), 'consilium' => (array) ($cached['consilium'] ?? [])]); try { - $data = raids_api_request('GET', '', ['status' => 'active'], null, 3); - if (($data['status'] ?? '') === 'success' && is_array($data['raids'] ?? null)) { - $list = raids_nav_store($data['raids']); - } + $list = raids_nav_store(raids_fetch_combined('active', 3)); } catch (Throwable $e) { // Bot nicht erreichbar oder nicht eingerichtet - dann eben der letzte Stand } @@ -408,7 +521,7 @@ function raids_apply_display_names(array $raids): array /** @throws RuntimeException */ function archive_raid(int $raidId): void { - raids_api_request('DELETE', '/' . $raidId); + raid_backend_request($raidId, 'DELETE', '/' . $raidId); } /** @@ -420,7 +533,7 @@ function archive_raid(int $raidId): void */ function restore_raid(int $raidId): int { - $data = raids_api_request('POST', '/' . $raidId . '/restore'); + $data = raid_backend_request($raidId, 'POST', '/' . $raidId . '/restore'); return (int) ($data['raid_id'] ?? $raidId) ?: $raidId; } @@ -432,7 +545,7 @@ function restore_raid(int $raidId): int */ function delete_raid_permanently(int $raidId): void { - raids_api_request('DELETE', '/' . $raidId . '/permanent'); + raid_backend_request($raidId, 'DELETE', '/' . $raidId . '/permanent'); } /** @@ -447,7 +560,7 @@ function delete_raid_permanently(int $raidId): void */ function raid_signup(int $raidId, int $discordId, string $discordName, string $className, ?int $wish = null): array { - $data = raids_api_request('POST', '/' . $raidId . '/signup', [], [ + $data = raid_backend_request($raidId, 'POST', '/' . $raidId . '/signup', [ 'user_id' => $discordId, 'name' => $discordName, 'class' => $className, @@ -468,13 +581,13 @@ function raid_signup(int $raidId, int $discordId, string $discordName, string $c */ function raid_decline(int $raidId, int $discordId, string $name): void { - raids_api_request('POST', '/' . $raidId . '/signup/' . $discordId . '/decline', [], ['name' => $name]); + raid_backend_request($raidId, 'POST', '/' . $raidId . '/signup/' . $discordId . '/decline', ['name' => $name]); } /** @throws RuntimeException */ function move_signup(int $raidId, int $discordId, int $group): void { - raids_api_request('PATCH', '/' . $raidId . '/signup/' . $discordId, [], ['group' => $group]); + raid_backend_request($raidId, 'PATCH', '/' . $raidId . '/signup/' . $discordId, ['group' => $group]); } /** @@ -488,12 +601,13 @@ function move_signup(int $raidId, int $discordId, int $group): void */ function update_raid(int $raidId, array $fields): array { - return raids_api_request('PATCH', '/' . $raidId, [], $fields); + return raid_backend_request($raidId, 'PATCH', '/' . $raidId, $fields); } /** * Erstellt einen neuen Raid ueber den in config.php (raids_api.guild_id) hinterlegten * Discord-Server. Der Bot postet ihn in den Raid-Kanal dieses Servers (Verwaltung -> Discord-Bot). + * Raids der Elyos Allianz postet Siel (siel_api_config()), sonst - wie frueher - Nezekan. * * @param array $fields title, date_raw, requirements, group_names * (Pflicht), max_slots, gearscore, lead_id, lead_name, points_text (optional) @@ -522,7 +636,11 @@ function create_raid(array $fields, string $area = 'legion'): array $fields['guild_id'] = (int) $guildId; - return raids_api_request('POST', '', [], $fields); + // Raids der Elyos Allianz postet Siel (auf deren Server), sobald er eingerichtet ist + $backend = $area === 'consilium' && siel_api_config() !== null ? 'siel' : 'nezekan'; + $data = raids_api_request('POST', '', [], $fields, 10, $backend); + raid_backend_remember((int) ($data['raid_id'] ?? 0), $backend); + return $data; } /** @throws RuntimeException */ diff --git a/raid_create_action.php b/raid_create_action.php index 624c901..16f4dcd 100644 --- a/raid_create_action.php +++ b/raid_create_action.php @@ -52,6 +52,9 @@ if ($area === 'consilium') { } // Feste Premades, die direkt einer Gruppe zugeordnet werden (Gruppe => Premade-ID). +if ($area === 'consilium' && !empty($input['premades'])) { + json_response(false, 'Premades gibt es nur bei Raids der Legion.'); +} $premadeChoices = []; foreach ((array) ($input['premades'] ?? []) as $choice) { $group = (int) ($choice['group'] ?? 0); diff --git a/raid_premade_invite_action.php b/raid_premade_invite_action.php index f2738e8..9f1e45e 100644 --- a/raid_premade_invite_action.php +++ b/raid_premade_invite_action.php @@ -14,6 +14,9 @@ $group = (int) ($input['group'] ?? 0); if ($raidId <= 0 || $premadeId <= 0 || $group <= 0) { json_response(false, 'Bitte Premade und Zielgruppe auswählen.'); } +if (raid_area_of($raidId) === 'consilium') { + json_response(false, 'Premades gibt es nur bei Raids der Legion.'); +} // Die Leitung in jeden Raid, der Raid-Lead in seinen eigenen if (!raid_can_manage($raidId)) { http_response_code(403); diff --git a/raids.php b/raids.php index 13afa43..8d2947d 100644 --- a/raids.php +++ b/raids.php @@ -75,7 +75,8 @@ if ($apiError === null && $status !== 'archived' && raid_sync_extras($raids, $ra // Premades fuer das Anlegen und fuers Einladen in eigene (Raid-Lead) bzw. alle Raids (Leitung) $premades = []; -if ($canCreateRaids) { +// Premades gibt es nur in der Legion - nicht bei den Raids der Elyos Allianz +if ($canCreateRaids && $area !== 'consilium') { try { $premades = fetch_premades(); } catch (Throwable $e) {