rename admin Command to CommandInput
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
271959ee27
commit
68f42baf73
2 changed files with 14 additions and 14 deletions
|
@ -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);
|
||||
|
|
|
@ -26,8 +26,8 @@ use crate::{globals, rooms, rooms::state::RoomMutexGuard, Dep};
|
|||
|
||||
pub struct Service {
|
||||
services: Services,
|
||||
sender: Sender<Command>,
|
||||
receiver: Mutex<Receiver<Command>>,
|
||||
sender: Sender<CommandInput>,
|
||||
receiver: Mutex<Receiver<CommandInput>>,
|
||||
pub handle: RwLock<Option<Handler>>,
|
||||
pub complete: StdRwLock<Option<Completer>>,
|
||||
#[cfg(feature = "console")]
|
||||
|
@ -44,13 +44,13 @@ struct Services {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Command {
|
||||
pub struct CommandInput {
|
||||
pub command: String,
|
||||
pub reply_id: Option<OwnedEventId>,
|
||||
}
|
||||
|
||||
pub type Completer = fn(&str) -> String;
|
||||
pub type Handler = fn(Command) -> HandlerResult;
|
||||
pub type Handler = fn(CommandInput) -> HandlerResult;
|
||||
pub type HandlerResult = Pin<Box<dyn Future<Output = CommandResult> + Send>>;
|
||||
pub type CommandResult = Result<CommandOutput, Error>;
|
||||
pub type CommandOutput = Option<RoomMessageEventContent>;
|
||||
|
@ -129,7 +129,7 @@ impl Service {
|
|||
}
|
||||
|
||||
pub async fn command(&self, command: String, reply_id: Option<OwnedEventId>) {
|
||||
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<OwnedEventId>,
|
||||
) -> Result<Option<RoomMessageEventContent>> {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue