diff options
| author | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-11 14:59:59 +0200 |
|---|---|---|
| committer | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-12 12:06:57 +0200 |
| commit | 1dd4a4e70a9ac757ca2f539221e4e1a5b4fbf89d (patch) | |
| tree | 45f3b51e356359ec1d1859ec62ee98fa39a9ed51 | |
| parent | Add test (diff) | |
Add wa as hook
Diffstat (limited to '')
| -rw-r--r-- | src/hooks/wa.rs | 16 | ||||
| -rw-r--r-- | src/main.rs | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/hooks/wa.rs b/src/hooks/wa.rs index 7d087ea..e51aa47 100644 --- a/src/hooks/wa.rs +++ b/src/hooks/wa.rs @@ -1,9 +1,11 @@ use crate::util::web::shorten_url; use anyhow::{Context, Error, Result}; use futures::try_join; +use irc::client::prelude::*; use reqwest::{get, Url}; use serde::{Deserialize, Serialize}; use serde_json::Result as SerdeJsonResult; +use macros::privmsg; #[derive(Serialize, Deserialize, Debug)] struct WaResponse { @@ -103,6 +105,20 @@ async fn wa_query(query_str: &str, base_url: Option<&str>) -> Result<String, Err )) } +pub async fn wa(bot: &crate::Bot, msg: Message) -> Result<()> { + privmsg!(msg, { + let mut chars = text.chars(); + chars.next(); + chars.next_back(); + let content = chars.as_str(); + + bot.send_privmsg( + msg.response_target().context("failed to get response target")?, + &wa_query(content, None).await? + )?; + }) +} + #[cfg(test)] mod tests { diff --git a/src/main.rs b/src/main.rs index 9ab7f6c..f337613 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,5 +52,10 @@ async fn main() { "Prints some info about this kitty cat", catinator::hooks::about ), + async command( + "wa", + "Returns Wolfram Alpha results for a query", + catinator::hooks::wa::wa + ), ]; } |
