mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
chore: fix clippy warnings
This commit is contained in:
parent
a35b255d67
commit
bae194b2bf
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod telemetry;
|
||||||
32
src/main.rs
32
src/main.rs
@ -36,25 +36,25 @@ enum MediaKind {
|
|||||||
async fn main() -> color_eyre::Result<()> {
|
async fn main() -> color_eyre::Result<()> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
setup_logger()?;
|
setup_logger();
|
||||||
|
|
||||||
let bot = Bot::from_env();
|
let bot = Bot::from_env();
|
||||||
|
|
||||||
teloxide::repl(bot, |bot: Bot, msg: Message| async move {
|
teloxide::repl(bot, |bot: Bot, msg: Message| async move {
|
||||||
if let Some(text) = msg.text() {
|
if let Some(text) = msg.text()
|
||||||
if let Some(shortcode) = extract_instagram_shortcode(text) {
|
&& let Some(shortcode) = extract_instagram_shortcode(text)
|
||||||
let bot_cloned = bot.clone();
|
{
|
||||||
let chat = msg.chat.id;
|
let bot_cloned = bot.clone();
|
||||||
|
let chat = msg.chat.id;
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Err(e) = fetch_and_send(&bot_cloned, chat, &shortcode).await {
|
if let Err(e) = fetch_and_send(&bot_cloned, chat, &shortcode).await {
|
||||||
error!("error fetching/sending: {:?}", e);
|
error!("error fetching/sending: {:?}", e);
|
||||||
let _ = bot_cloned
|
let _ = bot_cloned
|
||||||
.send_message(chat, "Failed to fetch Instagram media.")
|
.send_message(chat, "Failed to fetch Instagram media.")
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
respond(())
|
respond(())
|
||||||
})
|
})
|
||||||
@ -77,7 +77,7 @@ async fn fetch_and_send(bot: &Bot, chat_id: ChatId, shortcode: &str) -> Result<(
|
|||||||
let dir_path = dir.path().to_path_buf();
|
let dir_path = dir.path().to_path_buf();
|
||||||
|
|
||||||
dbg!(&dir_path);
|
dbg!(&dir_path);
|
||||||
let target = format!("-{}", shortcode);
|
let target = format!("-{shortcode}");
|
||||||
dbg!(&target);
|
dbg!(&target);
|
||||||
let status = Command::new("instaloader")
|
let status = Command::new("instaloader")
|
||||||
.arg("--dirname-pattern")
|
.arg("--dirname-pattern")
|
||||||
@ -134,7 +134,7 @@ async fn fetch_and_send(bot: &Bot, chat_id: ChatId, shortcode: &str) -> Result<(
|
|||||||
fn ext_lower(path: &Path) -> Option<String> {
|
fn ext_lower(path: &Path) -> Option<String> {
|
||||||
path.extension()
|
path.extension()
|
||||||
.and_then(|s| s.to_str())
|
.and_then(|s| s.to_str())
|
||||||
.map(|s| s.to_ascii_lowercase())
|
.map(str::to_ascii_lowercase)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kind_by_magic(path: &Path) -> Option<MediaKind> {
|
fn kind_by_magic(path: &Path) -> Option<MediaKind> {
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
use color_eyre::Result;
|
|
||||||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
||||||
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
/// # Errors
|
/// Initialise tracing with bunyan-style JSON output.
|
||||||
pub fn setup_logger() -> Result<()> {
|
pub fn setup_logger() {
|
||||||
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into());
|
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into());
|
||||||
let formatter = BunyanFormattingLayer::new("tg-relay-rs".into(), std::io::stdout);
|
let formatter = BunyanFormattingLayer::new("tg-relay-rs".into(), std::io::stdout);
|
||||||
|
|
||||||
@ -12,6 +11,4 @@ pub fn setup_logger() -> Result<()> {
|
|||||||
.with(JsonStorageLayer)
|
.with(JsonStorageLayer)
|
||||||
.with(formatter)
|
.with(formatter)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user