mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-11 08:13:02 +02:00
feat: Pass sender through admin commands
This commit is contained in:
parent
ecc6fda98b
commit
acb74faa07
5 changed files with 41 additions and 8 deletions
|
@ -7,13 +7,14 @@ use futures::{
|
|||
io::{AsyncWriteExt, BufWriter},
|
||||
lock::Mutex,
|
||||
};
|
||||
use ruma::EventId;
|
||||
use ruma::{EventId, UserId};
|
||||
|
||||
pub(crate) struct Context<'a> {
|
||||
pub(crate) services: &'a Services,
|
||||
pub(crate) body: &'a [&'a str],
|
||||
pub(crate) timer: SystemTime,
|
||||
pub(crate) reply_id: Option<&'a EventId>,
|
||||
pub(crate) sender: Option<&'a UserId>,
|
||||
pub(crate) output: Mutex<BufWriter<Vec<u8>>>,
|
||||
}
|
||||
|
||||
|
@ -36,4 +37,16 @@ impl Context<'_> {
|
|||
output.write_all(s.as_bytes()).map_err(Into::into).await
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the sender of the admin command, if available
|
||||
pub(crate) fn sender(&self) -> Option<&UserId> { self.sender }
|
||||
|
||||
/// Check if the command has sender information
|
||||
pub(crate) fn has_sender(&self) -> bool { self.sender.is_some() }
|
||||
|
||||
/// Get the sender as a string, or service user ID if not available
|
||||
pub(crate) fn sender_or_service_user(&self) -> &UserId {
|
||||
self.sender
|
||||
.unwrap_or_else(|| self.services.globals.server_user.as_ref())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ async fn process_command(services: Arc<Services>, input: &CommandInput) -> Proce
|
|||
body: &body,
|
||||
timer: SystemTime::now(),
|
||||
reply_id: input.reply_id.as_deref(),
|
||||
sender: input.sender.as_deref(),
|
||||
output: BufWriter::new(Vec::new()).into(),
|
||||
};
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ pub(super) async fn suspend(&self, user_id: String) -> Result {
|
|||
// TODO: Record the actual user that sent the suspension where possible
|
||||
self.services
|
||||
.users
|
||||
.suspend_account(&user_id, self.services.globals.server_user.as_ref())
|
||||
.suspend_account(&user_id, self.sender_or_service_user())
|
||||
.await;
|
||||
|
||||
self.write_str(&format!("User {user_id} has been suspended."))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue