mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-02-18 12:42:35 +03:00
Refactor admin code to always defer command processing
This commit is contained in:
parent
7505548b94
commit
677f044d13
3 changed files with 155 additions and 169 deletions
|
@ -1,7 +1,4 @@
|
||||||
use crate::{
|
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||||
database::{admin::AdminCommand, DatabaseGuard},
|
|
||||||
ConduitResult, Error, Ruma,
|
|
||||||
};
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{error::ErrorKind, r0::room::report_content},
|
api::client::{error::ErrorKind, r0::room::report_content},
|
||||||
events::room::message,
|
events::room::message,
|
||||||
|
@ -50,8 +47,8 @@ pub async fn report_event_route(
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
db.admin.send(AdminCommand::SendMessage(
|
db.admin
|
||||||
message::RoomMessageEventContent::text_html(
|
.send_message(message::RoomMessageEventContent::text_html(
|
||||||
format!(
|
format!(
|
||||||
"Report received from: {}\n\n\
|
"Report received from: {}\n\n\
|
||||||
Event ID: {}\n\
|
Event ID: {}\n\
|
||||||
|
@ -75,8 +72,7 @@ pub async fn report_event_route(
|
||||||
body.score,
|
body.score,
|
||||||
RawStr::new(&body.reason).html_escape()
|
RawStr::new(&body.reason).html_escape()
|
||||||
),
|
),
|
||||||
),
|
));
|
||||||
));
|
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
|
|
|
@ -19,25 +19,21 @@ use serde_json::value::to_raw_value;
|
||||||
use tokio::sync::{MutexGuard, RwLock, RwLockReadGuard};
|
use tokio::sync::{MutexGuard, RwLock, RwLockReadGuard};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
pub enum AdminCommand {
|
pub enum AdminRoomEvent {
|
||||||
RegisterAppservice(serde_yaml::Value),
|
ProcessMessage(String),
|
||||||
UnregisterAppservice(String),
|
|
||||||
ListAppservices,
|
|
||||||
ListLocalUsers,
|
|
||||||
ShowMemoryUsage,
|
|
||||||
SendMessage(RoomMessageEventContent),
|
SendMessage(RoomMessageEventContent),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Admin {
|
pub struct Admin {
|
||||||
pub sender: mpsc::UnboundedSender<AdminCommand>,
|
pub sender: mpsc::UnboundedSender<AdminRoomEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Admin {
|
impl Admin {
|
||||||
pub fn start_handler(
|
pub fn start_handler(
|
||||||
&self,
|
&self,
|
||||||
db: Arc<RwLock<Database>>,
|
db: Arc<RwLock<Database>>,
|
||||||
mut receiver: mpsc::UnboundedReceiver<AdminCommand>,
|
mut receiver: mpsc::UnboundedReceiver<AdminRoomEvent>,
|
||||||
) {
|
) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
// TODO: Use futures when we have long admin commands
|
// TODO: Use futures when we have long admin commands
|
||||||
|
@ -56,7 +52,7 @@ impl Admin {
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("#admins:server_name is a valid room alias"),
|
.expect("#admins:server_name is a valid room alias"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.expect("Admin room must exist");
|
||||||
|
|
||||||
let conduit_room = match conduit_room {
|
let conduit_room = match conduit_room {
|
||||||
None => {
|
None => {
|
||||||
|
@ -105,46 +101,13 @@ impl Admin {
|
||||||
let state_lock = mutex_state.lock().await;
|
let state_lock = mutex_state.lock().await;
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
AdminCommand::ListLocalUsers => {
|
AdminRoomEvent::SendMessage(content) => {
|
||||||
match guard.users.list_local_users() {
|
send_message(content, guard, &state_lock);
|
||||||
Ok(users) => {
|
|
||||||
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
|
|
||||||
msg += &users.join("\n");
|
|
||||||
send_message(RoomMessageEventContent::text_plain(&msg), guard, &state_lock);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
send_message(RoomMessageEventContent::text_plain(e.to_string()), guard, &state_lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
AdminCommand::RegisterAppservice(yaml) => {
|
AdminRoomEvent::ProcessMessage(room_message) => {
|
||||||
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
let reply_message = process_admin_message(&*guard, room_message);
|
||||||
}
|
|
||||||
AdminCommand::UnregisterAppservice(service_name) => {
|
send_message(reply_message, guard, &state_lock);
|
||||||
guard.appservice.unregister_appservice(&service_name).unwrap(); // TODO: see above
|
|
||||||
}
|
|
||||||
AdminCommand::ListAppservices => {
|
|
||||||
if let Ok(appservices) = guard.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
|
||||||
let count = appservices.len();
|
|
||||||
let output = format!(
|
|
||||||
"Appservices ({}): {}",
|
|
||||||
count,
|
|
||||||
appservices.into_iter().filter_map(|r| r.ok()).collect::<Vec<_>>().join(", ")
|
|
||||||
);
|
|
||||||
send_message(RoomMessageEventContent::text_plain(output), guard, &state_lock);
|
|
||||||
} else {
|
|
||||||
send_message(RoomMessageEventContent::text_plain("Failed to get appservices."), guard, &state_lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AdminCommand::ShowMemoryUsage => {
|
|
||||||
if let Ok(response) = guard._db.memory_usage() {
|
|
||||||
send_message(RoomMessageEventContent::text_plain(response), guard, &state_lock);
|
|
||||||
} else {
|
|
||||||
send_message(RoomMessageEventContent::text_plain("Failed to get database memory usage.".to_owned()), guard, &state_lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AdminCommand::SendMessage(message) => {
|
|
||||||
send_message(message, guard, &state_lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,67 +118,81 @@ impl Admin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&self, command: AdminCommand) {
|
pub fn process_message(&self, room_message: String) {
|
||||||
self.sender.unbounded_send(command).unwrap();
|
self.sender
|
||||||
|
.unbounded_send(AdminRoomEvent::ProcessMessage(room_message))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_message(&self, message_content: RoomMessageEventContent) {
|
||||||
|
self.sender
|
||||||
|
.unbounded_send(AdminRoomEvent::SendMessage(message_content))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse and process a message from the admin room
|
||||||
|
pub fn process_admin_message(db: &Database, room_message: String) -> RoomMessageEventContent {
|
||||||
|
let mut lines = room_message.lines();
|
||||||
|
let command_line = lines.next().expect("each string has at least one line");
|
||||||
|
let body: Vec<_> = lines.collect();
|
||||||
|
|
||||||
|
let admin_command = match parse_admin_command(&command_line) {
|
||||||
|
Ok(command) => command,
|
||||||
|
Err(error) => {
|
||||||
|
let message = error
|
||||||
|
.to_string()
|
||||||
|
.replace("example.com", db.globals.server_name().as_str());
|
||||||
|
let html_message = usage_to_html(&message);
|
||||||
|
|
||||||
|
return RoomMessageEventContent::text_html(message, html_message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match process_admin_command(db, admin_command, body) {
|
||||||
|
Ok(reply_message) => reply_message,
|
||||||
|
Err(error) => {
|
||||||
|
let markdown_message = format!(
|
||||||
|
"Encountered an error while handling the command:\n\
|
||||||
|
```\n{}\n```",
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
let html_message = format!(
|
||||||
|
"Encountered an error while handling the command:\n\
|
||||||
|
<pre>\n{}\n</pre>",
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
|
||||||
|
RoomMessageEventContent::text_html(markdown_message, html_message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse chat messages from the admin room into an AdminCommand object
|
// Parse chat messages from the admin room into an AdminCommand object
|
||||||
pub fn parse_admin_command(db: &Database, command_line: &str, body: Vec<&str>) -> AdminCommand {
|
fn parse_admin_command(command_line: &str) -> std::result::Result<AdminCommand, String> {
|
||||||
let mut argv: Vec<_> = command_line.split_whitespace().skip(1).collect();
|
// Note: argv[0] is `@conduit:servername:`, which is treated as the main command
|
||||||
|
let mut argv: Vec<_> = command_line.split_whitespace().collect();
|
||||||
let command_name = match argv.get(0) {
|
|
||||||
Some(command) => *command,
|
|
||||||
None => {
|
|
||||||
let markdown_message = "No command given. Use `help` for a list of commands.";
|
|
||||||
let html_message = "No command given. Use <code>help</code> for a list of commands.";
|
|
||||||
|
|
||||||
return AdminCommand::SendMessage(RoomMessageEventContent::text_html(
|
|
||||||
markdown_message,
|
|
||||||
html_message,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Replace `help command` with `command --help`
|
// Replace `help command` with `command --help`
|
||||||
// Clap has a help subcommand, but it omits the long help description.
|
// Clap has a help subcommand, but it omits the long help description.
|
||||||
if argv[0] == "help" {
|
if argv.len() > 1 && argv[1] == "help" {
|
||||||
argv.remove(0);
|
argv.remove(1);
|
||||||
argv.push("--help");
|
argv.push("--help");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backwards compatibility with `register_appservice`-style commands
|
// Backwards compatibility with `register_appservice`-style commands
|
||||||
let command_with_dashes;
|
let command_with_dashes;
|
||||||
if argv[0].contains("_") {
|
if argv.len() > 1 && argv[1].contains("_") {
|
||||||
command_with_dashes = argv[0].replace("_", "-");
|
command_with_dashes = argv[1].replace("_", "-");
|
||||||
argv[0] = &command_with_dashes;
|
argv[1] = &command_with_dashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
match try_parse_admin_command(db, argv, body) {
|
AdminCommand::try_parse_from(argv).map_err(|error| error.to_string())
|
||||||
Ok(admin_command) => admin_command,
|
|
||||||
Err(error) => {
|
|
||||||
let markdown_message = format!(
|
|
||||||
"Encountered an error while handling the `{}` command:\n\
|
|
||||||
```\n{}\n```",
|
|
||||||
command_name, error,
|
|
||||||
);
|
|
||||||
let html_message = format!(
|
|
||||||
"Encountered an error while handling the <code>{}</code> command:\n\
|
|
||||||
<pre>\n{}\n</pre>",
|
|
||||||
command_name, error,
|
|
||||||
);
|
|
||||||
|
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_html(
|
|
||||||
markdown_message,
|
|
||||||
html_message,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(name = "@conduit:example.com", version = env!("CARGO_PKG_VERSION"))]
|
#[clap(name = "@conduit:example.com", version = env!("CARGO_PKG_VERSION"))]
|
||||||
enum AdminCommands {
|
enum AdminCommand {
|
||||||
#[clap(verbatim_doc_comment)]
|
#[clap(verbatim_doc_comment)]
|
||||||
/// Register an appservice using its registration YAML
|
/// Register an appservice using its registration YAML
|
||||||
///
|
///
|
||||||
|
@ -264,49 +241,70 @@ enum AdminCommands {
|
||||||
DatabaseMemoryUsage,
|
DatabaseMemoryUsage,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_parse_admin_command(
|
fn process_admin_command(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
mut argv: Vec<&str>,
|
command: AdminCommand,
|
||||||
body: Vec<&str>,
|
body: Vec<&str>,
|
||||||
) -> Result<AdminCommand> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
argv.insert(0, "@conduit:example.com:");
|
let reply_message_content = match command {
|
||||||
let command = match AdminCommands::try_parse_from(argv) {
|
AdminCommand::RegisterAppservice => {
|
||||||
Ok(command) => command,
|
|
||||||
Err(error) => {
|
|
||||||
let message = error
|
|
||||||
.to_string()
|
|
||||||
.replace("example.com", db.globals.server_name().as_str());
|
|
||||||
let html_message = usage_to_html(&message);
|
|
||||||
|
|
||||||
return Ok(AdminCommand::SendMessage(
|
|
||||||
RoomMessageEventContent::text_html(message, html_message),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let admin_command = match command {
|
|
||||||
AdminCommands::RegisterAppservice => {
|
|
||||||
if body.len() > 2 && body[0].trim() == "```" && body.last().unwrap().trim() == "```" {
|
if body.len() > 2 && body[0].trim() == "```" && body.last().unwrap().trim() == "```" {
|
||||||
let appservice_config = body[1..body.len() - 1].join("\n");
|
let appservice_config = body[1..body.len() - 1].join("\n");
|
||||||
let parsed_config = serde_yaml::from_str::<serde_yaml::Value>(&appservice_config);
|
let parsed_config = serde_yaml::from_str::<serde_yaml::Value>(&appservice_config);
|
||||||
match parsed_config {
|
match parsed_config {
|
||||||
Ok(yaml) => AdminCommand::RegisterAppservice(yaml),
|
Ok(yaml) => match db.appservice.register_appservice(yaml) {
|
||||||
Err(e) => AdminCommand::SendMessage(RoomMessageEventContent::text_plain(
|
Ok(()) => RoomMessageEventContent::text_plain("Appservice registered."),
|
||||||
format!("Could not parse appservice config: {}", e),
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
|
"Failed to register appservice: {}",
|
||||||
|
e
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
|
"Could not parse appservice config: {}",
|
||||||
|
e
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_plain(
|
RoomMessageEventContent::text_plain(
|
||||||
"Expected code block in command body.",
|
"Expected code block in command body. Add --help for details.",
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdminCommands::UnregisterAppservice {
|
AdminCommand::UnregisterAppservice {
|
||||||
appservice_identifier,
|
appservice_identifier,
|
||||||
} => AdminCommand::UnregisterAppservice(appservice_identifier),
|
} => match db.appservice.unregister_appservice(&appservice_identifier) {
|
||||||
AdminCommands::ListAppservices => AdminCommand::ListAppservices,
|
Ok(()) => RoomMessageEventContent::text_plain("Appservice unregistered."),
|
||||||
AdminCommands::ListLocalUsers => AdminCommand::ListLocalUsers,
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
AdminCommands::GetAuthChain { event_id } => {
|
"Failed to unregister appservice: {}",
|
||||||
|
e
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
AdminCommand::ListAppservices => {
|
||||||
|
if let Ok(appservices) = db.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
||||||
|
let count = appservices.len();
|
||||||
|
let output = format!(
|
||||||
|
"Appservices ({}): {}",
|
||||||
|
count,
|
||||||
|
appservices
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|r| r.ok())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
);
|
||||||
|
RoomMessageEventContent::text_plain(output)
|
||||||
|
} else {
|
||||||
|
RoomMessageEventContent::text_plain("Failed to get appservices.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AdminCommand::ListLocalUsers => match db.users.list_local_users() {
|
||||||
|
Ok(users) => {
|
||||||
|
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
|
||||||
|
msg += &users.join("\n");
|
||||||
|
RoomMessageEventContent::text_plain(&msg)
|
||||||
|
}
|
||||||
|
Err(e) => RoomMessageEventContent::text_plain(e.to_string()),
|
||||||
|
},
|
||||||
|
AdminCommand::GetAuthChain { event_id } => {
|
||||||
let event_id = Arc::<EventId>::from(event_id);
|
let event_id = Arc::<EventId>::from(event_id);
|
||||||
if let Some(event) = db.rooms.get_pdu_json(&event_id)? {
|
if let Some(event) = db.rooms.get_pdu_json(&event_id)? {
|
||||||
let room_id_str = event
|
let room_id_str = event
|
||||||
|
@ -320,17 +318,15 @@ pub fn try_parse_admin_command(
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let count = server_server::get_auth_chain(room_id, vec![event_id], db)?.count();
|
let count = server_server::get_auth_chain(room_id, vec![event_id], db)?.count();
|
||||||
let elapsed = start.elapsed();
|
let elapsed = start.elapsed();
|
||||||
return Ok(AdminCommand::SendMessage(
|
RoomMessageEventContent::text_plain(format!(
|
||||||
RoomMessageEventContent::text_plain(format!(
|
"Loaded auth chain with length {} in {:?}",
|
||||||
"Loaded auth chain with length {} in {:?}",
|
count, elapsed
|
||||||
count, elapsed
|
))
|
||||||
)),
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_plain("Event not found."))
|
RoomMessageEventContent::text_plain("Event not found.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdminCommands::ParsePdu => {
|
AdminCommand::ParsePdu => {
|
||||||
if body.len() > 2 && body[0].trim() == "```" && body.last().unwrap().trim() == "```" {
|
if body.len() > 2 && body[0].trim() == "```" && body.last().unwrap().trim() == "```" {
|
||||||
let string = body[1..body.len() - 1].join("\n");
|
let string = body[1..body.len() - 1].join("\n");
|
||||||
match serde_json::from_str(&string) {
|
match serde_json::from_str(&string) {
|
||||||
|
@ -346,30 +342,26 @@ pub fn try_parse_admin_command(
|
||||||
match serde_json::from_value::<PduEvent>(
|
match serde_json::from_value::<PduEvent>(
|
||||||
serde_json::to_value(value).expect("value is json"),
|
serde_json::to_value(value).expect("value is json"),
|
||||||
) {
|
) {
|
||||||
Ok(pdu) => {
|
Ok(pdu) => RoomMessageEventContent::text_plain(format!(
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_plain(
|
"EventId: {:?}\n{:#?}",
|
||||||
format!("EventId: {:?}\n{:#?}", event_id, pdu),
|
event_id, pdu
|
||||||
))
|
)),
|
||||||
}
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
Err(e) => AdminCommand::SendMessage(
|
"EventId: {:?}\nCould not parse event: {}",
|
||||||
RoomMessageEventContent::text_plain(format!(
|
event_id, e
|
||||||
"EventId: {:?}\nCould not parse event: {}",
|
)),
|
||||||
event_id, e
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => AdminCommand::SendMessage(RoomMessageEventContent::text_plain(
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
format!("Invalid json in command body: {}", e),
|
"Invalid json in command body: {}",
|
||||||
|
e
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_plain(
|
RoomMessageEventContent::text_plain("Expected code block in command body.")
|
||||||
"Expected code block in command body.",
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdminCommands::GetPdu { event_id } => {
|
AdminCommand::GetPdu { event_id } => {
|
||||||
let mut outlier = false;
|
let mut outlier = false;
|
||||||
let mut pdu_json = db.rooms.get_non_outlier_pdu_json(&event_id)?;
|
let mut pdu_json = db.rooms.get_non_outlier_pdu_json(&event_id)?;
|
||||||
if pdu_json.is_none() {
|
if pdu_json.is_none() {
|
||||||
|
@ -380,7 +372,7 @@ pub fn try_parse_admin_command(
|
||||||
Some(json) => {
|
Some(json) => {
|
||||||
let json_text =
|
let json_text =
|
||||||
serde_json::to_string_pretty(&json).expect("canonical json is valid json");
|
serde_json::to_string_pretty(&json).expect("canonical json is valid json");
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_html(
|
RoomMessageEventContent::text_html(
|
||||||
format!(
|
format!(
|
||||||
"{}\n```json\n{}\n```",
|
"{}\n```json\n{}\n```",
|
||||||
if outlier {
|
if outlier {
|
||||||
|
@ -399,17 +391,21 @@ pub fn try_parse_admin_command(
|
||||||
},
|
},
|
||||||
RawStr::new(&json_text).html_escape()
|
RawStr::new(&json_text).html_escape()
|
||||||
),
|
),
|
||||||
))
|
)
|
||||||
}
|
|
||||||
None => {
|
|
||||||
AdminCommand::SendMessage(RoomMessageEventContent::text_plain("PDU not found."))
|
|
||||||
}
|
}
|
||||||
|
None => RoomMessageEventContent::text_plain("PDU not found."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdminCommands::DatabaseMemoryUsage => AdminCommand::ShowMemoryUsage,
|
AdminCommand::DatabaseMemoryUsage => match db._db.memory_usage() {
|
||||||
|
Ok(response) => RoomMessageEventContent::text_plain(response),
|
||||||
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
|
"Failed to get database memory usage: {}",
|
||||||
|
e
|
||||||
|
)),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(admin_command)
|
Ok(reply_message_content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility to turn clap's `--help` text to HTML.
|
// Utility to turn clap's `--help` text to HTML.
|
||||||
|
|
|
@ -3,7 +3,6 @@ mod edus;
|
||||||
pub use edus::RoomEdus;
|
pub use edus::RoomEdus;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::admin::parse_admin_command,
|
|
||||||
pdu::{EventHash, PduBuilder},
|
pdu::{EventHash, PduBuilder},
|
||||||
utils, Database, Error, PduEvent, Result,
|
utils, Database, Error, PduEvent, Result,
|
||||||
};
|
};
|
||||||
|
@ -1490,12 +1489,7 @@ impl Rooms {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
== Some(&pdu.room_id)
|
== Some(&pdu.room_id)
|
||||||
{
|
{
|
||||||
let mut lines = body.lines();
|
db.admin.process_message(body.to_string());
|
||||||
let command_line = lines.next().expect("each string has at least one line");
|
|
||||||
let body: Vec<_> = lines.collect();
|
|
||||||
|
|
||||||
let command = parse_admin_command(db, command_line, body);
|
|
||||||
db.admin.send(command);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue