The bot API now lets the website create raids without knowing a
Discord channel: POST /api/raids accepts guild_id and resolves the
target channel via the server's /set_raidchannel default. Adds a
"+ Neuer Raid" panel on raids.php (raids.manage only) with the same
title/date/max slots/gearscore grid and requirements textarea as the
edit form, plus the group-name row editor reused without its lock
toggle (data-locks="0" on .group-editor, since creation doesn't
support locked_groups) - one shared component instead of a second
implementation. Needs raids_api.guild_id in config.php, documented in
README.md.
Also updates the editor's "Speichern" flow for the API's other
change: PATCH /api/raids/{id} now auto-reposts the Discord message
(via sync_raid_message) if it was deleted manually, returning the new
raid_id. update_raid() now returns the API response instead of
discarding it, and raid_edit_action.php surfaces a distinct message
when the id changed - the page reload right after already picks up
the new id either way, since it re-fetches the raid list fresh.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/raids_api.php';
|
|
require_permission('raids.manage');
|
|
|
|
$input = read_json_body();
|
|
verify_csrf_token($input['csrf_token'] ?? '');
|
|
|
|
$raidId = (int) ($input['raid_id'] ?? 0);
|
|
if ($raidId <= 0) {
|
|
json_response(false, 'Ungültige Anfrage.');
|
|
}
|
|
|
|
$fields = [];
|
|
foreach (['title', 'date_raw', 'requirements', 'gearscore', 'group_names'] as $key) {
|
|
if (isset($input[$key]) && trim((string) $input[$key]) !== '') {
|
|
$fields[$key] = trim((string) $input[$key]);
|
|
}
|
|
}
|
|
if (isset($input['max_slots']) && is_numeric($input['max_slots'])) {
|
|
$fields['max_slots'] = (int) $input['max_slots'];
|
|
}
|
|
if (isset($input['locked_groups']) && is_array($input['locked_groups'])) {
|
|
$fields['locked_groups'] = array_values(array_map('intval', $input['locked_groups']));
|
|
}
|
|
|
|
if (empty($fields)) {
|
|
json_response(false, 'Keine Änderungen übermittelt.');
|
|
}
|
|
|
|
try {
|
|
$result = update_raid($raidId, $fields);
|
|
$newRaidId = (int) ($result['raid_id'] ?? $raidId);
|
|
|
|
// Die API postet die Discord-Nachricht automatisch neu, falls sie zwischenzeitlich
|
|
// manuell geloescht wurde - die raid_id (= Discord-Message-ID) aendert sich dann.
|
|
if ($newRaidId !== $raidId) {
|
|
json_response(true, 'Raid wurde aktualisiert. Die Discord-Nachricht war nicht mehr auffindbar und wurde neu gepostet.', ['raid_id' => $newRaidId]);
|
|
} else {
|
|
json_response(true, 'Raid wurde aktualisiert.', ['raid_id' => $newRaidId]);
|
|
}
|
|
} catch (Throwable $e) {
|
|
json_response(false, 'Speichern fehlgeschlagen: ' . $e->getMessage());
|
|
}
|