Remove code comments
This commit is contained in:
parent
a5e58493d8
commit
52d7c13013
17 changed files with 18 additions and 335 deletions
|
|
@ -1,8 +1,3 @@
|
|||
//! A dice roller: `roll 2d6`, `roll d20`, or `roll` (defaults to `1d6`).
|
||||
//!
|
||||
//! Demonstrates a *stateful* module — it carries its own tiny PRNG, seeded once
|
||||
//! at construction — while keeping the crate dependency-free (no `rand`).
|
||||
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::bot::module::{Action, Command, CommandSpec, Module};
|
||||
|
|
@ -13,12 +8,9 @@ const COMMANDS: &[CommandSpec] = &[CommandSpec {
|
|||
about: "roll N dice of M sides (default 1d6), e.g. roll 2d20",
|
||||
}];
|
||||
|
||||
/// Upper bounds to keep output (and the channel) sane.
|
||||
const MAX_DICE: u64 = 100;
|
||||
const MAX_SIDES: u64 = 1000;
|
||||
|
||||
/// Dice roller with a self-contained xorshift PRNG — fine for dice, not for
|
||||
/// anything security-sensitive.
|
||||
pub struct Dice {
|
||||
rng: u64,
|
||||
}
|
||||
|
|
@ -29,7 +21,7 @@ impl Dice {
|
|||
.duration_since(UNIX_EPOCH)
|
||||
.map(|d| d.as_nanos() as u64)
|
||||
.unwrap_or(0x9E37_79B9_7F4A_7C15);
|
||||
Dice { rng: seed | 1 } // never seed to 0 (xorshift would stay stuck)
|
||||
Dice { rng: seed | 1 }
|
||||
}
|
||||
|
||||
fn next_u64(&mut self) -> u64 {
|
||||
|
|
@ -41,7 +33,6 @@ impl Dice {
|
|||
x
|
||||
}
|
||||
|
||||
/// Roll a single die in `1..=sides`.
|
||||
fn die(&mut self, sides: u64) -> u64 {
|
||||
self.next_u64() % sides + 1
|
||||
}
|
||||
|
|
@ -81,8 +72,6 @@ impl Module for Dice {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parse `NdM` / `dM` / `M` into `(count, sides)` within sane bounds. A bare
|
||||
/// number `M` means `1dM`.
|
||||
fn parse_spec(s: &str) -> Option<(u64, u64)> {
|
||||
let (count, sides) = match s.split_once('d') {
|
||||
Some((c, m)) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue