47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
|
use teloxide::prelude::*;
|
||
|
use crate::Spotify::Track;
|
||
|
|
||
|
enum Spotify {
|
||
|
Track(String)
|
||
|
}
|
||
|
|
||
|
fn get_spotify_entry(url : &str) -> Option<Spotify> {
|
||
|
if url.contains("https://open.spotify.com/track/") {
|
||
|
let track_id = url.rsplit('/').next().and_then(|x| x.split('?').next());
|
||
|
return match track_id {
|
||
|
Some(id) => Some(Spotify::Track(id.to_string())),
|
||
|
None => None
|
||
|
}
|
||
|
}
|
||
|
return None
|
||
|
}
|
||
|
|
||
|
fn is_spotify_url(url : &str) -> Option<&str> {
|
||
|
// https://open.spotify.com/track/0VffaI2jwQknRrxpECYHsF?si=1e16c64779744375
|
||
|
if url.contains("https://open.spotify.com/") {
|
||
|
return Some(url)
|
||
|
}
|
||
|
return None
|
||
|
}
|
||
|
|
||
|
#[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(get_spotify_entry);
|
||
|
match text {
|
||
|
Some(spotify) => {
|
||
|
match spotify {
|
||
|
Track(id) => Some(message.reply_to(id).await?)
|
||
|
}
|
||
|
}
|
||
|
None => None
|
||
|
};
|
||
|
respond(())
|
||
|
})
|
||
|
.await;
|
||
|
}
|