remove some unnecessary HTML from admin commands
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
065396f8f5
commit
85890ed425
5 changed files with 16 additions and 50 deletions
|
@ -106,7 +106,7 @@ pub(super) async fn get_pdu(&self, event_id: Box<EventId>) -> Result<RoomMessage
|
||||||
Ok(RoomMessageEventContent::notice_markdown(format!(
|
Ok(RoomMessageEventContent::notice_markdown(format!(
|
||||||
"{}\n```json\n{}\n```",
|
"{}\n```json\n{}\n```",
|
||||||
if outlier {
|
if outlier {
|
||||||
"Outlier PDU found in our database"
|
"Outlier (Rejected / Soft Failed) PDU found in our database"
|
||||||
} else {
|
} else {
|
||||||
"PDU found in our database"
|
"PDU found in our database"
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ use conduit::Result;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId};
|
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId};
|
||||||
|
|
||||||
use crate::{admin_command, escape_html, get_room_info};
|
use crate::{admin_command, get_room_info};
|
||||||
|
|
||||||
#[admin_command]
|
#[admin_command]
|
||||||
pub(super) async fn disable_room(&self, room_id: Box<RoomId>) -> Result<RoomMessageEventContent> {
|
pub(super) async fn disable_room(&self, room_id: Box<RoomId>) -> Result<RoomMessageEventContent> {
|
||||||
|
@ -108,33 +108,15 @@ pub(super) async fn remote_user_in_rooms(&self, user_id: Box<UserId>) -> Result<
|
||||||
rooms.sort_by_key(|r| r.1);
|
rooms.sort_by_key(|r| r.1);
|
||||||
rooms.reverse();
|
rooms.reverse();
|
||||||
|
|
||||||
let output_plain = format!(
|
let output = format!(
|
||||||
"Rooms {user_id} shares with us ({}):\n{}",
|
"Rooms {user_id} shares with us ({}):\n```\n{}\n```",
|
||||||
rooms.len(),
|
rooms.len(),
|
||||||
rooms
|
rooms
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, members, name)| format!("{id}\tMembers: {members}\tName: {name}"))
|
.map(|(id, members, name)| format!("{id} | Members: {members} | Name: {name}"))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
);
|
);
|
||||||
let output_html = format!(
|
|
||||||
"<table><caption>Rooms {user_id} shares with us \
|
|
||||||
({})</caption>\n<tr><th>id</th>\t<th>members</th>\t<th>name</th></tr>\n{}</table>",
|
|
||||||
rooms.len(),
|
|
||||||
rooms
|
|
||||||
.iter()
|
|
||||||
.fold(String::new(), |mut output, (id, members, name)| {
|
|
||||||
writeln!(
|
|
||||||
output,
|
|
||||||
"<tr><td>{}</td>\t<td>{}</td>\t<td>{}</td></tr>",
|
|
||||||
id,
|
|
||||||
members,
|
|
||||||
escape_html(name)
|
|
||||||
)
|
|
||||||
.expect("should be able to write to string buffer");
|
|
||||||
output
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(RoomMessageEventContent::text_html(output_plain, output_html))
|
Ok(RoomMessageEventContent::text_markdown(output))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
use std::fmt::Write;
|
|
||||||
|
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use conduit::Result;
|
use conduit::Result;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use ruma::{events::room::message::RoomMessageEventContent, RoomId};
|
use ruma::{events::room::message::RoomMessageEventContent, RoomId};
|
||||||
|
|
||||||
use crate::{escape_html, get_room_info, Command, PAGE_SIZE};
|
use crate::{get_room_info, Command, PAGE_SIZE};
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
pub(crate) enum RoomDirectoryCommand {
|
pub(crate) enum RoomDirectoryCommand {
|
||||||
|
@ -68,32 +66,15 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Command<'_>
|
||||||
return Ok(RoomMessageEventContent::text_plain("No more rooms."));
|
return Ok(RoomMessageEventContent::text_plain("No more rooms."));
|
||||||
};
|
};
|
||||||
|
|
||||||
let output_plain = format!(
|
let output = format!(
|
||||||
"Rooms:\n{}",
|
"Rooms (page {page}):\n```\n{}\n```",
|
||||||
rooms
|
rooms
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, members, name)| format!("{id}\tMembers: {members}\tName: {name}"))
|
.map(|(id, members, name)| format!("{id} | Members: {members} | Name: {name}"))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
);
|
);
|
||||||
let output_html = format!(
|
Ok(RoomMessageEventContent::text_markdown(output))
|
||||||
"<table><caption>Room directory - page \
|
|
||||||
{page}</caption>\n<tr><th>id</th>\t<th>members</th>\t<th>name</th></tr>\n{}</table>",
|
|
||||||
rooms
|
|
||||||
.iter()
|
|
||||||
.fold(String::new(), |mut output, (id, members, name)| {
|
|
||||||
writeln!(
|
|
||||||
output,
|
|
||||||
"<tr><td>{}</td>\t<td>{}</td>\t<td>{}</td></tr>",
|
|
||||||
escape_html(id.as_ref()),
|
|
||||||
members,
|
|
||||||
escape_html(name.as_ref())
|
|
||||||
)
|
|
||||||
.expect("should be able to write to string buffer");
|
|
||||||
output
|
|
||||||
})
|
|
||||||
);
|
|
||||||
Ok(RoomMessageEventContent::text_html(output_plain, output_html))
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,10 @@ pub(super) async fn uptime(&self) -> Result<RoomMessageEventContent> {
|
||||||
#[admin_command]
|
#[admin_command]
|
||||||
pub(super) async fn show_config(&self) -> Result<RoomMessageEventContent> {
|
pub(super) async fn show_config(&self) -> Result<RoomMessageEventContent> {
|
||||||
// Construct and send the response
|
// Construct and send the response
|
||||||
Ok(RoomMessageEventContent::text_plain(format!("{}", self.services.globals.config)))
|
Ok(RoomMessageEventContent::text_markdown(format!(
|
||||||
|
"```\n{}\n```",
|
||||||
|
self.services.globals.config
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[admin_command]
|
#[admin_command]
|
||||||
|
|
|
@ -1441,7 +1441,7 @@ impl Config {
|
||||||
|
|
||||||
impl fmt::Display for Config {
|
impl fmt::Display for Config {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
writeln!(f, "Active config values:\n\n").expect("wrote line to formatter stream");
|
writeln!(f, "Active config values:\n").expect("wrote line to formatter stream");
|
||||||
let mut line = |key: &str, val: &str| {
|
let mut line = |key: &str, val: &str| {
|
||||||
writeln!(f, "{key}: {val}").expect("wrote line to formatter stream");
|
writeln!(f, "{key}: {val}").expect("wrote line to formatter stream");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue