aboutsummaryrefslogtreecommitdiff
path: root/src/hooks
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 /src/hooks
parentAdd test (diff)
Add wa as hook
Diffstat (limited to '')
-rw-r--r--src/hooks/wa.rs16
1 files changed, 16 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 {