add admin command for admin room notices

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-16 02:10:47 +00:00
parent 3d3d63fdf4
commit 483f0a9c86
3 changed files with 16 additions and 1 deletions

View file

@ -40,6 +40,11 @@ pub(crate) enum ServerCommand {
/// - List database files /// - List database files
ListDatabaseFiles, ListDatabaseFiles,
/// - Send a message to the admin room.
AdminNotice {
message: Vec<String>,
},
#[cfg(conduit_mods)] #[cfg(conduit_mods)]
/// - Hot-reload the server /// - Hot-reload the server
Reload, Reload,
@ -62,6 +67,9 @@ pub(crate) async fn process(command: ServerCommand, body: Vec<&str>) -> Result<R
ServerCommand::ListBackups => list_backups(body).await?, ServerCommand::ListBackups => list_backups(body).await?,
ServerCommand::BackupDatabase => backup_database(body).await?, ServerCommand::BackupDatabase => backup_database(body).await?,
ServerCommand::ListDatabaseFiles => list_database_files(body).await?, ServerCommand::ListDatabaseFiles => list_database_files(body).await?,
ServerCommand::AdminNotice {
message,
} => admin_notice(body, message).await?,
#[cfg(conduit_mods)] #[cfg(conduit_mods)]
ServerCommand::Reload => reload(body).await?, ServerCommand::Reload => reload(body).await?,
ServerCommand::Shutdown => shutdown(body).await?, ServerCommand::Shutdown => shutdown(body).await?,

View file

@ -98,6 +98,13 @@ pub(crate) async fn list_database_files(_body: Vec<&str>) -> Result<RoomMessageE
Ok(RoomMessageEventContent::notice_html(String::new(), result)) Ok(RoomMessageEventContent::notice_html(String::new(), result))
} }
pub(crate) async fn admin_notice(_body: Vec<&str>, message: Vec<String>) -> Result<RoomMessageEventContent> {
let message = message.join(" ");
services().admin.send_text(&message).await;
Ok(RoomMessageEventContent::notice_plain("Notice was sent to #admins"))
}
#[cfg(conduit_mods)] #[cfg(conduit_mods)]
pub(crate) async fn reload(_body: Vec<&str>) -> Result<RoomMessageEventContent> { pub(crate) async fn reload(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
services().server.reload()?; services().server.reload()?;

View file

@ -92,7 +92,7 @@ impl Service {
} }
pub async fn send_text(&self, body: &str) { pub async fn send_text(&self, body: &str) {
self.send_message(RoomMessageEventContent::text_plain(body)) self.send_message(RoomMessageEventContent::text_markdown(body))
.await; .await;
} }