rename some command types for consistency
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
a552321287
commit
eded585f79
2 changed files with 8 additions and 8 deletions
|
@ -11,7 +11,7 @@ use ruma::{
|
||||||
OwnedEventId,
|
OwnedEventId,
|
||||||
};
|
};
|
||||||
use service::{
|
use service::{
|
||||||
admin::{CommandInput, CommandOutput, CommandResult, HandlerResult},
|
admin::{CommandInput, CommandOutput, HandlerFuture, HandlerResult},
|
||||||
Services,
|
Services,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ use crate::{admin, admin::AdminCommand, Command};
|
||||||
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
|
||||||
.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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue