apply new rustfmt.toml changes, fix some clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0317cc8cc5
commit
77e0b76408
296 changed files with 7147 additions and 4300 deletions
|
@ -94,15 +94,16 @@ impl Console {
|
|||
debug!("session starting");
|
||||
while self.server.running() {
|
||||
match self.readline().await {
|
||||
Ok(event) => match event {
|
||||
ReadlineEvent::Line(string) => self.clone().handle(string).await,
|
||||
ReadlineEvent::Interrupted => continue,
|
||||
ReadlineEvent::Eof => break,
|
||||
ReadlineEvent::Quit => self.server.shutdown().unwrap_or_else(error::default_log),
|
||||
| Ok(event) => match event {
|
||||
| ReadlineEvent::Line(string) => self.clone().handle(string).await,
|
||||
| ReadlineEvent::Interrupted => continue,
|
||||
| ReadlineEvent::Eof => break,
|
||||
| ReadlineEvent::Quit =>
|
||||
self.server.shutdown().unwrap_or_else(error::default_log),
|
||||
},
|
||||
Err(error) => match error {
|
||||
ReadlineError::Closed => break,
|
||||
ReadlineError::IO(error) => {
|
||||
| Err(error) => match error {
|
||||
| ReadlineError::Closed => break,
|
||||
| ReadlineError::IO(error) => {
|
||||
error!("console I/O: {error:?}");
|
||||
break;
|
||||
},
|
||||
|
@ -158,9 +159,9 @@ impl Console {
|
|||
|
||||
async fn process(self: Arc<Self>, line: String) {
|
||||
match self.admin.command_in_place(line, None).await {
|
||||
Ok(Some(ref content)) => self.output(content),
|
||||
Err(ref content) => self.output_err(content),
|
||||
_ => unreachable!(),
|
||||
| Ok(Some(ref content)) => self.output(content),
|
||||
| Err(ref content) => self.output_err(content),
|
||||
| _ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,9 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
let create_content = {
|
||||
use RoomVersionId::*;
|
||||
match room_version {
|
||||
V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => RoomCreateEventContent::new_v1(server_user.clone()),
|
||||
_ => RoomCreateEventContent::new_v11(),
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
|
||||
RoomCreateEventContent::new_v1(server_user.clone()),
|
||||
| _ => RoomCreateEventContent::new_v11(),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -52,15 +53,12 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomCreateEventContent {
|
||||
federate: true,
|
||||
predecessor: None,
|
||||
room_version: room_version.clone(),
|
||||
..create_content
|
||||
},
|
||||
),
|
||||
PduBuilder::state(String::new(), &RoomCreateEventContent {
|
||||
federate: true,
|
||||
predecessor: None,
|
||||
room_version: room_version.clone(),
|
||||
..create_content
|
||||
}),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -72,7 +70,10 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(server_user.to_string(), &RoomMemberEventContent::new(MembershipState::Join)),
|
||||
PduBuilder::state(
|
||||
server_user.to_string(),
|
||||
&RoomMemberEventContent::new(MembershipState::Join),
|
||||
),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -86,13 +87,10 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomPowerLevelsEventContent {
|
||||
users,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
PduBuilder::state(String::new(), &RoomPowerLevelsEventContent {
|
||||
users,
|
||||
..Default::default()
|
||||
}),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -131,7 +129,10 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &RoomGuestAccessEventContent::new(GuestAccess::Forbidden)),
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomGuestAccessEventContent::new(GuestAccess::Forbidden),
|
||||
),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -155,12 +156,9 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomTopicEventContent {
|
||||
topic: format!("Manage {}", services.globals.server_name()),
|
||||
},
|
||||
),
|
||||
PduBuilder::state(String::new(), &RoomTopicEventContent {
|
||||
topic: format!("Manage {}", services.globals.server_name()),
|
||||
}),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -174,13 +172,10 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomCanonicalAliasEventContent {
|
||||
alias: Some(alias.clone()),
|
||||
alt_aliases: Vec::new(),
|
||||
},
|
||||
),
|
||||
PduBuilder::state(String::new(), &RoomCanonicalAliasEventContent {
|
||||
alias: Some(alias.clone()),
|
||||
alt_aliases: Vec::new(),
|
||||
}),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -197,12 +192,7 @@ pub async fn create_admin_room(services: &Services) -> Result<()> {
|
|||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomPreviewUrlsEventContent {
|
||||
disabled: true,
|
||||
},
|
||||
),
|
||||
PduBuilder::state(String::new(), &RoomPreviewUrlsEventContent { disabled: true }),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
|
|
@ -34,7 +34,10 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result<()> {
|
|||
self.services
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent::new(MembershipState::Invite)),
|
||||
PduBuilder::state(
|
||||
user_id.to_string(),
|
||||
&RoomMemberEventContent::new(MembershipState::Invite),
|
||||
),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -43,7 +46,10 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result<()> {
|
|||
self.services
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent::new(MembershipState::Join)),
|
||||
PduBuilder::state(
|
||||
user_id.to_string(),
|
||||
&RoomMemberEventContent::new(MembershipState::Join),
|
||||
),
|
||||
user_id,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -51,18 +57,18 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result<()> {
|
|||
.await?;
|
||||
|
||||
// Set power level
|
||||
let users = BTreeMap::from_iter([(server_user.clone(), 100.into()), (user_id.to_owned(), 100.into())]);
|
||||
let users = BTreeMap::from_iter([
|
||||
(server_user.clone(), 100.into()),
|
||||
(user_id.to_owned(), 100.into()),
|
||||
]);
|
||||
|
||||
self.services
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
PduBuilder::state(
|
||||
String::new(),
|
||||
&RoomPowerLevelsEventContent {
|
||||
users,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
PduBuilder::state(String::new(), &RoomPowerLevelsEventContent {
|
||||
users,
|
||||
..Default::default()
|
||||
}),
|
||||
server_user,
|
||||
&room_id,
|
||||
&state_lock,
|
||||
|
@ -103,9 +109,7 @@ async fn set_room_tag(&self, room_id: &RoomId, user_id: &UserId, tag: &str) -> R
|
|||
.get_room(room_id, user_id, RoomAccountDataEventType::Tag)
|
||||
.await
|
||||
.unwrap_or_else(|_| TagEvent {
|
||||
content: TagEventContent {
|
||||
tags: BTreeMap::new(),
|
||||
},
|
||||
content: TagEventContent { tags: BTreeMap::new() },
|
||||
});
|
||||
|
||||
event
|
||||
|
|
|
@ -10,7 +10,9 @@ use std::{
|
|||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{debug, err, error, error::default_log, pdu::PduBuilder, Error, PduEvent, Result, Server};
|
||||
use conduwuit::{
|
||||
debug, err, error, error::default_log, pdu::PduBuilder, Error, PduEvent, Result, Server,
|
||||
};
|
||||
pub use create::create_admin_room;
|
||||
use futures::{FutureExt, TryFutureExt};
|
||||
use loole::{Receiver, Sender};
|
||||
|
@ -158,21 +160,19 @@ impl Service {
|
|||
/// the queue is full.
|
||||
pub fn command(&self, command: String, reply_id: Option<OwnedEventId>) -> Result<()> {
|
||||
self.sender
|
||||
.send(CommandInput {
|
||||
command,
|
||||
reply_id,
|
||||
})
|
||||
.send(CommandInput { command, reply_id })
|
||||
.map_err(|e| err!("Failed to enqueue admin command: {e:?}"))
|
||||
}
|
||||
|
||||
/// Dispatches a comamnd to the processor on the current task and waits for
|
||||
/// completion.
|
||||
pub async fn command_in_place(&self, command: String, reply_id: Option<OwnedEventId>) -> ProcessorResult {
|
||||
self.process_command(CommandInput {
|
||||
command,
|
||||
reply_id,
|
||||
})
|
||||
.await
|
||||
pub async fn command_in_place(
|
||||
&self,
|
||||
command: String,
|
||||
reply_id: Option<OwnedEventId>,
|
||||
) -> ProcessorResult {
|
||||
self.process_command(CommandInput { command, reply_id })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Invokes the tab-completer to complete the command. When unavailable,
|
||||
|
@ -191,8 +191,8 @@ impl Service {
|
|||
|
||||
async fn handle_command(&self, command: CommandInput) {
|
||||
match self.process_command(command).await {
|
||||
Ok(None) => debug!("Command successful with no response"),
|
||||
Ok(Some(output)) | Err(output) => self
|
||||
| Ok(None) => debug!("Command successful with no response"),
|
||||
| Ok(Some(output)) | Err(output) => self
|
||||
.handle_response(output)
|
||||
.await
|
||||
.unwrap_or_else(default_log),
|
||||
|
@ -250,10 +250,7 @@ impl Service {
|
|||
}
|
||||
|
||||
async fn handle_response(&self, content: RoomMessageEventContent) -> Result<()> {
|
||||
let Some(Relation::Reply {
|
||||
in_reply_to,
|
||||
}) = content.relates_to.as_ref()
|
||||
else {
|
||||
let Some(Relation::Reply { in_reply_to }) = content.relates_to.as_ref() else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
@ -277,7 +274,10 @@ impl Service {
|
|||
}
|
||||
|
||||
async fn respond_to_room(
|
||||
&self, content: RoomMessageEventContent, room_id: &RoomId, user_id: &UserId,
|
||||
&self,
|
||||
content: RoomMessageEventContent,
|
||||
room_id: &RoomId,
|
||||
user_id: &UserId,
|
||||
) -> Result<()> {
|
||||
assert!(self.user_is_admin(user_id).await, "sender is not admin");
|
||||
|
||||
|
@ -298,12 +298,16 @@ impl Service {
|
|||
}
|
||||
|
||||
async fn handle_response_error(
|
||||
&self, e: Error, room_id: &RoomId, user_id: &UserId, state_lock: &RoomMutexGuard,
|
||||
&self,
|
||||
e: Error,
|
||||
room_id: &RoomId,
|
||||
user_id: &UserId,
|
||||
state_lock: &RoomMutexGuard,
|
||||
) -> Result<()> {
|
||||
error!("Failed to build and append admin room response PDU: \"{e}\"");
|
||||
let content = RoomMessageEventContent::text_plain(format!(
|
||||
"Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command may have finished \
|
||||
successfully, but we could not return the output."
|
||||
"Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command \
|
||||
may have finished successfully, but we could not return the output."
|
||||
));
|
||||
|
||||
self.services
|
||||
|
@ -321,7 +325,8 @@ impl Service {
|
|||
|
||||
// Admin command with public echo (in admin room)
|
||||
let server_user = &self.services.globals.server_user;
|
||||
let is_public_prefix = body.starts_with("!admin") || body.starts_with(server_user.as_str());
|
||||
let is_public_prefix =
|
||||
body.starts_with("!admin") || body.starts_with(server_user.as_str());
|
||||
|
||||
// Expected backward branch
|
||||
if !is_public_escape && !is_public_prefix {
|
||||
|
|
|
@ -65,9 +65,9 @@ async fn startup_execute_command(&self, i: usize, command: String) -> Result<()>
|
|||
debug!("Startup command #{i}: executing {command:?}");
|
||||
|
||||
match self.command_in_place(command, None).await {
|
||||
Ok(Some(output)) => Self::startup_command_output(i, &output),
|
||||
Err(output) => Self::startup_command_error(i, &output),
|
||||
Ok(None) => {
|
||||
| Ok(Some(output)) => Self::startup_command_output(i, &output),
|
||||
| Err(output) => Self::startup_command_error(i, &output),
|
||||
| Ok(None) => {
|
||||
info!("Startup command #{i} completed (no output).");
|
||||
Ok(())
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue