Skip to content
Snippets Groups Projects
Commit eded585f authored by Jason Volk's avatar Jason Volk
Browse files

rename some command types for consistency


Signed-off-by: default avatarJason Volk <jason@zemos.net>
parent a5523212
No related branches found
No related tags found
1 merge request!545Admin command tracing capture
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
OwnedEventId, OwnedEventId,
}; };
use service::{ use service::{
admin::{CommandInput, CommandOutput, CommandResult, HandlerResult}, admin::{CommandInput, CommandOutput, HandlerFuture, HandlerResult},
Services, Services,
}; };
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
pub(super) fn complete(line: &str) -> String { complete_command(AdminCommand::command(), line) } pub(super) fn complete(line: &str) -> String { complete_command(AdminCommand::command(), line) }
#[must_use] #[must_use]
pub(super) fn handle(services: Arc<Services>, command: CommandInput) -> HandlerResult { pub(super) fn handle(services: Arc<Services>, command: CommandInput) -> HandlerFuture {
Box::pin(handle_command(services, command)) Box::pin(handle_command(services, command))
} }
#[tracing::instrument(skip_all, name = "admin")] #[tracing::instrument(skip_all, name = "admin")]
async fn handle_command(services: Arc<Services>, command: CommandInput) -> CommandResult { async fn handle_command(services: Arc<Services>, command: CommandInput) -> HandlerResult {
AssertUnwindSafe(Box::pin(process_command(services, &command))) AssertUnwindSafe(Box::pin(process_command(services, &command)))
.catch_unwind() .catch_unwind()
.await .await
...@@ -40,7 +40,7 @@ async fn process_command(services: Arc<Services>, command: &CommandInput) -> Com ...@@ -40,7 +40,7 @@ async fn process_command(services: Arc<Services>, command: &CommandInput) -> Com
.and_then(|content| reply(content, command.reply_id.clone())) .and_then(|content| reply(content, command.reply_id.clone()))
} }
fn handle_panic(error: &Error, command: CommandInput) -> CommandResult { fn handle_panic(error: &Error, command: CommandInput) -> HandlerResult {
let link = "Please submit a [bug report](https://github.com/girlbossceo/conduwuit/issues/new). 🥺"; 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 msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}");
let content = RoomMessageEventContent::notice_markdown(msg); let content = RoomMessageEventContent::notice_markdown(msg);
......
...@@ -51,9 +51,9 @@ pub struct CommandInput { ...@@ -51,9 +51,9 @@ pub struct CommandInput {
} }
pub type Completer = fn(&str) -> String; pub type Completer = fn(&str) -> String;
pub type Handler = fn(Arc<crate::Services>, CommandInput) -> HandlerResult; pub type Handler = fn(Arc<crate::Services>, CommandInput) -> HandlerFuture;
pub type HandlerResult = Pin<Box<dyn Future<Output = CommandResult> + Send>>; pub type HandlerFuture = Pin<Box<dyn Future<Output = HandlerResult> + Send>>;
pub type CommandResult = Result<CommandOutput, Error>; pub type HandlerResult = Result<CommandOutput>;
pub type CommandOutput = Option<RoomMessageEventContent>; pub type CommandOutput = Option<RoomMessageEventContent>;
const COMMAND_QUEUE_LIMIT: usize = 512; const COMMAND_QUEUE_LIMIT: usize = 512;
...@@ -173,7 +173,7 @@ async fn handle_command(&self, command: CommandInput) { ...@@ -173,7 +173,7 @@ async fn handle_command(&self, command: CommandInput) {
} }
} }
async fn process_command(&self, command: CommandInput) -> CommandResult { async fn process_command(&self, command: CommandInput) -> HandlerResult {
let Some(services) = self let Some(services) = self
.services .services
.services .services
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment