aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Leitner <lrnz.ltnr@gmail.com>2021-10-11 14:59:59 +0200
committerLorenz Leitner <lrnz.ltnr@gmail.com>2021-10-12 12:06:57 +0200
commit1dd4a4e70a9ac757ca2f539221e4e1a5b4fbf89d (patch)
tree45f3b51e356359ec1d1859ec62ee98fa39a9ed51
parentAdd test (diff)
Add wa as hook
-rw-r--r--src/hooks/wa.rs16
-rw-r--r--src/main.rs5
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
+ ),
];
}
nd bump versionMax Audron-9/+10 2021-10-20change hook errors to be logged as warningsMax Audron-3/+3 2021-10-20fix configuration not loading correctly on release buildsMax Audron-8/+23 2021-10-19replace sedregex crate8-rework-sedMax Audron-20/+358 2021-10-19add formatting trait for irc codesMax Audron-0/+129 2021-10-17fix links in readmeMax Audron-2/+2