@@ -323,40 +323,49 @@ namespace cqhttp::plugins {
323323 }
324324
325325 void Http::hook_after_event (EventContext<cq::Event> &ctx) {
326- if (!post_url_.empty ()) {
327- logging::debug (TAG, u8" 开始通过 HTTP 上报事件" );
328- const auto resp = post_json (post_url_, ctx.data , secret_, post_timeout_);
326+ if (post_url_.empty ()) {
327+ ctx.next ();
328+ return ;
329+ }
330+ if (ctx.data [" post_type" ] == " meta_event" && ctx.data [" meta_event_type" ] == " lifecycle"
331+ && ctx.data [" _post_method" ] != static_cast <int >(LifecycleMetaEvent::_PostMethod::ALL)
332+ && ctx.data [" _post_method" ] != static_cast <int >(LifecycleMetaEvent::_PostMethod::HTTP)) {
333+ ctx.next ();
334+ return ;
335+ }
336+
337+ logging::debug (TAG, u8" 开始通过 HTTP 上报事件" );
338+ const auto resp = post_json (post_url_, ctx.data , secret_, post_timeout_);
329339
330- if (resp.status_code == 0 ) {
331- logging::warning (TAG, u8" HTTP 上报地址 " + post_url_ + u8" 无法访问" );
340+ if (resp.status_code == 0 ) {
341+ logging::warning (TAG, u8" HTTP 上报地址 " + post_url_ + u8" 无法访问" );
342+ } else {
343+ const auto log_msg = u8" 通过 HTTP 上报数据到 " + post_url_ + (resp.ok () ? u8" 成功" : u8" 失败" )
344+ + u8" ,状态码:" + to_string (resp.status_code );
345+ if (resp.ok ()) {
346+ logging::info_success (TAG, log_msg);
332347 } else {
333- const auto log_msg = u8" 通过 HTTP 上报数据到 " + post_url_ + (resp.ok () ? u8" 成功" : u8" 失败" )
334- + u8" ,状态码:" + to_string (resp.status_code );
335- if (resp.ok ()) {
336- logging::info_success (TAG, log_msg);
337- } else {
338- logging::warning (TAG, log_msg);
339- }
348+ logging::warning (TAG, log_msg);
340349 }
350+ }
341351
342- if (resp.ok () && !resp.body .empty ()) {
343- logging::debug (TAG, u8" 收到响应 " + resp.body );
352+ if (resp.ok () && !resp.body .empty ()) {
353+ logging::debug (TAG, u8" 收到响应 " + resp.body );
344354
345- const auto resp_payload = resp.get_json ();
346- if (resp_payload.is_object ()) {
347- const utils::JsonEx params = resp_payload;
355+ const auto resp_payload = resp.get_json ();
356+ if (resp_payload.is_object ()) {
357+ const utils::JsonEx params = resp_payload;
348358
349- // note here that the ctx.data object was processed by backward_compatibility plugin,
350- // but now that the ".handle_quick_operation" action can handle legacy data format,
351- // it's ok here to use ctx.data directly
352- call_action (" .handle_quick_operation" , {{" context" , ctx.data }, {" operation" , params.raw }});
359+ // note here that the ctx.data object was processed by backward_compatibility plugin,
360+ // but now that the ".handle_quick_operation" action can handle legacy data format,
361+ // it's ok here to use ctx.data directly
362+ call_action (" .handle_quick_operation" , {{" context" , ctx.data }, {" operation" , params.raw }});
353363
354- if (params.get_bool (" block" , false )) {
355- ctx.event .block ();
356- }
357- } else {
358- logging::debug (TAG, u8" 上报响应不是有效的 JSON,已忽略" );
364+ if (params.get_bool (" block" , false )) {
365+ ctx.event .block ();
359366 }
367+ } else {
368+ logging::debug (TAG, u8" 上报响应不是有效的 JSON,已忽略" );
360369 }
361370 }
362371
0 commit comments