tenebrous-dicebot/src/commands/cofd.rs

26 lines
728 B
Rust
Raw Normal View History

use super::{Command, CommandResult, Execution};
2020-10-31 12:40:44 +00:00
use crate::cofd::dice::{roll_pool, DicePool, DicePoolWithContext};
use crate::context::Context;
use async_trait::async_trait;
pub struct PoolRollCommand(pub DicePool);
#[async_trait]
impl Command for PoolRollCommand {
fn name(&self) -> &'static str {
"roll dice pool"
}
async fn execute(&self, ctx: &Context<'_>) -> CommandResult {
2020-10-31 12:40:44 +00:00
let pool_with_ctx = DicePoolWithContext(&self.0, ctx);
let rolled_pool = roll_pool(&pool_with_ctx).await?;
2020-10-31 12:40:44 +00:00
let html = format!(
"<p><strong>Pool:</strong> {}</p><p><strong>Result</strong>: {}</p>",
rolled_pool, rolled_pool.roll
);
2020-10-31 12:40:44 +00:00
Execution::new(html)
2020-10-31 12:40:44 +00:00
}
}