Compare commits

..

1 Commits

Author SHA1 Message Date
projectmoon bf1e2a248f Convert command execution to use results.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-01-30 14:17:34 +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
/// displayed in the user's client depending on its capabilities.
#[derive(Debug)]
pub struct Execution {
pub struct Response {
plain: String,
html: String,
}
impl Execution {
pub fn new(plain: String, html: String) -> CommandResult {
Ok(Execution { plain, html })
impl Response {
pub fn success(plain: String, html: String) -> CommandResult {
Ok(Response { plain, html })
}
/// Response message in plain text.
@ -75,7 +75,7 @@ impl ExecutionError {
/// Wraps either a successful command execution response, or an error
/// that occurred.
pub type CommandResult = Result<Execution, ExecutionError>;
pub type CommandResult = Result<Response, ExecutionError>;
/// Extract response messages out of a type, whether it is success or
/// failure.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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