Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ pub enum Commands {
post_id: String,
},

/// Report a post to moderators (One-shot)
Report {
/// Post ID
post_id: String,
/// Report reason (spam, harassment, rule-violation, other)
#[arg(short, long, default_value = "spam")]
reason: String,
},

/// Delete a post (One-shot)
DeletePost {
/// Post ID
Expand Down Expand Up @@ -505,6 +514,7 @@ pub async fn execute(command: Commands, client: &MoltbookClient) -> Result<(), A
Commands::DeletePost { post_id } => post::delete_post(client, &post_id).await,
Commands::Upvote { post_id } => post::upvote_post(client, &post_id).await,
Commands::Downvote { post_id } => post::downvote_post(client, &post_id).await,
Commands::Report { post_id, reason } => post::report_post(client, &post_id, Some(reason)).await,
Commands::Search {
query,
type_filter,
Expand Down
22 changes: 22 additions & 0 deletions src/cli/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,28 @@ pub async fn create_comment(
Ok(())
}

pub async fn report_post(
client: &MoltbookClient,
post_id: &str,
reason: Option<String>,
) -> Result<(), ApiError> {
let reason = reason.unwrap_or_else(|| "spam".to_string());
let body = json!({ "reason": reason });
let result: serde_json::Value = client
.post(&format!("/posts/{}/report", post_id), &body)
.await?;

if result["success"].as_bool().unwrap_or(false) {
display::success(&format!("Post {} reported (reason: {}). 🦞", post_id, reason));
} else {
display::error(&format!(
"Failed to report post: {}",
result["error"].as_str().unwrap_or("unknown error")
));
}
Ok(())
}

pub async fn upvote_comment(client: &MoltbookClient, comment_id: &str) -> Result<(), ApiError> {
let result: serde_json::Value = client
.post(&format!("/comments/{}/upvote", comment_id), &json!({}))
Expand Down