From f8502953dd56250f2e0952f7b0c3062e58b6716a Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sat, 9 Oct 2021 17:17:01 +0200 Subject: make url_preview async --- src/hooks/url.rs | 8 ++++---- src/main.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hooks/url.rs b/src/hooks/url.rs index 2392d1d..4e19282 100644 --- a/src/hooks/url.rs +++ b/src/hooks/url.rs @@ -41,17 +41,17 @@ pub async fn url_title(url: &str) -> Result { } #[tracing::instrument(skip(bot))] -pub fn url_preview(bot: &crate::Bot, msg: Message) -> Result<()> { +pub async fn url_preview(bot: &crate::Bot, msg: Message) -> Result<()> { if let Command::PRIVMSG(target, text) = msg.command.clone() { let mut titles: Vec = Vec::new(); for url in url_parser(&text) { trace!("got url: {:?}", url); - match futures::executor::block_on(url_title(&url.as_str())) { + match url_title(&url.as_str()).await { Ok(title) => { trace!("extracted title from url: {:?}, {:?}", title, url); titles.push(title); - }, + } Err(err) => error!("Failed to get urls title: {:?}", err), } } @@ -69,7 +69,7 @@ pub fn msg_builder(titles: &Vec) -> String { "Title{}: {}", if titles.len() > 1 { "s" } else { "" }, titles.join(" --- ") - ) + ) } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index 776299d..f442d35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ async fn main() { AUTHENTICATE, catinator::hooks::sasl ), - hook( + async hook( "url_preview", "Send preview of website", PRIVMSG, -- cgit v1.2.3