diff --git a/assets/pasted-20260409-011806-1d0a77ea.png b/assets/pasted-20260409-011806-1d0a77ea.png new file mode 100644 index 0000000..f1d9076 Binary files /dev/null and b/assets/pasted-20260409-011806-1d0a77ea.png differ diff --git a/db/scdiscord.php b/db/scdiscord.php index 8a894f5..b0943af 100644 --- a/db/scdiscord.php +++ b/db/scdiscord.php @@ -393,30 +393,32 @@ function scdiscord_apply_bot_actions(array $message_data, bool $use_reactions, b } $details = []; - $failed = false; $last_http_code = 200; + $failed = false; if ($use_reactions) { foreach (['👍', '⌛', '❔', '👎'] as $emoji) { $url = 'https://discord.com/api/v10/channels/' . rawurlencode($channel_id) . '/messages/' . rawurlencode($message_id) . '/reactions/' . rawurlencode($emoji) . '/@me'; $result = scdiscord_bot_request('PUT', $url, $bot_token); + $action_success = !empty($result['success']); + $last_http_code = (int) ($result['http_code'] ?? $last_http_code); $details[] = [ 'action' => 'reaction', 'emoji' => $emoji, - 'success' => !empty($result['success']), - 'http_code' => (int) ($result['http_code'] ?? 0), + 'success' => $action_success, + 'http_code' => $last_http_code, 'response' => (string) ($result['response'] ?? ''), ]; - $last_http_code = (int) ($result['http_code'] ?? $last_http_code); - if (empty($result['success'])) { + + if (!$action_success) { $failed = true; - break; } - usleep(300000); + + sleep(1); } } - if (!$failed && $use_publicthread) { + if ($use_publicthread) { $thread_payload = [ 'name' => $thread_name !== '' ? $thread_name : 'Discussion - Opération', 'auto_archive_duration' => 1440, @@ -424,14 +426,16 @@ function scdiscord_apply_bot_actions(array $message_data, bool $use_reactions, b ]; $url = 'https://discord.com/api/v10/channels/' . rawurlencode($channel_id) . '/messages/' . rawurlencode($message_id) . '/threads'; $result = scdiscord_bot_request('POST', $url, $bot_token, $thread_payload); + $action_success = !empty($result['success']); + $last_http_code = (int) ($result['http_code'] ?? $last_http_code); $details[] = [ 'action' => 'thread', - 'success' => !empty($result['success']), - 'http_code' => (int) ($result['http_code'] ?? 0), + 'success' => $action_success, + 'http_code' => $last_http_code, 'response' => (string) ($result['response'] ?? ''), ]; - $last_http_code = (int) ($result['http_code'] ?? $last_http_code); - if (empty($result['success'])) { + + if (!$action_success) { $failed = true; } } diff --git a/scnotification.php b/scnotification.php index db7467c..850292f 100644 --- a/scnotification.php +++ b/scnotification.php @@ -32,20 +32,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_SESSION['scnotification_old'] = $_POST; $action = (string) ($_POST['action'] ?? ''); - if ($action === 'send_notification') { + $is_legacy_send = $action === '' && (isset($_POST['description']) || isset($_POST['title']) || isset($_POST['webhook_choice'])); + if ($action === 'send_notification' || $is_legacy_send) { + $legacy_webhook_choice = trim((string) ($_POST['webhook_choice'] ?? '')); $cl_scnotification_webhook_id = (int) ($_POST['cl_scnotification_webhook_id'] ?? 0); + if ($cl_scnotification_webhook_id <= 0 && preg_match('/^notif(\d+)$/', $legacy_webhook_choice, $matches)) { + $cl_scnotification_webhook_id = (int) $matches[1]; + } + $cl_scnotification_banner_id = (int) ($_POST['cl_scnotification_banner_id'] ?? 0); - $use_custom_banner = isset($_POST['cl_scnotification_use_custom_banner']); - $cl_scnotification_custom_banner_url = trim((string) ($_POST['cl_scnotification_custom_banner_url'] ?? '')); - $notify_here = isset($_POST['cl_scnotification_notify_here']); - $notify_everyone = isset($_POST['cl_scnotification_notify_everyone']); - $cl_scnotification_title = trim((string) ($_POST['cl_scnotification_title'] ?? '')); - $cl_scnotification_message = trim((string) ($_POST['cl_scnotification_message'] ?? '')); + $use_custom_banner = isset($_POST['cl_scnotification_use_custom_banner']) || isset($_POST['use_custom_banner']); + $cl_scnotification_custom_banner_url = trim((string) ($_POST['cl_scnotification_custom_banner_url'] ?? ($_POST['custom_banner'] ?? ''))); + $notify_here = isset($_POST['cl_scnotification_notify_here']) || isset($_POST['ping_here']); + $notify_everyone = isset($_POST['cl_scnotification_notify_everyone']) || isset($_POST['ping_everyone']); + $cl_scnotification_title = trim((string) ($_POST['cl_scnotification_title'] ?? ($_POST['title'] ?? ''))); + $cl_scnotification_message = trim((string) ($_POST['cl_scnotification_message'] ?? ($_POST['description'] ?? ''))); $show_footer = isset($_POST['cl_scnotification_show_footer']); $cl_scnotification_footer_text = trim((string) ($_POST['cl_scnotification_footer_text'] ?? '')); $cl_scnotification_footer_icon_url = trim((string) ($_POST['cl_scnotification_footer_icon_url'] ?? '')); - $show_reactions = isset($_POST['cl_scnotification_show_reactions']); - $show_thread = isset($_POST['cl_scnotification_show_thread']); + $show_reactions = isset($_POST['cl_scnotification_show_reactions']) || isset($_POST['use_reactions']); + $show_thread = isset($_POST['cl_scnotification_show_thread']) || isset($_POST['use_publicthread']); $show_org = isset($_POST['cl_scnotification_show_org']); $cl_scnotification_org_value = trim((string) ($_POST['cl_scnotification_org_value'] ?? '')); $show_pvp = isset($_POST['cl_scnotification_show_pvp']);