diff options
| author | Max Audron <audron@cocaine.farm> | 2021-10-09 17:17:01 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-10-10 16:21:55 +0200 |
| commit | f8502953dd56250f2e0952f7b0c3062e58b6716a (patch) | |
| tree | 57e694a2bafc85b85913e0553d3c63419b23eb46 /src | |
| parent | add tracing and error context to url preview (diff) | |
make url_preview async
Diffstat (limited to 'src')
| -rw-r--r-- | src/hooks/url.rs | 8 | ||||
| -rw-r--r-- | 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<String, Error> { } #[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<String> = 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>) -> 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, |
