chore: fix clippy warnings

This commit is contained in:
Kristofers Solo 2025-09-19 17:14:56 +03:00
parent a35b255d67
commit bae194b2bf
Signed by: kristoferssolo
GPG Key ID: 8687F2D3EEE6F0ED
3 changed files with 19 additions and 21 deletions

1
src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod telemetry;

View File

@ -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> {

View File

@ -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(())
} }