From 68f42baf736258b90924cce1aee2511765d1abc2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 25 Jul 2024 22:13:22 +0000 Subject: [PATCH] rename admin Command to CommandInput Signed-off-by: Jason Volk --- src/admin/handler.rs | 10 +++++----- src/service/admin/mod.rs | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/admin/handler.rs b/src/admin/handler.rs index 6acb19bf..26a5ea41 100644 --- a/src/admin/handler.rs +++ b/src/admin/handler.rs @@ -11,7 +11,7 @@ use ruma::{ OwnedEventId, }; use service::{ - admin::{Command, CommandOutput, CommandResult, HandlerResult}, + admin::{CommandInput, CommandOutput, CommandResult, HandlerResult}, Services, }; @@ -30,10 +30,10 @@ pub(super) fn complete(line: &str) -> String { } #[must_use] -pub(super) fn handle(command: Command) -> HandlerResult { Box::pin(handle_command(command)) } +pub(super) fn handle(command: CommandInput) -> HandlerResult { Box::pin(handle_command(command)) } #[tracing::instrument(skip_all, name = "admin")] -async fn handle_command(command: Command) -> CommandResult { +async fn handle_command(command: CommandInput) -> CommandResult { AssertUnwindSafe(Box::pin(process_command(&command))) .catch_unwind() .await @@ -41,7 +41,7 @@ async fn handle_command(command: Command) -> CommandResult { .or_else(|error| handle_panic(&error, command)) } -async fn process_command(command: &Command) -> CommandOutput { +async fn process_command(command: &CommandInput) -> CommandOutput { Handler { services: service::services(), } @@ -50,7 +50,7 @@ async fn process_command(command: &Command) -> CommandOutput { .and_then(|content| reply(content, command.reply_id.clone())) } -fn handle_panic(error: &Error, command: Command) -> CommandResult { +fn handle_panic(error: &Error, command: CommandInput) -> CommandResult { let link = "Please submit a [bug report](https://github.com/girlbossceo/conduwuit/issues/new). 🥺"; let msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}"); let content = RoomMessageEventContent::notice_markdown(msg); diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index b3879deb..6241c668 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -26,8 +26,8 @@ use crate::{globals, rooms, rooms::state::RoomMutexGuard, Dep}; pub struct Service { services: Services, - sender: Sender, - receiver: Mutex>, + sender: Sender, + receiver: Mutex>, pub handle: RwLock>, pub complete: StdRwLock>, #[cfg(feature = "console")] @@ -44,13 +44,13 @@ struct Services { } #[derive(Debug)] -pub struct Command { +pub struct CommandInput { pub command: String, pub reply_id: Option, } pub type Completer = fn(&str) -> String; -pub type Handler = fn(Command) -> HandlerResult; +pub type Handler = fn(CommandInput) -> HandlerResult; pub type HandlerResult = Pin + Send>>; pub type CommandResult = Result; pub type CommandOutput = Option; @@ -129,7 +129,7 @@ impl Service { } pub async fn command(&self, command: String, reply_id: Option) { - self.send(Command { + self.send(CommandInput { command, reply_id, }) @@ -139,7 +139,7 @@ impl Service { pub async fn command_in_place( &self, command: String, reply_id: Option, ) -> Result> { - self.process_command(Command { + self.process_command(CommandInput { command, reply_id, }) @@ -153,7 +153,7 @@ impl Service { .map(|complete| complete(command)) } - async fn send(&self, message: Command) { + async fn send(&self, message: CommandInput) { debug_assert!(!self.sender.is_closed(), "channel closed"); self.sender.send_async(message).await.expect("message sent"); } @@ -163,7 +163,7 @@ impl Service { self.console.handle_signal(sig).await; } - async fn handle_command(&self, command: Command) { + async fn handle_command(&self, command: CommandInput) { match self.process_command(command).await { Ok(Some(output)) => self.handle_response(output).await, Ok(None) => debug!("Command successful with no response"), @@ -171,7 +171,7 @@ impl Service { } } - async fn process_command(&self, command: Command) -> CommandResult { + async fn process_command(&self, command: CommandInput) -> CommandResult { if let Some(handle) = self.handle.read().await.as_ref() { handle(command).await } else {