add subcommands for platforms
This commit is contained in:
parent
90a6a03890
commit
05ab839ed6
3 changed files with 72 additions and 45 deletions
|
@ -1,7 +1,19 @@
|
|||
use clap::Parser;
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
|
||||
/// Bluesky Command Arguments
|
||||
#[derive(Args, Debug)]
|
||||
pub struct BlueskyCommand {
|
||||
/// The Bluesky bot user's handle.
|
||||
#[arg(short = 'u', long)]
|
||||
pub bluesky_handle: String,
|
||||
|
||||
/// The Bluesky bot user's password.
|
||||
#[arg(short = 'p', long)]
|
||||
pub bluesky_password: String,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
#[command(version, about = "Social media posting bot.", long_about = None)]
|
||||
pub struct CliArgs {
|
||||
/// Redis host
|
||||
#[arg(short, long)]
|
||||
|
@ -19,11 +31,16 @@ pub struct CliArgs {
|
|||
#[arg(short = 'n', long)]
|
||||
pub redis_consumer_name: String,
|
||||
|
||||
/// The bluesky bot user's handle.
|
||||
#[arg(short = 'u', long)]
|
||||
pub bluesky_handle: String,
|
||||
|
||||
/// The bluesky bot user's password.
|
||||
#[arg(short = 'p', long)]
|
||||
pub bluesky_password: String,
|
||||
/// Platform
|
||||
#[command(subcommand)]
|
||||
pub platform: Command,
|
||||
}
|
||||
|
||||
/// Available Subcommands
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum Command {
|
||||
/// Post on bluesky platform.
|
||||
Bluesky(BlueskyCommand),
|
||||
/// Post on Mastodon, the FediVerse
|
||||
Mastodon,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::bluesky::BlueSkyClient;
|
||||
use crate::cli::CliArgs;
|
||||
use crate::cli::{CliArgs, Command};
|
||||
use clap::Parser;
|
||||
use infrastructure::RedisService;
|
||||
use log::{error, info, warn};
|
||||
|
@ -65,8 +65,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
warn!("{}", err);
|
||||
}
|
||||
|
||||
match args.platform {
|
||||
Command::Bluesky(bluesky) => {
|
||||
let mut bluesky_client =
|
||||
BlueSkyClient::new(&args.bluesky_handle, &args.bluesky_password).await?;
|
||||
BlueSkyClient::new(&bluesky.bluesky_handle, &bluesky.bluesky_password).await?;
|
||||
|
||||
// Read from stream
|
||||
while running.load(Ordering::SeqCst) {
|
||||
|
@ -80,12 +82,14 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
.await
|
||||
{
|
||||
Ok(post) => {
|
||||
let mut data: bluesky::atproto::ATProtoRepoCreateRecord = post.clone().into();
|
||||
data.repo = args.bluesky_handle.clone();
|
||||
let mut data: bluesky::atproto::ATProtoRepoCreateRecord =
|
||||
post.clone().into();
|
||||
data.repo = bluesky.bluesky_handle.clone();
|
||||
|
||||
if let Some(image_link) = post.image.clone() {
|
||||
let result =
|
||||
add_image_to_post(&mut bluesky_client, &image_link, &mut data).await;
|
||||
add_image_to_post(&mut bluesky_client, &image_link, &mut data)
|
||||
.await;
|
||||
if let Err(err) = result {
|
||||
warn!("Failed to upload image: {err}")
|
||||
}
|
||||
|
@ -109,6 +113,11 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::Mastodon => {
|
||||
unimplemented!("This command is not currently implemented.")
|
||||
}
|
||||
}
|
||||
|
||||
info!("Stopping the program");
|
||||
Ok(())
|
||||
|
|
|
@ -10,7 +10,7 @@ services:
|
|||
- "redis://192.168.0.221:6379"
|
||||
- "--redis-stream-name"
|
||||
- "posts::g4media"
|
||||
bot:
|
||||
bluesky-bot:
|
||||
container_name: bluesky-bot
|
||||
image: metonymy/bot
|
||||
environment:
|
||||
|
@ -24,6 +24,7 @@ services:
|
|||
- "bluesky-bot-nas"
|
||||
- "--redis-consumer-name"
|
||||
- "bot-1"
|
||||
- "bluesky"
|
||||
- "--bluesky-handle"
|
||||
- "REPLACE-ME"
|
||||
- "--bluesky-password"
|
||||
|
|
Loading…
Reference in a new issue