$reply .= "• Xphere 블록체인 (Chain ID: 20250217)\n"; $reply .= "• TVL: $12.4M | 거래량: $2.5M"; break; case '/price': case '/price@xpsnewsbot': $reply = "💰 XP 토큰 실시간 정보\n\n"; $reply .= "💵 현재가: $0.000012 USD\n"; $reply .= "📈 24시간 변동: +2.34%\n"; $reply .= "📊 시가총액: $1.2M\n"; $reply .= "💧 유동성: $245K\n\n"; $reply .= "🔗 거래하기: XpSwap DEX\n"; $reply .= "📋 차트: CoinMarketCap ID: 36056"; break; case '/community': case '/community@xpsnewsbot': $reply = "🌐 XPS 커뮤니티 네트워크\n\n"; $reply .= "💬 텔레그램 커뮤니티\n"; $reply .= "🐦 트위터 (X)\n"; $reply .= "📝 공식 블로그\n"; $reply .= "📰 뉴스 포털\n\n"; $reply .= "🔗 메인 사이트:\n"; $reply .= "• trendy.storydot.kr\n"; $reply .= "• XpSwap DEX"; break; case '/latest': case '/latest@xpsnewsbot': global $wpdb; $latest_posts = $wpdb->get_results(" SELECT p.ID, p.post_title, p.post_date FROM {$wpdb->posts} p INNER JOIN {$wpdb->term_relationships} tr ON p.ID = tr.object_id WHERE tr.term_taxonomy_id = 4197 AND p.post_status = 'publish' ORDER BY p.post_date DESC LIMIT 5 "); $reply = "📰 최신 XPS 뉴스 (TOP 5)\n\n"; if ($latest_posts) { foreach ($latest_posts as $post) { $date = date('m/d H:i', strtotime($post->post_date)); $url = get_permalink($post->ID); $title = mb_substr($post->post_title, 0, 40) . (mb_strlen($post->post_title) > 40 ? '...' : ''); $reply .= "📝 {$title}\n"; $reply .= "📅 {$date}\n\n"; } $reply .= "🔗 전체 XPS 뉴스"; } else { $reply .= "📭 아직 발행된 뉴스가 없습니다."; } break; default: if (strpos($command, '/') === 0) { $reply = "❓ 알 수 없는 명령어입니다.\n\n"; $reply .= "사용 가능한 명령어:\n"; $reply .= "/start - 시작하기\n"; $reply .= "/status - 시스템 상태\n"; $reply .= "/docs - 기술 문서\n"; $reply .= "/community - 커뮤니티\n"; $reply .= "/latest - 최신 뉴스\n\n"; $reply .= "💡 /start를 입력하면 전체 명령어를 볼 수 있습니다."; } else { return false; } } return $reply; } // 웹훅 핸들러 수정 (명령어 처리 추가) function xps_telegram_webhook_handler_fixed() { if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); exit('Method Not Allowed'); } $input = file_get_contents('php://input'); if (empty($input)) { http_response_code(200); exit('OK'); } $update = json_decode($input, true); if (!$update || !isset($update['message'])) { http_response_code(200); exit('OK'); } $message = $update['message']; $chat_id = $message['chat']['id']; $text = isset($message['text']) ? $message['text'] : ''; // 로그 기록 error_log("XPS Telegram: 메시지 수신 - Chat: {$chat_id}, Text: {$text}"); // 명령어 처리 if (!empty($text) && strpos($text, '/') === 0) { $reply = xps_telegram_process_command($text, $chat_id); if ($reply) { $bot_token = get_option('xps_telegram_bot_token'); $url = "https://api.telegram.org/bot{$bot_token}/sendMessage"; $post_data = array( 'chat_id' => $chat_id, 'text' => $reply, 'parse_mode' => 'HTML', 'disable_web_page_preview' => false ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); error_log("XPS Telegram: 응답 전송 - HTTP {$http_code}"); } } http_response_code(200); exit('OK'); } // 기존 웹훅 핸들러 대체 remove_action('init', 'xps_telegram_webhook_handler'); add_action('init', function() { if (isset($_GET['xps_telegram_webhook'])) { xps_telegram_webhook_handler_fixed(); } }); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); exit('Method Not Allowed'); } $input = file_get_contents('php://input'); if (empty($input)) { http_response_code(200); exit('OK'); } $update = json_decode($input, true); if (!$update) { http_response_code(200); exit('OK'); } // 채팅 ID 자동 캡처 xps_telegram_capture_chat_id($update); // 메시지 처리 if (isset($update['message'])) { $message = $update['message']; $chat_id = $message['chat']['id']; $text = isset($message['text']) ? $message['text'] : ''; error_log("XPS Telegram: 메시지 처리 - Chat: {$chat_id}, Text: {$text}"); // 명령어 처리 if (!empty($text) && strpos($text, '/') === 0) { $reply = xps_telegram_process_command_fixed($text, $chat_id); if ($reply) { $bot_token = get_option('xps_telegram_bot_token'); $url = "https://api.telegram.org/bot{$bot_token}/sendMessage"; $post_data = array( 'chat_id' => $chat_id, 'text' => $reply, 'parse_mode' => 'HTML', 'disable_web_page_preview' => false ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); error_log("XPS Telegram: 명령어 응답 전송 - HTTP {$http_code}"); } } } http_response_code(200); exit('OK'); } // 기존 웹훅 핸들러 완전 대체 remove_all_actions('init'); add_action('init', function() { if (isset($_GET['xps_telegram_webhook'])) { xps_telegram_webhook_handler_with_capture(); } }); ?> 전력수요 보관 - TrendyNews