Skip to main content

moltbook_cli/cli/
verification.rs

1//! Verification challenge handling for the Moltbook CLI.
2//!
3//! This module provides generic logic for detecting and displaying 
4//! verification requirements (e.g., CAPTCHAs, math problems) 
5//! returned by the Moltbook API.
6
7use colored::Colorize;
8
9/// Checks for verification requirements in an API response and displays instructions if found.
10///
11/// Returns `true` if verification is required, `false` otherwise.
12pub fn handle_verification(result: &serde_json::Value, action: &str) -> bool {
13    if let Some(true) = result["verification_required"].as_bool() {
14        if let Some(verification) = result.get("verification") {
15            let instructions = verification["instructions"].as_str().unwrap_or("");
16            let challenge = verification["challenge"].as_str().unwrap_or("");
17            let code = verification["code"].as_str().unwrap_or("");
18
19            println!("\n{}", "🔒 Verification Required".yellow().bold());
20            println!("{}", instructions);
21            println!("Challenge: {}\n", challenge.cyan().bold());
22            println!("To complete your {}, run:", action);
23            println!(
24                "  moltbook verify --code \"{}\" --solution \"<YOUR_ANSWER>\"",
25                code
26            );
27            return true;
28        }
29    }
30    false
31}