refactored dice output

This commit is contained in:
Lilith Schier 2026-08-11 22:04:00 +02:00
parent 7b6eecf40e
commit 8e2f75d624
2 changed files with 259 additions and 78 deletions

View file

@ -14,7 +14,7 @@ use serenity::builder::{
};
use serenity::{async_trait, prelude::*};
use std::sync::Arc;
use tracing::{info, warn};
use tracing::{debug, info, warn};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@ -46,7 +46,7 @@ impl EventHandler for Handler {
match event {
FullEvent::InteractionCreate { interaction, .. } => {
if let Interaction::Command(command) = interaction {
info!("Received command interaction: {command:#?}");
debug!("Received command interaction: {command:#?}");
let content = match command.data.name.as_str() {
"roll" => {
@ -62,14 +62,12 @@ impl EventHandler for Handler {
let data = CreateInteractionResponseMessage::new().content(content);
let builder = CreateInteractionResponse::Message(data);
if let Err(why) = command.create_response(&ctx.http, builder).await {
info!("Cannot respond to slash command: {why}");
warn!("Cannot respond to slash command: {why}");
}
}
}
}
FullEvent::Ready { data_about_bot, .. } => {
info!("{} is connected!", data_about_bot.user.name);
let global_command = Command::create_global_command(
&ctx.http,
CreateCommand::new("roll")
@ -102,7 +100,7 @@ impl EventHandler for Handler {
)
.await;
info!("I created the following global slash command: {global_command:#?}");
debug!("I created the following global slash command: {global_command:#?}");
info!("{} is connected!", data_about_bot.user.name);
}
@ -200,8 +198,20 @@ pub async fn roll(ctx: &Context, command: &CommandInteraction) -> anyhow::Result
));
}
for _ in 0..repeat {
let result = match expression.collect_evaluation(&mut rng) {
Ok(res) => res,
Err(err) => {
command
.create_followup(
&ctx.http,
CreateInteractionResponseFollowup::new().content(format!("{}", err)),
)
.await?;
return Err(err);
}
};
text_components.push(CreateContainerComponent::TextDisplay(
CreateTextDisplay::new(format!("{}\n", expression.collect_evaluation(&mut rng)?)),
CreateTextDisplay::new(format!("{}\n", result)),
));
}
if fixed_seed.is_some() {