Use active room in relevant commands.
This commit is contained in:
parent
3d2eb14cd3
commit
b7393c1907
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue