mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
feat: add platforms as features
This commit is contained in:
parent
ebffa20ec9
commit
a83dff719f
@ -29,6 +29,11 @@ tracing-appender = "0.2"
|
||||
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
|
||||
url = "2.5"
|
||||
|
||||
[features]
|
||||
default = ["instagram", "youtube"]
|
||||
instagram = []
|
||||
youtube = []
|
||||
|
||||
[lints.clippy]
|
||||
pedantic = "warn"
|
||||
nursery = "warn"
|
||||
|
||||
@ -8,7 +8,6 @@ use crate::{
|
||||
use futures::{StreamExt, stream};
|
||||
use std::{
|
||||
cmp::min,
|
||||
env,
|
||||
ffi::OsStr,
|
||||
fs::{self, metadata},
|
||||
path::{Path, PathBuf},
|
||||
@ -109,6 +108,7 @@ async fn run_command_in_tempdir(cmd: &str, args: &[&str]) -> Result<DownloadResu
|
||||
/// # Errors
|
||||
///
|
||||
/// - Propagates `run_command_in_tempdir` errors.
|
||||
#[cfg(feature = "instagram")]
|
||||
pub async fn download_instaloader(shortcode: &str) -> Result<DownloadResult> {
|
||||
let args = [
|
||||
"--dirname-pattern=.",
|
||||
@ -126,6 +126,7 @@ pub async fn download_instaloader(shortcode: &str) -> Result<DownloadResult> {
|
||||
/// # Errors
|
||||
///
|
||||
/// - Propagates `run_command_in_tempdir` errors.
|
||||
#[cfg(feature = "youtube")]
|
||||
pub async fn download_ytdlp<P: AsRef<Path>>(
|
||||
url: &str,
|
||||
cookies_path: Option<P>,
|
||||
|
||||
@ -1,9 +1,16 @@
|
||||
#[cfg(feature = "instagram")]
|
||||
mod instagram;
|
||||
#[cfg(feature = "youtube")]
|
||||
mod youtube;
|
||||
|
||||
use crate::error::Result;
|
||||
use teloxide::{Bot, types::ChatId};
|
||||
|
||||
#[cfg(feature = "instagram")]
|
||||
pub use instagram::InstagramHandler;
|
||||
#[cfg(feature = "youtube")]
|
||||
pub use youtube::YouTubeShortsHandler;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait SocialHandler: Send + Sync {
|
||||
/// Short name used for logging etc.
|
||||
@ -25,6 +32,3 @@ impl Clone for Box<dyn SocialHandler> {
|
||||
self.box_clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub use instagram::InstagramHandler;
|
||||
pub use youtube::YouTubeShortsHandler;
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use teloxide::{Bot, prelude::Requester, respond, types::Message};
|
||||
use tg_relay_rs::{
|
||||
comments::{Comments, init_global_comments},
|
||||
handlers::{InstagramHandler, SocialHandler, YouTubeShortsHandler},
|
||||
handlers::SocialHandler,
|
||||
telemetry::setup_logger,
|
||||
};
|
||||
use tracing::{error, info, warn};
|
||||
@ -27,8 +27,12 @@ async fn main() -> color_eyre::Result<()> {
|
||||
let bot = Bot::from_env();
|
||||
info!("bot starting");
|
||||
|
||||
let handlers: Vec<Arc<dyn SocialHandler>> =
|
||||
vec![Arc::new(InstagramHandler), Arc::new(YouTubeShortsHandler)];
|
||||
let handlers: Vec<Arc<dyn SocialHandler>> = vec![
|
||||
#[cfg(feature = "instagram")]
|
||||
Arc::new(tg_relay_rs::handlers::InstagramHandler),
|
||||
#[cfg(feature = "youtube")]
|
||||
Arc::new(tg_relay_rs::handlers::YouTubeShortsHandler),
|
||||
];
|
||||
|
||||
teloxide::repl(bot.clone(), move |bot: Bot, msg: Message| {
|
||||
// clone the handlers vector into the closure
|
||||
|
||||
Loading…
Reference in New Issue
Block a user