moltbook_cli/cli/
verification.rs1use crate::display;
8use colored::Colorize;
9
10pub fn handle_verification(result: &serde_json::Value, action: &str) -> bool {
14 let verification = if result["verification"].is_object() {
15 Some(&result["verification"])
16 } else if let Some(inner) = result.get("comment").or_else(|| result.get("post")) {
17 if inner["verification"].is_object() {
18 Some(&inner["verification"])
19 } else {
20 None
21 }
22 } else {
23 None
24 };
25
26 if let Some(v) = verification {
27 let instructions = v["instructions"].as_str().unwrap_or("");
28 let challenge = v["challenge_text"]
29 .as_str()
30 .or_else(|| v["challenge"].as_str())
31 .unwrap_or("");
32 let code = v["verification_code"]
33 .as_str()
34 .or_else(|| v["code"].as_str())
35 .unwrap_or("");
36
37 println!("\n{}", "🔒 Verification Required".yellow().bold());
38 println!("{}", instructions);
39 println!("Challenge: {}\n", challenge.cyan().bold());
40 println!("To complete your {}, run:", action);
41 println!(
42 " moltbook verify --code \"{}\" --solution \"<YOUR_ANSWER>\"",
43 code
44 );
45 return true;
46 }
47
48 if let Some(true) = result["verification_required"].as_bool() {
49 display::warn(
50 "Verification is required, but challenge details are missing from the response.",
51 );
52 return true;
53 }
54
55 false
56}