From 410784cf33de212e8da20cbe4a0e4653a090c84f Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:35:16 +0800 Subject: [PATCH] feat(experimental): valfisk intelligence --- src/commands/fun/intelligence.rs | 38 ++++++++++++++++++++++++++++++++ src/commands/fun/mod.rs | 1 + src/commands/mod.rs | 1 + 3 files changed, 40 insertions(+) create mode 100644 src/commands/fun/intelligence.rs diff --git a/src/commands/fun/intelligence.rs b/src/commands/fun/intelligence.rs new file mode 100644 index 0000000..3296a3d --- /dev/null +++ b/src/commands/fun/intelligence.rs @@ -0,0 +1,38 @@ +use std::env; + +use color_eyre::eyre::Result; +use serde::Deserialize; +use serde_json::json; + +use crate::{reqwest_client::HTTP, Context}; + +static ASK_API_URL: &str = "https://intelligence.valfisk.ryanccn.dev/ask"; + +#[derive(Deserialize)] +struct AskResponse { + response: String, +} + +/// Ask Valfisk Intelligenceā„¢ +#[poise::command(slash_command, guild_only)] +#[tracing::instrument(skip(ctx), fields(channel = ctx.channel_id().get(), author = ctx.author().id.get()))] +pub async fn ask( + ctx: Context<'_>, + #[description = "The query to ask about"] query: String, +) -> Result<()> { + ctx.defer().await?; + + let secret = env::var("INTELLIGENCE_SECRET")?; + let resp: AskResponse = HTTP + .post(ASK_API_URL) + .bearer_auth(secret) + .json(&json!({ "query": query })) + .send() + .await? + .json() + .await?; + + ctx.say(&resp.response).await?; + + Ok(()) +} diff --git a/src/commands/fun/mod.rs b/src/commands/fun/mod.rs index 7cdb716..f6b9498 100644 --- a/src/commands/fun/mod.rs +++ b/src/commands/fun/mod.rs @@ -1,4 +1,5 @@ pub mod autoreply; +pub mod intelligence; pub mod owo; pub mod pomelo; pub mod shiggy; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index e966cb5..ece0ff2 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -29,6 +29,7 @@ pub fn to_vec() -> Vec< command!(useful, translate), command!(useful, suppress_embeds), command!(fun, autoreply), + command!(fun, intelligence, ask), command!(fun, owo), command!(fun, pomelo), command!(fun, shiggy),