LuminaWebsite/activity_action.php
Maaxxs 392994e1cd Activity check (website + bot), videos in the wiki, contributor search list
- Activity check: created on the website (activity.php, activity.manage) or with /aktivitaetscheck; the bot posts "I'm in" / "I'm out" buttons; title, text, color, image and button labels are configurable with a live preview; deadline; consequences for non-responders (DM, remove/add role, optionally also for "I'm out"); close early or cancel; overview of in / out / pending
- Wiki: a video link alone on a line (YouTube incl. Shorts/start time, Twitch, Vimeo, .mp4/.webm) becomes an embedded player, plus a "Video" button in the editor
- Wiki: "Add contributor" as a search list with avatar, group and class instead of a dropdown

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 01:11:49 +02:00

111 lines
5.5 KiB
PHP

<?php
/**
* Aktivitaetschecks anlegen, abschliessen, abbrechen, loeschen - weitergereicht an den Bot.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/activity_api.php';
require_permission('activity.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/activity.php');
}
verify_csrf();
$action = (string) ($_POST['action'] ?? '');
$id = (int) ($_POST['id'] ?? 0);
$me = current_user();
$myName = $me['display_name'] !== '' ? $me['display_name'] : $me['username'];
/** Ganze Zahl aus einem ID-Feld (Discord-IDs sind 17-20 Stellen), null wenn leer. */
$idField = static function (string $name): ?int {
$value = trim((string) ($_POST[$name] ?? ''));
return preg_match('/^\d{5,20}$/', $value) ? (int) $value : null;
};
try {
switch ($action) {
case 'create':
$title = trim((string) ($_POST['title'] ?? ''));
$message = trim(str_replace("\r\n", "\n", (string) ($_POST['message'] ?? '')));
$channelId = $idField('channel_id');
$roleId = $idField('target_role_id');
$value = max(1, min(60, (int) ($_POST['duration_value'] ?? 3)));
$minutes = ($_POST['duration_unit'] ?? 'days') === 'hours' ? $value * 60 : $value * 1440;
// Farbe: eigene Farbe gewinnt, wenn sie von der Auswahl abweicht
$color = (string) ($_POST['color'] ?? '#c9a227');
$custom = (string) ($_POST['color_custom'] ?? '');
if (preg_match('/^#[0-9a-f]{6}$/i', $custom) && strtolower($custom) !== '#c9a227') {
$color = $custom;
}
$image = trim((string) ($_POST['image_url'] ?? ''));
if ($title === '' || $message === '' || $channelId === null || $roleId === null) {
throw new InvalidArgumentException('Bitte Titel, Nachricht, Kanal und Zielrolle ausfüllen.');
}
if ($image !== '' && !preg_match('#^https://\S+$#', $image)) {
throw new InvalidArgumentException('Das Bild muss ein https-Link sein.');
}
$dmEnabled = !empty($_POST['dm_enabled']);
$body = [
'guild_id' => events_guild_id(),
'channel_id' => $channelId,
'target_role_id' => $roleId,
'title' => mb_substr($title, 0, 100),
'message' => mb_substr($message, 0, 3500),
'color' => preg_match('/^#[0-9a-f]{6}$/i', $color) ? hexdec(substr($color, 1)) : 0xC9A227,
'image_url' => $image !== '' ? $image : null,
'ping_role' => !empty($_POST['ping_role']),
'yes_label' => mb_substr(trim((string) ($_POST['yes_label'] ?? '')), 0, 60) ?: null,
'no_label' => mb_substr(trim((string) ($_POST['no_label'] ?? '')), 0, 60) ?: null,
'duration_minutes' => $minutes,
'dm_enabled' => $dmEnabled,
'dm_message' => $dmEnabled ? mb_substr(trim((string) ($_POST['dm_message'] ?? '')), 0, 1800) : null,
'remove_role_id' => $idField('remove_role_id'),
'add_role_id' => $idField('add_role_id'),
'apply_to_absent' => !empty($_POST['apply_to_absent']),
'created_by' => (int) ($me['discord_id'] ?? 0),
];
$result = activity_api_request('POST', '', [], $body);
$consequences = array_filter([
$dmEnabled ? 'PN' : null,
$body['remove_role_id'] ? 'Rolle entfernen' : null,
$body['add_role_id'] ? 'Rolle geben' : null,
]);
admin_log('📋 Aktivitätscheck gestartet', [
'Titel' => $body['title'],
'Dauer' => $minutes >= 1440 ? ($minutes / 1440) . ' Tage' : ($minutes / 60) . ' Stunden',
'Folgen' => $consequences ? implode(', ', $consequences) : 'keine',
], 'info', 'events');
set_flash('success', 'Aktivitätscheck gepostet - die Leute können sich jetzt im Discord zurückmelden.');
redirect('/activity.php?id=' . (int) ($result['check_id'] ?? 0));
case 'close':
case 'cancel':
$result = activity_api_request('POST', '/' . $id . '/close', [], [
'cancel' => $action === 'cancel',
'closed_by' => $myName . ' (Website)',
])['result'] ?? [];
admin_log($action === 'cancel' ? '🚫 Aktivitätscheck abgebrochen' : '📋 Aktivitätscheck abgeschlossen', [
'Check' => '#' . $id,
'Ohne Rückmeldung' => $action === 'cancel' ? '' : (string) count($result['missing'] ?? []),
], $action === 'cancel' ? 'warning' : 'success', 'events');
set_flash('success', $action === 'cancel'
? 'Aktivitätscheck abgebrochen - ohne Folgen.'
: 'Aktivitätscheck abgeschlossen. Ohne Rückmeldung: ' . count($result['missing'] ?? []) . '.');
redirect('/activity.php?id=' . $id);
case 'delete':
activity_api_request('DELETE', '/' . $id);
admin_log('🗑️ Aktivitätscheck gelöscht', ['Check' => '#' . $id], 'warning', 'events');
set_flash('success', 'Aktivitätscheck gelöscht.');
redirect('/activity.php');
}
} catch (InvalidArgumentException $e) {
set_flash('error', $e->getMessage());
redirect('/activity.php');
} catch (Throwable $e) {
set_flash('error', 'Der Discord-Bot hat nicht mitgespielt: ' . $e->getMessage());
redirect($id > 0 ? '/activity.php?id=' . $id : '/activity.php');
}
redirect('/activity.php');