Add an is_secure attribute for commands.

This commit is contained in:
projectmoon 2021-05-21 15:32:08 +00:00
parent 5643677627
commit 9de74d05a9
7 changed files with 41 additions and 0 deletions

View File

@ -12,6 +12,10 @@ impl Command for RollCommand {
"roll regular dice" "roll regular dice"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, _ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, _ctx: &Context<'_>) -> ExecutionResult {
let roll = self.0.roll(); let roll = self.0.roll();
let html = format!( let html = format!(

View File

@ -11,6 +11,10 @@ impl Command for PoolRollCommand {
"roll dice pool" "roll dice pool"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let pool_with_ctx = DicePoolWithContext(&self.0, ctx); let pool_with_ctx = DicePoolWithContext(&self.0, ctx);
let rolled_pool = roll_pool(&pool_with_ctx).await?; let rolled_pool = roll_pool(&pool_with_ctx).await?;

View File

@ -14,6 +14,10 @@ impl Command for CthRoll {
"roll percentile dice" "roll percentile dice"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let roll_with_ctx = DiceRollWithContext(&self.0, ctx); let roll_with_ctx = DiceRollWithContext(&self.0, ctx);
let executed_roll = regular_roll(&roll_with_ctx).await?; let executed_roll = regular_roll(&roll_with_ctx).await?;
@ -35,6 +39,10 @@ impl Command for CthAdvanceRoll {
"roll skill advancement dice" "roll skill advancement dice"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let roll_with_ctx = AdvancementRollWithContext(&self.0, ctx); let roll_with_ctx = AdvancementRollWithContext(&self.0, ctx);
let executed_roll = advancement_roll(&roll_with_ctx).await?; let executed_roll = advancement_roll(&roll_with_ctx).await?;

View File

@ -12,6 +12,10 @@ impl Command for ResyncCommand {
"resync room information" "resync room information"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let our_username: Option<UserId> = ctx.matrix_client.user_id().await; let our_username: Option<UserId> = ctx.matrix_client.user_id().await;
let our_username: &str = our_username.as_ref().map_or("", UserId::as_str); let our_username: &str = our_username.as_ref().map_or("", UserId::as_str);

View File

@ -11,6 +11,10 @@ impl Command for HelpCommand {
"help information" "help information"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, _ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, _ctx: &Context<'_>) -> ExecutionResult {
let help = match &self.0 { let help = match &self.0 {
Some(topic) => topic.message(), Some(topic) => topic.message(),

View File

@ -96,6 +96,7 @@ impl ResponseExtractor for ExecutionResult {
pub trait Command: Send + Sync { pub trait Command: Send + Sync {
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult; async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult;
fn name(&self) -> &'static str; fn name(&self) -> &'static str;
fn is_secure(&self) -> bool;
} }
/// Attempt to execute a command, and return the content that should /// Attempt to execute a command, and return the content that should

View File

@ -12,6 +12,10 @@ impl Command for GetAllVariablesCommand {
"get all variables" "get all variables"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let variables = ctx let variables = ctx
.db .db
@ -43,6 +47,10 @@ impl Command for GetVariableCommand {
"retrieve variable value" "retrieve variable value"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let name = &self.0; let name = &self.0;
let result = ctx let result = ctx
@ -69,6 +77,10 @@ impl Command for SetVariableCommand {
"set variable value" "set variable value"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let name = &self.0; let name = &self.0;
let value = self.1; let value = self.1;
@ -91,6 +103,10 @@ impl Command for DeleteVariableCommand {
"delete variable" "delete variable"
} }
fn is_secure(&self) -> bool {
false
}
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
let name = &self.0; let name = &self.0;
let result = ctx let result = ctx