prepare('SELECT * FROM tbl_scwebhooks WHERE cl_scwebhook_id = :id LIMIT 1'); $stmt_webhook->execute(['id' => $cl_scnotification_webhook_id]); $webhook = $stmt_webhook->fetch(); if (!$webhook) { auth_flash_set('error', 'Webhook Discord introuvable.'); header('Location: scnotification.php'); exit; } foreach ([ 'URL canal Discord' => [$show_channel_url, $cl_scnotification_channel_url], 'URL inventaire' => [$show_inventory_url, $cl_scnotification_inventory_url], 'URL source' => [$show_source_url, $cl_scnotification_source_url], 'Icône du footer' => [$show_footer && $cl_scnotification_footer_icon_url !== '', $cl_scnotification_footer_icon_url], ] as $label => [$enabled, $value]) { if ($enabled && $value !== '' && !filter_var($value, FILTER_VALIDATE_URL)) { auth_flash_set('error', $label . ' invalide.'); header('Location: scnotification.php'); exit; } } $mentions = scdiscord_build_mentions($notify_here, $notify_everyone); $banner_image_url = (string) ($webhook['cl_scwebhook_image_url'] ?? ''); $border_color = (string) ($webhook['cl_scwebhook_border_color'] ?? '#ffae00'); $fields = []; if ($show_org && $cl_scnotification_org_value !== '' && mb_strtolower($cl_scnotification_org_value) !== 'non') { $fields[] = [ 'name' => 'Tenue d’organisation', 'value' => mb_substr($cl_scnotification_org_value, 0, 1024), 'inline' => true, ]; } if ($show_pvp && $cl_scnotification_pvp_value !== '' && mb_strtolower($cl_scnotification_pvp_value) !== 'inexistant') { $fields[] = [ 'name' => 'Risques PvP', 'value' => mb_substr($cl_scnotification_pvp_value, 0, 1024), 'inline' => true, ]; } if ($include_schedule) { if ($cl_scnotification_location !== '') { $fields[] = ['name' => 'Lieu de ralliement', 'value' => mb_substr($cl_scnotification_location, 0, 1024), 'inline' => false]; } if ($cl_scnotification_start_date !== '') { $fields[] = ['name' => 'Date de début', 'value' => mb_substr($cl_scnotification_start_date, 0, 1024), 'inline' => true]; } if ($cl_scnotification_departure_time !== '') { $fields[] = ['name' => 'Heure de départ', 'value' => mb_substr($cl_scnotification_departure_time, 0, 1024), 'inline' => true]; } if ($include_briefing_time && $cl_scnotification_briefing_time !== '') { $fields[] = ['name' => 'Heure de briefing', 'value' => mb_substr($cl_scnotification_briefing_time, 0, 1024), 'inline' => true]; } if ($include_end_date && $cl_scnotification_end_date !== '') { $fields[] = ['name' => 'Date de fin', 'value' => mb_substr($cl_scnotification_end_date, 0, 1024), 'inline' => true]; } if ($include_end_time && $cl_scnotification_end_time !== '') { $fields[] = ['name' => 'Heure de fin', 'value' => mb_substr($cl_scnotification_end_time, 0, 1024), 'inline' => true]; } } if ($show_channel_url && $cl_scnotification_channel_url !== '') { $fields[] = ['name' => 'Canal Discord', 'value' => '[Ouvrir le canal](' . $cl_scnotification_channel_url . ')', 'inline' => false]; } if ($show_inventory_url && $cl_scnotification_inventory_url !== '') { $fields[] = ['name' => 'Inventaire A.R.I.A', 'value' => '[Consulter l’inventaire](' . $cl_scnotification_inventory_url . ')', 'inline' => false]; } if ($show_source_url && $cl_scnotification_source_url !== '') { $fields[] = ['name' => 'Source', 'value' => '[Ouvrir la source](' . $cl_scnotification_source_url . ')', 'inline' => false]; } $embed = [ 'description' => mb_substr($cl_scnotification_message, 0, 4096), 'color' => scdiscord_hex_to_decimal($border_color), ]; if ($cl_scnotification_title !== '') { $embed['title'] = mb_substr($cl_scnotification_title, 0, 256); } if (!empty($fields)) { $embed['fields'] = $fields; } if ($banner_image_url !== '') { $embed['image'] = ['url' => $banner_image_url]; } if ($show_footer && ($cl_scnotification_footer_text !== '' || $cl_scnotification_footer_icon_url !== '')) { $embed['footer'] = []; if ($cl_scnotification_footer_text !== '') { $embed['footer']['text'] = mb_substr($cl_scnotification_footer_text, 0, 2048); } if ($cl_scnotification_footer_icon_url !== '') { $embed['footer']['icon_url'] = $cl_scnotification_footer_icon_url; } } $payload = [ 'embeds' => [$embed], ]; if (!empty($mentions)) { $payload['content'] = implode(' ', $mentions); $payload['allowed_mentions'] = ['parse' => ['everyone']]; } $thread_name = $show_thread ? ('Discussion - ' . scdiscord_build_thread_name( $cl_scnotification_title, $cl_scnotification_location, $cl_scnotification_start_date )) : ''; $result = scdiscord_post_webhook((string) $webhook['cl_scwebhook_url'], $payload); $bot_actions = [ 'success' => true, 'http_code' => 200, 'response' => 'Aucune action bot demandée.', ]; if (!empty($result['success']) && ($show_reactions || $show_thread)) { $message_data = scdiscord_decode_json_response((string) ($result['response'] ?? '')); $bot_actions = scdiscord_apply_bot_actions($message_data, $show_reactions, $show_thread, $thread_name); } $log_response = json_encode([ 'webhook' => [ 'success' => !empty($result['success']), 'http_code' => (int) ($result['http_code'] ?? 0), 'response' => (string) ($result['response'] ?? ''), ], 'bot_actions' => [ 'success' => !empty($bot_actions['success']), 'http_code' => (int) ($bot_actions['http_code'] ?? 0), 'response' => (string) ($bot_actions['response'] ?? ''), 'details' => $bot_actions['details'] ?? [], ], ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $stmt_log = $db->prepare( 'INSERT INTO tbl_scnotifications ( cl_scnotification_webhook_id, cl_scnotification_title, cl_scnotification_message, cl_scnotification_payload, cl_scnotification_response, cl_scnotification_success, cl_scnotification_created_by ) VALUES ( :webhook_id, :title, :message, :payload, :response, :success, :created_by )' ); $stmt_log->execute([ 'webhook_id' => $cl_scnotification_webhook_id, 'title' => $cl_scnotification_title, 'message' => $cl_scnotification_message, 'payload' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 'response' => $log_response !== false ? $log_response : (string) ($result['response'] ?? ''), 'success' => (!empty($result['success']) && !empty($bot_actions['success'])) ? 1 : 0, 'created_by' => $current_session_user !== '' ? $current_session_user : 'Inconnu', ]); if (empty($result['success'])) { auth_flash_set('error', 'Échec de l’envoi Discord (HTTP ' . (int) ($result['http_code'] ?? 0) . ').'); } elseif (empty($bot_actions['success'])) { auth_flash_set('error', 'Notification envoyée, mais échec des actions bot Discord : ' . (string) ($bot_actions['response'] ?? 'Erreur inconnue.')); } else { unset($_SESSION['scnotification_old']); auth_flash_set('success', 'Notification Discord envoyée avec succès.'); } header('Location: scnotification.php'); exit; } } $old = $_SESSION['scnotification_old'] ?? []; unset($_SESSION['scnotification_old']); $stmt_webhooks = $db->query('SELECT * FROM tbl_scwebhooks ORDER BY cl_scwebhook_name ASC'); $webhooks = $stmt_webhooks->fetchAll(); function scnotification_old_value(array $old, string $key, string $default = ''): string { $value = $old[$key] ?? $default; return is_string($value) ? $value : $default; } function scnotification_old_checked(array $old, string $key, bool $default = false): bool { if (empty($old)) { return $default; } return array_key_exists($key, $old); } ?> SC Notification | R.E.A.C.T. Admin

R.E.A.C.T. SC Notification

Niveau d'accès :

Envoi d'une notification sur Discord

Canal de notification

Prévisualisation et Couleur

L’image de prévisualisation et la couleur de bordure sont maintenant prises automatiquement depuis le canal Discord sélectionné. Pour les modifier, va dans la page de configuration Discord du webhook correspondant.

Message

2500 caractères restants

Options Footer

Réactions & Fils

Tenue d'organisation & PvP

Lieu, Date et Heure

URL externes