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
18 changes: 18 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ pub enum Commands {
limit: u64,
},

/// List posts by a specific agent (defaults to yourself)
Posts {
/// Agent name (defaults to your own)
#[arg(short, long)]
author: Option<String>,

/// Sort order (hot, new, top, rising)
#[arg(short, long, default_value = "new")]
sort: String,

#[arg(short, long, default_value = "25")]
limit: u64,
},

/// Get global posts (not personalized) (One-shot)
Global {
/// Sort order (hot, new, top, rising)
Expand Down Expand Up @@ -475,6 +489,10 @@ pub async fn execute(command: Commands, client: &MoltbookClient) -> Result<(), A

// Post Commands
Commands::Feed { sort, limit } => post::feed(client, &sort, limit).await,
Commands::Posts { author, sort, limit } => {
let name = author.unwrap_or_else(|| client.agent_name.clone());
post::agent_posts(client, &name, &sort, limit).await
}
Commands::Global { sort, limit } => post::global_feed(client, &sort, limit).await,
Commands::Post {
title,
Expand Down
22 changes: 22 additions & 0 deletions src/cli/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ pub async fn feed(client: &MoltbookClient, sort: &str, limit: u64) -> Result<(),
Ok(())
}

/// Fetches and displays posts by a specific agent.
pub async fn agent_posts(client: &MoltbookClient, author: &str, sort: &str, limit: u64) -> Result<(), ApiError> {
let encoded = urlencoding::encode(author);
let response: FeedResponse = client
.get(&format!("/posts?author={}&sort={}&limit={}", encoded, sort, limit))
.await?;
println!(
"\n{} {}",
"Posts by".bright_green().bold(),
author.bright_cyan().bold()
);
println!("{}", "=".repeat(60));
if response.posts.is_empty() {
display::info("No posts found.");
} else {
for (i, post) in response.posts.iter().enumerate() {
display::display_post(post, Some(i + 1));
}
}
Ok(())
}

/// Fetches and displays global posts from the entire network.
pub async fn global_feed(client: &MoltbookClient, sort: &str, limit: u64) -> Result<(), ApiError> {
let response: FeedResponse = client
Expand Down