From b7393c19079591f4e6b424481b35f55e2e888bf0 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Sun, 30 May 2021 14:17:33 +0000 Subject: [PATCH] Use active room in relevant commands. --- src/commands/variables.rs | 8 ++++---- src/context.rs | 4 ++++ src/cthulhu/dice.rs | 7 ++++++- src/logic.rs | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/commands/variables.rs b/src/commands/variables.rs index 6b1a242..26124d5 100644 --- a/src/commands/variables.rs +++ b/src/commands/variables.rs @@ -35,7 +35,7 @@ impl Command for GetAllVariablesCommand { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { let variables = ctx .db - .get_user_variables(&ctx.username, ctx.room_id().as_str()) + .get_user_variables(&ctx.username, ctx.active_room_id().as_str()) .await?; let mut variable_list: Vec = variables @@ -85,7 +85,7 @@ impl Command for GetVariableCommand { let name = &self.0; let result = ctx .db - .get_user_variable(&ctx.username, ctx.room_id().as_str(), name) + .get_user_variable(&ctx.username, ctx.active_room_id().as_str(), name) .await; let value = match result { @@ -131,7 +131,7 @@ impl Command for SetVariableCommand { let value = self.1; ctx.db - .set_user_variable(&ctx.username, ctx.room_id().as_str(), name, value) + .set_user_variable(&ctx.username, ctx.active_room_id().as_str(), name, value) .await?; let content = format!("{} = {}", name, value); @@ -170,7 +170,7 @@ impl Command for DeleteVariableCommand { let name = &self.0; let result = ctx .db - .delete_user_variable(&ctx.username, ctx.room_id().as_str(), name) + .delete_user_variable(&ctx.username, ctx.active_room_id().as_str(), name) .await; let value = match result { diff --git a/src/context.rs b/src/context.rs index 28ba5b0..20b0f6f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -20,6 +20,10 @@ pub struct Context<'a> { } impl Context<'_> { + pub fn active_room_id(&self) -> &RoomId { + self.active_room.id + } + pub fn room_id(&self) -> &RoomId { self.origin_room.id } diff --git a/src/cthulhu/dice.rs b/src/cthulhu/dice.rs index ea63ed6..aa856ce 100644 --- a/src/cthulhu/dice.rs +++ b/src/cthulhu/dice.rs @@ -380,7 +380,12 @@ async fn update_skill(ctx: &Context<'_>, variable: &str, value: u32) -> Result<( use std::convert::TryInto; let value: i32 = value.try_into()?; ctx.db - .set_user_variable(&ctx.username, &ctx.room_id().as_str(), variable, value) + .set_user_variable( + &ctx.username, + &ctx.active_room_id().as_str(), + variable, + value, + ) .await?; Ok(()) } diff --git a/src/logic.rs b/src/logic.rs index 58dfd06..70fa796 100644 --- a/src/logic.rs +++ b/src/logic.rs @@ -27,7 +27,7 @@ pub async fn calculate_dice_amount(amounts: &[Amount], ctx: &Context<'_>) -> Res let stream = stream::iter(amounts); let variables = &ctx .db - .get_user_variables(&ctx.username, ctx.room_id().as_str()) + .get_user_variables(&ctx.username, ctx.active_room_id().as_str()) .await?; use DiceRollingError::VariableNotFound;