diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 065a39ee..1a10cf4b 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -87,6 +87,7 @@ enum AppserviceCommand { /// # ``` Register, + #[command(verbatim_doc_comment)] /// Unregister an appservice using its ID /// /// You can find the ID using the `list-appservices` command. @@ -95,6 +96,15 @@ enum AppserviceCommand { appservice_identifier: String, }, + #[command(verbatim_doc_comment)] + /// Show an appservice's config using its ID + /// + /// You can find the ID using the `list-appservices` command. + Show { + /// The appservice to show + appservice_identifier: String, + }, + /// List all the currently registered appservices List, } @@ -434,6 +444,29 @@ impl Service { "Failed to unregister appservice: {e}" )), }, + AppserviceCommand::Show { appservice_identifier } => { + match services() + .appservice + .get_registration(&appservice_identifier) { + Ok(Some(config)) => { + let config_str = serde_yaml::to_string(&config) + .expect("config should've been validated on register"); + let output = format!( + "Config for {}:\n\n```yaml\n{}\n```", + appservice_identifier, + config_str, + ); + let output_html = format!( + "Config for {}:\n\n
{}
", + escape_html(&appservice_identifier), + escape_html(&config_str), + ); + RoomMessageEventContent::text_html(output, output_html) + }, + Ok(None) => RoomMessageEventContent::text_plain("Appservice does not exist."), + Err(_) => RoomMessageEventContent::text_plain("Failed to get appservice."), + } + } AppserviceCommand::List => { if let Ok(appservices) = services() .appservice @@ -917,7 +950,7 @@ impl Service { let text = text.replace("subcommand", "command"); // Escape option names (e.g. ``) since they look like HTML tags - let text = text.replace('<', "<").replace('>', ">"); + let text = escape_html(&text); // Italicize the first line (command name and version text) let re = Regex::new("^(.*?)\n").expect("Regex compilation should not fail"); @@ -1353,6 +1386,10 @@ impl Service { } } +fn escape_html(s: &str) -> String { + s.replace('&', "&").replace('<', "<").replace('>', ">") +} + #[cfg(test)] mod test { use super::*;