The world's most clever kitty cat
at main 44 lines 1.4 kB view raw
1use std::sync::Arc; 2 3use twilight_interactions::command::{CommandModel, CreateCommand}; 4use twilight_model::application::interaction::{Interaction, application_command::CommandData}; 5 6use crate::{BotContext, cmd::DEFER_INTER_RESP, prelude::*}; 7 8#[derive(CommandModel, CreateCommand)] 9#[command( 10 name = "markov", 11 desc = "Trigger a response from bingus! Uses the last word you sent to start the chain" 12)] 13pub struct MarkovCommand { 14 /// Prompt bingus should reply to 15 prompt: String, 16} 17 18impl MarkovCommand { 19 pub async fn handle(inter: Interaction, data: CommandData, ctx: Arc<BotContext>) -> Result { 20 let Self { prompt } = 21 Self::from_interaction(data.into()).context("Failed to parse command data")?; 22 23 let client = ctx.http.interaction(ctx.app_id); 24 25 client 26 .create_response(inter.id, &inter.token, &DEFER_INTER_RESP) 27 .await 28 .context("Failed to defer")?; 29 30 let brain = ctx.brain_handle.read().await; 31 let content = brain 32 .respond(&prompt, false, true, None) 33 .unwrap_or_else(|| String::from("> Bingus couldn't think of what to say!")); 34 drop(brain); 35 36 client 37 .update_response(&inter.token) 38 .content(Some(content.as_str())) 39 .await 40 .context("Failed to reply")?; 41 42 Ok(()) 43 } 44}