LuminaWebsite/raid_premade_invite_action.php
2026-09-30 08:59:00 +02:00

67 lines
2.7 KiB
PHP
Raw Permalink 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
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raids_api.php';
require_once __DIR__ . '/includes/raid_attendance.php';
require_login();
$input = read_json_body();
verify_csrf_token($input['csrf_token'] ?? '');
$raidId = (int) ($input['raid_id'] ?? 0);
$premadeId = (int) ($input['premade_id'] ?? 0);
$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);
json_response(false, 'In diesen Raid darfst du keine Premade einladen.');
}
// Versteckte Premades laden nur ihre eigenen Leute und die Leitung ein - fuer alle anderen gibt es sie nicht
try {
foreach (fetch_premades() as $p) {
if ((int) ($p['id'] ?? 0) === $premadeId && !premade_visible_to($p, (int) (current_user()['discord_id'] ?? 0))) {
json_response(false, 'Diese Premade gibt es nicht (mehr) - bitte die Seite neu laden.');
}
}
} catch (RuntimeException $e) {
// Bot nicht erreichbar - dann scheitert gleich auch das Einladen mit einer Meldung
}
try {
// Name und Mitglieder der Premade sowie der Gruppenname fuers Audit-Log (vor dem Umbenennen)
$premadeName = '#' . $premadeId;
$premadeMembers = [];
$raidBefore = null;
try {
foreach (fetch_premades() as $p) {
if ((int) ($p['id'] ?? 0) === $premadeId) {
$premadeName = (string) ($p['name'] ?? $premadeName);
foreach ($p['members'] ?? [] as $m) {
if (($m['status'] ?? '') === 'accepted') {
$premadeMembers[] = (string) ($m['name'] ?? admin_log_discord_name((string) ($m['user_id'] ?? '')));
}
}
}
}
$raidBefore = fetch_raid_by_id($raidId);
} catch (Throwable $e) {
// nur fuers Log
}
$count = invite_premade($raidId, $premadeId, $group);
admin_log('🤝 Premade zum Raid eingeladen', [
'Raid' => admin_log_raid($raidId),
'Premade' => $premadeName,
'Zielgruppe' => admin_log_raid_group($raidBefore, $group) . ' – umbenannt und gesperrt',
'Eingeladen' => $count . ' Mitglied(er) per DM',
'Mitglieder' => implode(', ', $premadeMembers),
]);
json_response(true, $count . ' Mitglied(er) wurden per DM eingeladen, die Gruppe ist jetzt gesperrt.');
} catch (Throwable $e) {
json_response(false, 'Einladen fehlgeschlagen: ' . $e->getMessage());
}