changed stuff according to merge request !2

This commit is contained in:
Anish Nayak
2025-08-12 23:13:03 +01:00
parent 540db21c45
commit bacdc8ea0f
12 changed files with 262 additions and 134 deletions
+21 -28
View File
@@ -1,9 +1,10 @@
use async_trait::async_trait;
use scc::HashSet;
use std::sync::Arc;
use twilight_model::id::Id;
use crate::{
database::models::{Call, Channel, Message, Report},
database::models::{Call, Channel, Message, MessageRow, Report},
framework::commands::{Command, CommandError, context::CommandContext},
framework::interactions::{
InteractionError, context::InteractionContext, message_command::MessageCommand,
@@ -46,26 +47,29 @@ impl MessageCommand<State> for ReportMessageCommand {
.ok_or(InteractionError::InteractionNotFound)?;
// Fetch the message from the database
let message = Message::get_by_id(call_id, target_message_id, db)
let message_row = MessageRow::get_by_call_and_message_id(call_id, target_message_id, db)
.await
.map_err(|_| InteractionError::InteractionNotFound)?
.ok_or(InteractionError::InteractionNotFound)?;
// If the message is a reply, fetch the replied-to message and denormalize its metadata
let mut message_metadata = message.message_metadata.clone();
if let Some(replying_to_id) = message_metadata.replying_to_id {
if let Ok(Some(reply_msg)) =
Message::get_by_id(call_id, replying_to_id as u64, db).await
// If the message is a reply, fetch the replied-to message and store in replying_to
let replying_to = if let Some(replying_to_id) = message_row.data.replying_to_id {
if let Ok(Some(reply_msg_row)) =
MessageRow::get_by_call_and_message_id(call_id, replying_to_id as u64, db).await
{
message_metadata.message_replied_to_metadata =
Some(Box::new(reply_msg.message_metadata));
Some(reply_msg_row.data)
} else {
None
}
}
} else {
None
};
// Build the report using the new UDT-based message metadata
// Build the report using the new flat message and replying_to
let report = Report {
report_id: get_random_u64(),
message: message_metadata,
message: message_row.data,
replying_to,
created_at: time::OffsetDateTime::now_utc(),
reviewed_at: None,
created_by_ids: vec![ctx.event.author_id().map(|id| id.get()).unwrap_or(0)],
@@ -77,24 +81,13 @@ impl MessageCommand<State> for ReportMessageCommand {
report
.insert(db)
.await
.map_err(|_| InteractionError::DeferringFailed)?;
.map_err(InteractionError::DatabaseError)?;
// Respond to the user
ctx.rt.http
.interaction(ctx.rt.app.id)
.create_response(
ctx.event.id,
&ctx.event.token,
&twilight_model::http::interaction::InteractionResponse {
kind: twilight_model::http::interaction::InteractionResponseType::ChannelMessageWithSource,
data: Some(twilight_model::http::interaction::InteractionResponseData {
content: Some("Message has been reported to the moderators.".to_string()),
..Default::default()
}),
},
)
.await
.map_err(|_| InteractionError::DeferringFailed)?;
Arc::new(ctx)
.send()
.content("Message has been reported to the moderators.")
.await?;
Ok(())
}
}