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