Add and use active room value. #80

Manually merged
projectmoon merged 2 commits from use-active-room into master 2021-05-30 15:11:07 +00:00
4 changed files with 15 additions and 6 deletions
Showing only changes of commit b7393c1907 - Show all commits

View File

@ -35,7 +35,7 @@ impl Command for GetAllVariablesCommand {
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let variables = ctx let variables = ctx
.db .db
.get_user_variables(&ctx.username, ctx.room_id().as_str()) .get_user_variables(&ctx.username, ctx.active_room_id().as_str())
.await?; .await?;
let mut variable_list: Vec<String> = variables let mut variable_list: Vec<String> = variables
@ -85,7 +85,7 @@ impl Command for GetVariableCommand {
let name = &self.0; let name = &self.0;
let result = ctx let result = ctx
.db .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; .await;
let value = match result { let value = match result {
@ -131,7 +131,7 @@ impl Command for SetVariableCommand {
let value = self.1; let value = self.1;
ctx.db 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?; .await?;
let content = format!("{} = {}", name, value); let content = format!("{} = {}", name, value);
@ -170,7 +170,7 @@ impl Command for DeleteVariableCommand {
let name = &self.0; let name = &self.0;
let result = ctx let result = ctx
.db .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; .await;
let value = match result { let value = match result {

View File

@ -20,6 +20,10 @@ pub struct Context<'a> {
} }
impl Context<'_> { impl Context<'_> {
pub fn active_room_id(&self) -> &RoomId {
self.active_room.id
}
pub fn room_id(&self) -> &RoomId { pub fn room_id(&self) -> &RoomId {
self.origin_room.id 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; use std::convert::TryInto;
let value: i32 = value.try_into()?; let value: i32 = value.try_into()?;
ctx.db 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?; .await?;
Ok(()) Ok(())
} }

View File

@ -27,7 +27,7 @@ pub async fn calculate_dice_amount(amounts: &[Amount], ctx: &Context<'_>) -> Res
let stream = stream::iter(amounts); let stream = stream::iter(amounts);
let variables = &ctx let variables = &ctx
.db .db
.get_user_variables(&ctx.username, ctx.room_id().as_str()) .get_user_variables(&ctx.username, ctx.active_room_id().as_str())
.await?; .await?;
use DiceRollingError::VariableNotFound; use DiceRollingError::VariableNotFound;