Use active room in relevant commands.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
projectmoon 2021-05-30 14:17:33 +00:00
parent 3d2eb14cd3
commit b7393c1907
4 changed files with 15 additions and 6 deletions

View File

@ -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<String> = 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 {

View File

@ -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
}

View File

@ -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(())
}

View File

@ -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;