use teloxide::prelude::*; use spotify::SpotifyKind::Track; use crate::spotify::SpotifyKind::Album; mod spotify; #[tokio::main] async fn main() { teloxide::enable_logging!(); 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_spotify_entry); match text { Some(spotify) => { let spotify_client = spotify::get_spotify_client(); match spotify { Track(id) => { log::debug!("Parsing spotify song: {}", id); let track_info = spotify::get_spotify_track(spotify_client, &id).await; match track_info { Some(info) => { let reply = format!( "Track information:\n\ šŸŽµ Track name: {}\n\ šŸ§‘ā€šŸŽ¤ Artist(s): {}\n\ ā³ Duration: {} second(s)", info.name, info.artists.join(", "), info.duration.as_secs() ); Some(message.reply_to(reply).await?) } None => None, } } Album(id) => { log::debug!("Parsing spotify album: {}", id); let album_info = spotify::get_spotify_album(spotify_client, &id).await; match album_info { Some(info) => { let mut reply = format!( "Album information:\n\ šŸŽµ Album name name: {}\n\ šŸ§‘ā€šŸŽ¤ Artist(s): {}", info.name, info.artists.join(", ") ); if !info.genres.is_empty() { reply.push_str( format!("\nšŸ’æ Genre(s): {}", info.genres.join(", ")) .as_str(), ); } if !info.songs.is_empty() { let songs = info .songs .iter() .map(|x| x.name.clone() + "\n") .collect::(); reply.push_str(format!("\nšŸŽ¶ Song(s): {}", songs).as_str()); } Some(message.reply_to(reply).await?) } None => None, } } } } None => None, }; respond(()) }) .await; log::info!("Exiting..."); }