diff --git a/src/bot/command_execution.rs b/src/bot/command_execution.rs index 9005206..528d664 100644 --- a/src/bot/command_execution.rs +++ b/src/bot/command_execution.rs @@ -1,4 +1,4 @@ -use crate::commands::{execute_command, ExecutionError, ExecutionResult, ResponseExtractor}; +use crate::commands::{execute_command, ExecutionResult, ResponseExtractor}; use crate::context::{Context, RoomContext}; use crate::db::sqlite::Database; use crate::error::BotError; @@ -34,7 +34,7 @@ pub(super) async fn handle_multiple_results( respond_to, respond_to ); - let errors: Vec<(&str, &ExecutionError)> = results + let errors: Vec<(&str, &BotError)> = results .into_iter() .filter_map(|(cmd, result)| match result { Err(e) => Some((cmd.as_ref(), e)), @@ -96,7 +96,7 @@ pub(super) async fn execute( stream::iter(commands) .then(|command| async move { match create_context(db, client, room, sender, command).await { - Err(e) => (command.to_owned(), Err(ExecutionError(e))), + Err(e) => (command.to_owned(), Err(e)), Ok(ctx) => { let cmd_result = execute_command(&ctx).await; (command.to_owned(), cmd_result) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 6a7d43b..965b7f3 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -1,4 +1,4 @@ -use crate::commands::{ExecutionError, ExecutionResult}; +use crate::commands::ExecutionResult; use crate::config::*; use crate::db::sqlite::Database; use crate::db::DbState; @@ -129,10 +129,7 @@ impl DiceBot { let results: Vec<(String, ExecutionResult)> = if commands.len() < MAX_COMMANDS_PER_MESSAGE { command_execution::execute(commands, &self.db, &self.client, room, sender).await } else { - vec![( - "".to_owned(), - Err(ExecutionError(BotError::MessageTooLarge)), - )] + vec![("".to_owned(), Err(BotError::MessageTooLarge))] }; results diff --git a/src/commands/management.rs b/src/commands/management.rs index d161105..2c238bb 100644 --- a/src/commands/management.rs +++ b/src/commands/management.rs @@ -1,4 +1,4 @@ -use super::{Command, Execution, ExecutionError, ExecutionResult}; +use super::{Command, Execution, ExecutionResult}; use crate::db::Users; use crate::error::BotError::{AccountDoesNotExist, PasswordCreationError}; use crate::logic::hash_password; @@ -35,7 +35,7 @@ impl Command for RegisterCommand { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { if ctx.account.is_registered() { - return Err(ExecutionError(BotError::AccountAlreadyExists)); + return Err(BotError::AccountAlreadyExists); } let user = User { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 8553791..2f81af2 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3,7 +3,6 @@ use crate::error::BotError; use async_trait::async_trait; use log::{error, info}; use thiserror::Error; -use BotError::DataError; pub mod basic_rolling; pub mod cofd; @@ -46,29 +45,9 @@ impl Execution { } } -/// Wraps a command execution failure. Provides HTML formatting for -/// any error message from the BotError type, similar to how Execution -/// provides formatting for successfully executed commands. -#[derive(Error, Debug)] -#[error("{0}")] -pub struct ExecutionError(#[from] pub BotError); - -impl From for ExecutionError { - fn from(error: crate::db::errors::DataError) -> Self { - Self(DataError(error)) - } -} - -impl ExecutionError { - /// Error message in bolded HTML. - pub fn html(&self) -> String { - format!("{}", self.0) - } -} - /// Wraps either a successful command execution response, or an error /// that occurred. -pub type ExecutionResult = Result; +pub type ExecutionResult = Result; /// Extract response messages out of a type, whether it is success or /// failure. @@ -90,7 +69,9 @@ impl ResponseExtractor for ExecutionResult { match self { Ok(resp) => format!("

{}

{}

", username, resp.html).replace("\n", "
"), - Err(e) => format!("

{}

{}

", username, e.html()).replace("\n", "
"), + Err(e) => { + format!("

{}

{}

", username, e).replace("\n", "
") + } } } } @@ -125,7 +106,7 @@ pub async fn execute_command(ctx: &Context<'_>) -> ExecutionResult { let result = match execution_allowed(cmd.as_ref(), ctx) { Ok(_) => cmd.execute(ctx).await, - Err(e) => Err(ExecutionError(e.into())), + Err(e) => Err(e.into()), }; log_command(cmd.as_ref(), ctx, &result);