-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ExquisiteCore
committed
Dec 22, 2023
1 parent
c33457d
commit 5d1fe55
Showing
11 changed files
with
226 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
".\\Cargo.toml", | ||
".\\Cargo.toml", | ||
".\\Cargo.toml" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
use serde_json::Value; | ||
pub fn process_meta_event(json: &Value) { | ||
|
||
pub async fn process_meta_event(json: &Value, request: &crate::postrequest::Request) { | ||
// 处理 meta_event 类型的逻辑 | ||
// 获取 meta_event_type 值 | ||
if let Some(meta_event_type) = json["meta_event_type"].as_str() { | ||
match meta_event_type { | ||
"lifecycle" => println!("生活周期"), | ||
"lifecycle" => { | ||
println!("生活周期"); | ||
match request.send_private_msg_api(&2977926714, "Bot启动").await { | ||
Ok(text) => { | ||
println!("post 返回{}", text); | ||
} | ||
Err(err) => { | ||
eprintln!("Error sending HTTP request: {:?}", err); | ||
} | ||
} | ||
} | ||
"heartbeat" => println!("心跳一次"), | ||
_ => println!("Unknown meta_event_type: {:?}", meta_event_type), | ||
} | ||
} else { | ||
println!("Missing meta_event_type field in meta_event"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
mod message; | ||
mod meta_event; | ||
mod notice; | ||
mod request; | ||
mod meta_event; | ||
|
||
use serde_json::Value; | ||
|
||
pub fn process_json(json_str: &str) { | ||
pub async fn process_message(json_str: &str, request: &crate::postrequest::Request) { | ||
// 使用 serde_json 解析 JSON 字符串 | ||
let json: Value = serde_json::from_str(json_str).expect("Failed to parse JSON"); | ||
|
||
// 获取 post_type 值 | ||
let post_type = json["post_type"].as_str(); | ||
// 根据 post_type 值进行分类处理 | ||
match post_type { | ||
Some("message") => message::process_message_event(&json), | ||
Some("message_sent") => message::process_message_sent_event(&json), | ||
Some("notice") => notice::process_notice_event(&json), | ||
Some("request") => request::process_request_event(&json), | ||
Some("meta_event") => meta_event::process_meta_event(&json), | ||
Some("message") => message::process_message_event(&json, &&request).await, | ||
Some("message_sent") => message::process_message_send_event(&json, &&request).await, | ||
Some("notice") => notice::process_notice_event(&json, &&request).await, | ||
Some("request") => request::process_request_event(&json, &&request).await, | ||
Some("meta_event") => meta_event::process_meta_event(&json, &&request).await, | ||
_ => println!("未知 post_type: {:?}", post_type), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod bot; | ||
pub mod event; | ||
pub mod postrequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.