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)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about = "Social media posting bot.", long_about = None)]
|
||||||
pub struct CliArgs {
|
pub struct CliArgs {
|
||||||
/// Redis host
|
/// Redis host
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
@ -19,11 +31,16 @@ pub struct CliArgs {
|
||||||
#[arg(short = 'n', long)]
|
#[arg(short = 'n', long)]
|
||||||
pub redis_consumer_name: String,
|
pub redis_consumer_name: String,
|
||||||
|
|
||||||
/// The bluesky bot user's handle.
|
/// Platform
|
||||||
#[arg(short = 'u', long)]
|
#[command(subcommand)]
|
||||||
pub bluesky_handle: String,
|
pub platform: Command,
|
||||||
|
}
|
||||||
/// The bluesky bot user's password.
|
|
||||||
#[arg(short = 'p', long)]
|
/// Available Subcommands
|
||||||
pub bluesky_password: String,
|
#[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::bluesky::BlueSkyClient;
|
||||||
use crate::cli::CliArgs;
|
use crate::cli::{CliArgs, Command};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use infrastructure::RedisService;
|
use infrastructure::RedisService;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
|
@ -65,8 +65,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
warn!("{}", err);
|
warn!("{}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match args.platform {
|
||||||
|
Command::Bluesky(bluesky) => {
|
||||||
let mut bluesky_client =
|
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
|
// Read from stream
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
|
@ -80,12 +82,14 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(post) => {
|
Ok(post) => {
|
||||||
let mut data: bluesky::atproto::ATProtoRepoCreateRecord = post.clone().into();
|
let mut data: bluesky::atproto::ATProtoRepoCreateRecord =
|
||||||
data.repo = args.bluesky_handle.clone();
|
post.clone().into();
|
||||||
|
data.repo = bluesky.bluesky_handle.clone();
|
||||||
|
|
||||||
if let Some(image_link) = post.image.clone() {
|
if let Some(image_link) = post.image.clone() {
|
||||||
let result =
|
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 {
|
if let Err(err) = result {
|
||||||
warn!("Failed to upload image: {err}")
|
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");
|
info!("Stopping the program");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -10,7 +10,7 @@ services:
|
||||||
- "redis://192.168.0.221:6379"
|
- "redis://192.168.0.221:6379"
|
||||||
- "--redis-stream-name"
|
- "--redis-stream-name"
|
||||||
- "posts::g4media"
|
- "posts::g4media"
|
||||||
bot:
|
bluesky-bot:
|
||||||
container_name: bluesky-bot
|
container_name: bluesky-bot
|
||||||
image: metonymy/bot
|
image: metonymy/bot
|
||||||
environment:
|
environment:
|
||||||
|
@ -24,6 +24,7 @@ services:
|
||||||
- "bluesky-bot-nas"
|
- "bluesky-bot-nas"
|
||||||
- "--redis-consumer-name"
|
- "--redis-consumer-name"
|
||||||
- "bot-1"
|
- "bot-1"
|
||||||
|
- "bluesky"
|
||||||
- "--bluesky-handle"
|
- "--bluesky-handle"
|
||||||
- "REPLACE-ME"
|
- "REPLACE-ME"
|
||||||
- "--bluesky-password"
|
- "--bluesky-password"
|
||||||
|
|
Loading…
Reference in a new issue