* missing tests, docs and other stuff * missing playlist porting and other content too (maybe)
89 lines
2.9 KiB
Rust
89 lines
2.9 KiB
Rust
use log::{info, log, LevelFilter};
|
|
use search::spotify;
|
|
use sentry::ClientInitGuard;
|
|
use std::env;
|
|
use std::sync::Arc;
|
|
use teloxide::prelude::*;
|
|
|
|
use search::spotify::ContentKind::Track;
|
|
use search::spotify::{PlayableKind, TrackInfo};
|
|
|
|
use crate::search::get_spotify_kind;
|
|
use crate::spotify::ContentKind;
|
|
use search::spotify::ContentKind::{Album, Episode, Playlist, Podcast};
|
|
use tgformatter::utils::{human_readable_duration, truncate_with_dots};
|
|
|
|
mod search;
|
|
mod tgformatter;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
if env::var("RUST_LOG").is_err() {
|
|
pretty_env_logger::formatted_builder()
|
|
.filter_module("songlify", LevelFilter::Info)
|
|
.filter_module("teloxide", LevelFilter::Info)
|
|
.init();
|
|
} else {
|
|
pretty_env_logger::init();
|
|
}
|
|
log::info!("Starting Songlify...");
|
|
log::trace!("You're running in trace mode!");
|
|
|
|
let mut _guard: ClientInitGuard;
|
|
match env::var("SENTRY_DSN") {
|
|
Ok(sentry_dsn) => {
|
|
log::debug!("Sentry DSN found, enabling error reporting");
|
|
_guard = sentry::init((
|
|
sentry_dsn,
|
|
sentry::ClientOptions {
|
|
release: sentry::release_name!(),
|
|
..Default::default()
|
|
},
|
|
));
|
|
}
|
|
Err(_) => {
|
|
log::warn!("No sentry DSN set, errors will not be reported. Use SENTRY_DSN env variable if you want to set error reporting")
|
|
}
|
|
}
|
|
|
|
let bot = Bot::from_env().auto_send();
|
|
teloxide::repl(bot, |message: Message, bot: AutoSend<Bot>| async move {
|
|
let music_engine = search::Engine::new().await;
|
|
let opt_text_message = message.text();
|
|
if opt_text_message.is_none() {
|
|
return respond(());
|
|
}
|
|
let text_message = opt_text_message.unwrap();
|
|
let content_kind = opt_text_message.and_then(|x| get_spotify_kind(x));
|
|
let option_reply = match content_kind {
|
|
None => return respond(()),
|
|
Some(content) => match content {
|
|
Track(id) => {
|
|
info!("Processing song with spotify id: {}", id);
|
|
let track_item = music_engine.get_song_from_spotify_id(text_message).await;
|
|
tgformatter::format_track_message(track_item)
|
|
}
|
|
Album(id) => {
|
|
info!("Processing album with spotify id: {}", id);
|
|
let album_item = music_engine.get_album_by_spotify_id(text_message).await;
|
|
tgformatter::format_album_message(album_item)
|
|
}
|
|
_ => None,
|
|
},
|
|
};
|
|
|
|
if option_reply.is_some() {
|
|
info!("Got value to send back");
|
|
let reply = option_reply.unwrap();
|
|
bot.send_message(message.chat.id, reply)
|
|
.reply_to_message_id(message.id)
|
|
.await?;
|
|
}
|
|
|
|
return respond(());
|
|
})
|
|
.await;
|
|
|
|
log::info!("Exiting...");
|
|
}
|