45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
use poise::{CreateReply, Modal, send_application_reply};
|
|
use poise::serenity_prelude::CreateEmbed;
|
|
|
|
use crate::{Context, Error};
|
|
use crate::claude::DeathByHuaxuResponse;
|
|
use crate::errors::HuaxuError;
|
|
|
|
#[derive(Debug, Modal)]
|
|
struct EvaluationModal {
|
|
#[paragraph]
|
|
#[max_length = 200]
|
|
scenario: String,
|
|
#[paragraph]
|
|
#[max_length = 400]
|
|
solution: String,
|
|
}
|
|
|
|
/// Let Huaxu decide your fate!
|
|
#[poise::command(slash_command)]
|
|
pub(crate) async fn death_by_huaxu(ctx: Context<'_>) -> Result<(), Error> {
|
|
let data = match EvaluationModal::execute(ctx).await? {
|
|
Some(data) => data,
|
|
None => return Err(HuaxuError::EmptyModal.into()),
|
|
};
|
|
|
|
let handle = send_application_reply(ctx, CreateReply::default().content("Thinking....")).await?;
|
|
let response = ctx.data().claude.death_by_huaxu(&data.scenario, &data.solution).await?;
|
|
handle.edit(ctx.into(), CreateReply::default().embed(build_embed(
|
|
&response,
|
|
&data.scenario,
|
|
&data.solution,
|
|
))).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn build_embed(response: &DeathByHuaxuResponse, scenario: &str, solution: &str) -> CreateEmbed {
|
|
CreateEmbed::default()
|
|
.fields(vec![
|
|
("Scenario", scenario, false),
|
|
("Solution", solution, false),
|
|
("Evaluation", &response.evaluation, false),
|
|
("Verdict", &response.verdict, false),
|
|
])
|
|
}
|