2021-09-28 15:20:28 +02:00
|
|
|
|
use teloxide::prelude::*;
|
2021-09-21 23:41:50 +02:00
|
|
|
|
|
2021-09-28 15:20:28 +02:00
|
|
|
|
use spotify::SpotifyKind::Track;
|
2021-09-22 20:59:20 +02:00
|
|
|
|
|
2021-09-28 15:20:28 +02:00
|
|
|
|
use crate::spotify::SpotifyKind::Album;
|
2021-09-22 12:37:48 +02:00
|
|
|
|
|
2021-09-28 15:20:28 +02:00
|
|
|
|
mod spotify;
|
2021-09-21 23:41:50 +02:00
|
|
|
|
|
|
|
|
|
#[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 {
|
2021-09-28 15:20:28 +02:00
|
|
|
|
let text = message.update.text().and_then(spotify::get_spotify_entry);
|
2021-09-21 23:41:50 +02:00
|
|
|
|
match text {
|
2021-09-22 20:59:20 +02:00
|
|
|
|
Some(spotify) => {
|
2021-09-28 15:20:28 +02:00
|
|
|
|
let spotify_client = spotify::get_spotify_client();
|
2021-09-22 20:59:20 +02:00
|
|
|
|
match spotify {
|
|
|
|
|
Track(id) => {
|
|
|
|
|
log::debug!("Parsing spotify song: {}", id);
|
2021-09-28 15:20:28 +02:00
|
|
|
|
let track_info = spotify::get_spotify_track(spotify_client, &id).await;
|
2021-09-22 20:59:20 +02:00
|
|
|
|
match track_info {
|
|
|
|
|
Some(info) => {
|
|
|
|
|
let reply = format!(
|
|
|
|
|
"Track information:\n\
|
|
|
|
|
🎵 Track name: {}\n\
|
|
|
|
|
🧑🎤 Artist(s): {}\n\
|
|
|
|
|
⏳ Duration: {} second(s)",
|
|
|
|
|
info.name,
|
2021-09-28 15:20:28 +02:00
|
|
|
|
info.artists.join(", "),
|
2021-09-22 20:59:20 +02:00
|
|
|
|
info.duration.as_secs()
|
|
|
|
|
);
|
|
|
|
|
Some(message.reply_to(reply).await?)
|
|
|
|
|
}
|
|
|
|
|
None => None,
|
2021-09-22 12:37:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-28 15:20:28 +02:00
|
|
|
|
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::<String>();
|
|
|
|
|
reply.push_str(format!("\n🎶 Song(s): {}", songs).as_str());
|
|
|
|
|
}
|
|
|
|
|
Some(message.reply_to(reply).await?)
|
|
|
|
|
}
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-21 23:41:50 +02:00
|
|
|
|
}
|
2021-09-22 20:59:20 +02:00
|
|
|
|
}
|
2021-09-22 12:37:48 +02:00
|
|
|
|
None => None,
|
2021-09-21 23:41:50 +02:00
|
|
|
|
};
|
|
|
|
|
respond(())
|
|
|
|
|
})
|
2021-09-22 12:37:48 +02:00
|
|
|
|
.await;
|
|
|
|
|
|
|
|
|
|
log::info!("Exiting...");
|
|
|
|
|
}
|