From c02c390a6dacd494aa63f4f9c0b89c842f6a25c1 Mon Sep 17 00:00:00 2001 From: Davide Polonio Date: Tue, 31 May 2022 11:37:30 +0200 Subject: [PATCH] chore: bump depedencies --- .idea/misc.xml | 3 ++ Cargo.toml | 10 +++---- src/main.rs | 29 +++++++++--------- src/spotify/mod.rs | 75 +++++++++++++++++++++++----------------------- 4 files changed, 60 insertions(+), 57 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 9360735..b58379e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,4 +3,7 @@ + + diff --git a/Cargo.toml b/Cargo.toml index ac7c90b..ac205cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "songlify" -version = "0.2.3" +version = "0.3.1" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -teloxide = { version = "0.7.1", features = ["auto-send", "macros"] } -log = "0.4.14" +teloxide = { version = "0.9.1", features = ["auto-send", "macros"] } +log = "0.4.17" pretty_env_logger = "0.4.0" -tokio = { version = "1.17.0", features = ["rt-multi-thread", "macros"] } -rspotify = { version = "0.11.4", features = ["default"]} +tokio = { version = "1.18.2", features = ["rt-multi-thread", "macros"] } +rspotify = { version = "0.11.5", features = ["default"]} diff --git a/src/main.rs b/src/main.rs index fc8f0af..00e4fc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,8 +17,8 @@ async fn main() { log::info!("Starting Songlify..."); let bot = Bot::from_env().auto_send(); - teloxide::repl(bot, |message| async move { - let text = message.update.text().and_then(spotify::get_entry_kind); + teloxide::repl(bot, |message: Message, bot: AutoSend| async move { + let text = message.text().and_then(spotify::get_entry_kind); match text { Some(spotify) => { let spotify_client = spotify::get_client().await; @@ -37,7 +37,10 @@ async fn main() { truncate_with_dots(info.artists.join(", "), MAX_ARTISTS_CHARS), human_readable_duration(info.duration) ); - Some(message.reply_to(reply).await?) + bot.send_message(message.chat.id, reply) + .reply_to_message_id(message.id) + .await?; + Some(respond(())) } None => None, } @@ -61,11 +64,10 @@ async fn main() { .as_str(), ); } - Some( - message - .reply_to(add_track_section(info.tracks, reply)) - .await?, - ) + bot.send_message(message.chat.id, reply) + .reply_to_message_id(message.id) + .await?; + Some(respond(())) } None => None, } @@ -83,15 +85,14 @@ async fn main() { info.artists.len(), truncate_with_dots(info.artists.join(", "), MAX_ARTISTS_CHARS) ); - Some( - message - .reply_to(add_track_section_for_playlist(info.tracks, reply)) - .await?, - ) + bot.send_message(message.chat.id, reply) + .reply_to_message_id(message.id) + .await?; + Some(respond(())) } None => None, } - }, + } Episode(id) => { log::warn!("Support for episodes ({}) has not be implemented yet!", id); None diff --git a/src/spotify/mod.rs b/src/spotify/mod.rs index 3b9bb8b..b27de44 100644 --- a/src/spotify/mod.rs +++ b/src/spotify/mod.rs @@ -1,20 +1,20 @@ -use std::time::Duration; -use rspotify::{ClientCredsSpotify, Credentials}; -use rspotify::model::{AlbumId, FullTrack, PlaylistId, TrackId}; use rspotify::model::PlayableItem::{Episode, Track}; +use rspotify::model::{AlbumId, FullTrack, PlaylistId, TrackId}; use rspotify::prelude::*; +use rspotify::{ClientCredsSpotify, Credentials}; +use std::time::Duration; pub enum SpotifyKind { Track(String), Album(String), Playlist(String), Podcast(String), - Episode(String) + Episode(String), } pub enum PlayableKind { Track(TrackInfo), - Podcast(EpisodeInfo) + Podcast(EpisodeInfo), } pub struct TrackInfo { @@ -29,7 +29,7 @@ pub struct EpisodeInfo { pub(crate) duration: Duration, pub(crate) description: String, pub(crate) languages: Vec, - pub(crate) release_date: String + pub(crate) release_date: String, } pub struct AlbumInfo { @@ -99,7 +99,8 @@ pub fn get_entry_kind(url: &str) -> Option { } pub async fn get_client() -> Box { - let spotify_creds = Credentials::from_env().expect("RSPOTIFY_CLIENT_ID and RSPOTIFY_CLIENT_SECRET not found."); + let spotify_creds = + Credentials::from_env().expect("RSPOTIFY_CLIENT_ID and RSPOTIFY_CLIENT_SECRET not found."); let mut spotify = ClientCredsSpotify::new(spotify_creds); spotify.request_token().await.unwrap(); Box::new(spotify) @@ -108,23 +109,23 @@ pub async fn get_client() -> Box { pub async fn get_track(spotify: Box, id: &String) -> Option { let track_id = match TrackId::from_id(id.as_str()) { Ok(track) => track, - Err(_e) => return None + Err(_e) => return None, }; match spotify.track(&track_id).await { - Ok(track) => Some(TrackInfo{ + Ok(track) => Some(TrackInfo { name: track.name, artists: track.artists.iter().map(|x| x.name.clone()).collect(), duration: track.duration, }), - Err(_e) => None + Err(_e) => None, } } pub async fn get_album(spotify: Box, id: &String) -> Option { let album_id = match AlbumId::from_id(id.as_str()) { Ok(album) => album, - Err(_e) => return None + Err(_e) => return None, }; match spotify.album(&album_id).await { @@ -150,7 +151,7 @@ pub async fn get_album(spotify: Box, id: &String) -> Option< pub async fn get_playlist(spotify: Box, id: &String) -> Option { let playlist_id = match PlaylistId::from_id(id.as_str()) { Ok(playlist) => playlist, - Err(_e) => return None + Err(_e) => return None, }; match spotify.playlist(&playlist_id, None, None).await { @@ -163,37 +164,35 @@ pub async fn get_playlist(spotify: Box, id: &String) -> Opti .flat_map(|p| { match &p.track { Some(t) => match t { - Track(t) => t.artists.iter().map(|a| { - a.name.clone() - }).collect(), - Episode(e) => vec![e.show.publisher.clone()] - } + Track(t) => t.artists.iter().map(|a| a.name.clone()).collect(), + Episode(e) => vec![e.show.publisher.clone()], + }, None => Vec::new(), - }.into_iter() - }).collect(), + } + .into_iter() + }) + .collect(), tracks: playlist .tracks .items .iter() - .map(|p| { - match &p.track { - Some(t) => match t { - Track(t) => Some(PlayableKind::Track(TrackInfo{ - name: t.name.clone(), - artists: t.artists.iter().map(|a| a.name.clone()).collect(), - duration: t.duration - })), - Episode(e) => Some(PlayableKind::Podcast(EpisodeInfo{ - name: e.name.clone(), - show: e.show.name.clone(), - duration: e.duration, - description: e.description.clone(), - languages: e.languages.clone(), - release_date: e.release_date.clone() - })) - }, - None => None - } + .map(|p| match &p.track { + Some(t) => match t { + Track(t) => Some(PlayableKind::Track(TrackInfo { + name: t.name.clone(), + artists: t.artists.iter().map(|a| a.name.clone()).collect(), + duration: t.duration, + })), + Episode(e) => Some(PlayableKind::Podcast(EpisodeInfo { + name: e.name.clone(), + show: e.show.name.clone(), + duration: e.duration, + description: e.description.clone(), + languages: e.languages.clone(), + release_date: e.release_date.clone(), + })), + }, + None => None, }) .filter(|i| i.is_some()) .map(|i| i.unwrap())