feat: Audit Logs (#466)
* fix: squash audit log branch changes Signed-off-by: Zomatree <me@zomatree.live> * feat: emoji edit + pronoun Signed-off-by: Zomatree <me@zomatree.live> * fix: use tokio instead of async-std Signed-off-by: Zomatree <me@zomatree.live> * feat: add slowmode to audit log Signed-off-by: Zomatree <me@zomatree.live> * chore: update comments on permissions Signed-off-by: Zomatree <me@zomatree.live> --------- Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
use revolt_database::{
|
||||
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
||||
Database, User,
|
||||
AuditLogEntryAction, Database, User,
|
||||
};
|
||||
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
|
||||
use revolt_result::Result;
|
||||
use rocket::State;
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
use crate::util::audit_log_reason::AuditLogReason;
|
||||
|
||||
/// # Delete Message
|
||||
///
|
||||
/// Delete a message you've sent or one you have permission to delete.
|
||||
@@ -15,18 +17,40 @@ use rocket_empty::EmptyResponse;
|
||||
pub async fn delete(
|
||||
db: &State<Database>,
|
||||
user: User,
|
||||
reason: AuditLogReason,
|
||||
target: Reference<'_>,
|
||||
msg: Reference<'_>,
|
||||
) -> Result<EmptyResponse> {
|
||||
let message = msg.as_message_in_channel(db, target.id).await?;
|
||||
|
||||
if message.author != user.id {
|
||||
let channel = if message.author != user.id {
|
||||
let channel = target.as_channel(db).await?;
|
||||
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
||||
calculate_channel_permissions(&mut query)
|
||||
.await
|
||||
.throw_if_lacking_channel_permission(ChannelPermission::ManageMessages)?;
|
||||
}
|
||||
|
||||
message.delete(db).await.map(|_| EmptyResponse)
|
||||
Some(channel)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
message.delete(db).await?;
|
||||
|
||||
if let Some(server) = channel.and_then(|c| c.server().map(|s| s.to_string())) {
|
||||
AuditLogEntryAction::MessageDelete {
|
||||
author: message.author.clone(),
|
||||
channel: message.channel.clone(),
|
||||
}
|
||||
.insert(
|
||||
db,
|
||||
server.to_string(),
|
||||
reason,
|
||||
user.id.clone(),
|
||||
Some(message.author),
|
||||
)
|
||||
.await;
|
||||
};
|
||||
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user