small fixes, rename
This commit is contained in:
parent
2c2c78114f
commit
052d8359c4
4 changed files with 54 additions and 30 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -4,10 +4,7 @@ mod parsing;
|
|||
use anyhow::bail;
|
||||
use dotenv::dotenv;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use serenity::all::{
|
||||
Command, CommandInteraction, CommandOptionType, CreateCommandOption, CreateComponent,
|
||||
FullEvent, Interaction, MessageFlags, ResolvedOption, ResolvedValue,
|
||||
};
|
||||
use serenity::all::{Command, CommandInteraction, CommandOptionType, CreateCommandOption, CreateComponent, FullEvent, Interaction, InteractionContext, MessageFlags, ResolvedOption, ResolvedValue};
|
||||
use serenity::builder::{
|
||||
CreateCommand, CreateContainer, CreateContainerComponent, CreateInteractionResponse,
|
||||
CreateInteractionResponseFollowup, CreateInteractionResponseMessage, CreateTextDisplay,
|
||||
|
|
@ -96,7 +93,10 @@ impl EventHandler for Handler {
|
|||
CommandOptionType::String,
|
||||
"seed",
|
||||
"Roll with a fixed seed. This bot uses xoshiro256++.",
|
||||
)),
|
||||
))
|
||||
.add_context(InteractionContext::Guild)
|
||||
.add_context(InteractionContext::BotDm)
|
||||
.add_context(InteractionContext::PrivateChannel),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
@ -189,7 +189,19 @@ pub async fn roll(ctx: &Context, command: &CommandInteraction) -> anyhow::Result
|
|||
let seed = fixed_seed.unwrap_or_else(|| rand::rng().next_u64());
|
||||
let mut rng = rand_xoshiro::Xoshiro256PlusPlus::seed_from_u64(seed);
|
||||
|
||||
let ev = (expression.average(&mut rng)? * 10.0).round() / 10.0;
|
||||
let average = match expression.average(&mut rng) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
command
|
||||
.create_followup(
|
||||
&ctx.http,
|
||||
CreateInteractionResponseFollowup::new().content(format!("{}", err)),
|
||||
)
|
||||
.await?;
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let ev = (average * 10.0).round() / 10.0;
|
||||
|
||||
let mut text_components = Vec::with_capacity((repeat + 2) as usize);
|
||||
if let Some(description) = description {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue