aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJokler <jokler@protonmail.com>2020-01-14 19:51:24 +0100
committerJokler <jokler@protonmail.com>2020-01-14 19:51:24 +0100
commit58d7e8655d24a4f7ac846b1e27dd771717588849 (patch)
tree86c731ad9bcfa18c9b81bdb7b1762c6065c2c7b8 /src/main.rs
parent6bc3285baa3e51c6fa65cfa5f37de3c56da940d6 (diff)
downloadpokebot-58d7e8655d24a4f7ac846b1e27dd771717588849.tar.gz
pokebot-58d7e8655d24a4f7ac846b1e27dd771717588849.zip
Make youtube-dl execution async again
If tokio is run with a low thread count running youtube-dl can freeze audio playback. This should prevent that by waiting for the command asynchronously.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index e19a9ae..18b9cc7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -115,8 +115,8 @@ impl Application {
self.player.play().unwrap();
}
- pub fn add_audio(&self, url: String) {
- match youtube_dl::get_audio_download_url(url) {
+ pub async fn add_audio(&self, url: String) {
+ match youtube_dl::get_audio_download_url(url).await {
Ok((audio_url, audio_title)) => {
info!("Found audio url: {}", audio_url);
@@ -162,7 +162,7 @@ impl Application {
self.with_teamspeak(|ts| ts.set_description(desc));
}
- fn on_text(&self, message: Message) -> Result<(), AudioPlayerError> {
+ async fn on_text(&self, message: Message) -> Result<(), AudioPlayerError> {
let msg = message.text;
if msg.starts_with("!") {
let tokens = msg[1..].split_whitespace().collect::<Vec<_>>();
@@ -173,7 +173,7 @@ impl Application {
// strip bbcode tags from url
let url = url.replace("[URL]", "").replace("[/URL]", "");
- self.add_audio(url.to_string());
+ self.add_audio(url.to_string()).await;
}
}
Some("play") => {
@@ -257,14 +257,14 @@ impl Application {
Ok(())
}
- pub fn on_message(&self, message: ApplicationMessage) -> Result<(), AudioPlayerError> {
+ pub async fn on_message(&self, message: ApplicationMessage) -> Result<(), AudioPlayerError> {
match message {
ApplicationMessage::TextMessage(message) => {
if let MessageTarget::Poke(who) = message.target {
info!("Poked by {}, joining their channel", who);
self.with_teamspeak(|ts| ts.join_channel_of_user(who));
} else {
- self.on_text(message)?;
+ self.on_text(message).await?;
}
}
ApplicationMessage::StateChange(state) => {
@@ -357,7 +357,7 @@ async fn async_main() {
loop {
while let Some(msg) = rx.recv().await {
- application.on_message(msg).unwrap();
+ application.on_message(msg).await.unwrap();
}
}
}