Compare commits

..

1 Commits

Author SHA1 Message Date
projectmoon 16eb87e50f Convert command execution to use results.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2021-01-30 14:28:14 +00:00
7 changed files with 21 additions and 21 deletions

View File

@ -26,14 +26,14 @@ pub enum CommandError {
/// to the user in both plain text and HTML, one of which will be /// to the user in both plain text and HTML, one of which will be
/// displayed in the user's client depending on its capabilities. /// displayed in the user's client depending on its capabilities.
#[derive(Debug)] #[derive(Debug)]
pub struct Response { pub struct Execution {
plain: String, plain: String,
html: String, html: String,
} }
impl Response { impl Execution {
pub fn success(plain: String, html: String) -> CommandResult { pub fn new(plain: String, html: String) -> CommandResult {
Ok(Response { plain, html }) Ok(Execution { plain, html })
} }
/// Response message in plain text. /// Response message in plain text.
@ -75,7 +75,7 @@ impl ExecutionError {
/// Wraps either a successful command execution response, or an error /// Wraps either a successful command execution response, or an error
/// that occurred. /// that occurred.
pub type CommandResult = Result<Response, ExecutionError>; pub type CommandResult = Result<Execution, ExecutionError>;
/// Extract response messages out of a type, whether it is success or /// Extract response messages out of a type, whether it is success or
/// failure. /// failure.

View File

@ -1,4 +1,4 @@
use super::{Command, CommandResult, Response}; use super::{Command, CommandResult, Execution};
use crate::basic::dice::ElementExpression; use crate::basic::dice::ElementExpression;
use crate::basic::roll::Roll; use crate::basic::roll::Roll;
use crate::context::Context; use crate::context::Context;
@ -20,6 +20,6 @@ impl Command for RollCommand {
self.0, roll self.0, roll
); );
Response::success(plain, html) Execution::new(plain, html)
} }
} }

View File

@ -1,4 +1,4 @@
use super::{Command, CommandResult, Response}; use super::{Command, CommandResult, Execution};
use crate::cofd::dice::{roll_pool, DicePool, DicePoolWithContext}; use crate::cofd::dice::{roll_pool, DicePool, DicePoolWithContext};
use crate::context::Context; use crate::context::Context;
use async_trait::async_trait; use async_trait::async_trait;
@ -21,6 +21,6 @@ impl Command for PoolRollCommand {
rolled_pool, rolled_pool.roll rolled_pool, rolled_pool.roll
); );
Response::success(plain, html) Execution::new(plain, html)
} }
} }

View File

@ -1,4 +1,4 @@
use super::{Command, CommandResult, Response}; use super::{Command, CommandResult, Execution};
use crate::context::Context; use crate::context::Context;
use crate::cthulhu::dice::{regular_roll, AdvancementRoll, DiceRoll, DiceRollWithContext}; use crate::cthulhu::dice::{regular_roll, AdvancementRoll, DiceRoll, DiceRollWithContext};
use async_trait::async_trait; use async_trait::async_trait;
@ -21,7 +21,7 @@ impl Command for CthRoll {
executed_roll, executed_roll.roll executed_roll, executed_roll.roll
); );
Response::success(plain, html) Execution::new(plain, html)
} }
} }
@ -42,6 +42,6 @@ impl Command for CthAdvanceRoll {
self.0, roll self.0, roll
); );
Response::success(plain, html) Execution::new(plain, html)
} }
} }

View File

@ -1,4 +1,4 @@
use super::{Command, CommandResult, Response}; use super::{Command, CommandResult, Execution};
use crate::context::Context; use crate::context::Context;
use crate::logic::record_room_information; use crate::logic::record_room_information;
use async_trait::async_trait; use async_trait::async_trait;
@ -28,6 +28,6 @@ impl Command for ResyncCommand {
let plain = "Room information resynced".to_string(); let plain = "Room information resynced".to_string();
let html = "<p>Room information resynced.</p>".to_string(); let html = "<p>Room information resynced.</p>".to_string();
Response::success(plain, html) Execution::new(plain, html)
} }
} }

View File

@ -1,4 +1,4 @@
use super::{Command, CommandResult, Response}; use super::{Command, CommandResult, Execution};
use crate::context::Context; use crate::context::Context;
use crate::help::HelpTopic; use crate::help::HelpTopic;
use async_trait::async_trait; use async_trait::async_trait;
@ -19,6 +19,6 @@ impl Command for HelpCommand {
let plain = format!("Help: {}", help); let plain = format!("Help: {}", help);
let html = format!("<p><strong>Help:</strong> {}", help.replace("\n", "<br/>")); let html = format!("<p><strong>Help:</strong> {}", help.replace("\n", "<br/>"));
Response::success(plain, html) Execution::new(plain, html)
} }
} }

View File

@ -1,4 +1,4 @@
use super::{Command, CommandResult, Response}; use super::{Command, CommandResult, Execution};
use crate::context::Context; use crate::context::Context;
use crate::db::errors::DataError; use crate::db::errors::DataError;
use crate::db::variables::UserAndRoom; use crate::db::variables::UserAndRoom;
@ -29,7 +29,7 @@ impl Command for GetAllVariablesCommand {
"<p><strong>Variables:</strong><br/>{}", "<p><strong>Variables:</strong><br/>{}",
value.replace("\n", "<br/>") value.replace("\n", "<br/>")
); );
Response::success(plain, html) Execution::new(plain, html)
} }
} }
@ -54,7 +54,7 @@ impl Command for GetVariableCommand {
let plain = format!("Variable: {}", value); let plain = format!("Variable: {}", value);
let html = format!("<p><strong>Variable:</strong> {}", value); let html = format!("<p><strong>Variable:</strong> {}", value);
Response::success(plain, html) Execution::new(plain, html)
} }
} }
@ -76,7 +76,7 @@ impl Command for SetVariableCommand {
let content = format!("{} = {}", name, value); let content = format!("{} = {}", name, value);
let plain = format!("Set Variable: {}", content); let plain = format!("Set Variable: {}", content);
let html = format!("<p><strong>Set Variable:</strong> {}", content); let html = format!("<p><strong>Set Variable:</strong> {}", content);
Response::success(plain, html) Execution::new(plain, html)
} }
} }
@ -101,6 +101,6 @@ impl Command for DeleteVariableCommand {
let plain = format!("Remove Variable: {}", value); let plain = format!("Remove Variable: {}", value);
let html = format!("<p><strong>Remove Variable:</strong> {}", value); let html = format!("<p><strong>Remove Variable:</strong> {}", value);
Response::success(plain, html) Execution::new(plain, html)
} }
} }