moved message structs and ran cargo fmt

This commit is contained in:
Anish Nayak
2025-08-12 19:59:53 +01:00
parent 14e6d59ddd
commit 540db21c45
11 changed files with 211 additions and 171 deletions
+28 -10
View File
@@ -5,7 +5,9 @@ use twilight_model::id::Id;
use crate::{
database::models::{Call, Channel, Message, Report},
framework::commands::{Command, CommandError, context::CommandContext},
framework::interactions::{message_command::MessageCommand, InteractionError, context::InteractionContext},
framework::interactions::{
InteractionError, context::InteractionContext, message_command::MessageCommand,
},
state::State,
utils::{Bye, get_random_u64},
};
@@ -22,15 +24,26 @@ impl MessageCommand<State> for ReportMessageCommand {
"Report a message to the moderators."
}
async fn execute(&self, ctx: InteractionContext<State>, target_message_id: u64) -> Result<(), InteractionError> {
async fn execute(
&self,
ctx: InteractionContext<State>,
target_message_id: u64,
) -> Result<(), InteractionError> {
// Extract channel_id from resolved data or fallback to event.channel (Discord API v10+)
let channel_id = ctx.event.channel.as_ref().map(|c| c.id.get())
let channel_id = ctx
.event
.channel
.as_ref()
.map(|c| c.id.get())
.or_else(|| ctx.event.channel.as_ref().map(|c| c.id.get()))
.ok_or(InteractionError::InteractionNotFound)?;
let db = &ctx.rt.state.db;
let channel = Channel::get_by_id(channel_id, db).await.map_err(|_| InteractionError::InteractionNotFound)?;
let call_id = channel.and_then(|c| c.call_id).ok_or(InteractionError::InteractionNotFound)?;
let channel = Channel::get_by_id(channel_id, db)
.await
.map_err(|_| InteractionError::InteractionNotFound)?;
let call_id = channel
.and_then(|c| c.call_id)
.ok_or(InteractionError::InteractionNotFound)?;
// Fetch the message from the database
let message = Message::get_by_id(call_id, target_message_id, db)
@@ -41,8 +54,11 @@ impl MessageCommand<State> for ReportMessageCommand {
// 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 {
message_metadata.message_replied_to_metadata = Some(Box::new(reply_msg.message_metadata));
if let Ok(Some(reply_msg)) =
Message::get_by_id(call_id, replying_to_id as u64, db).await
{
message_metadata.message_replied_to_metadata =
Some(Box::new(reply_msg.message_metadata));
}
}
@@ -56,10 +72,12 @@ impl MessageCommand<State> for ReportMessageCommand {
reviewed_by_id: None,
resolution: None,
};
// Insert the report
report.insert(db).await.map_err(|_| InteractionError::DeferringFailed)?;
report
.insert(db)
.await
.map_err(|_| InteractionError::DeferringFailed)?;
// Respond to the user
ctx.rt.http
+6 -2
View File
@@ -6,10 +6,14 @@ use twilight_model::{gateway::payload::incoming::MessageCreate, id::Id};
use twilight_validate::request::webhook_username;
use crate::{
database::models::{Call, Channel}, discord::{images, sanitizing::SanitizeDiscordMarkdown}, framework::{
database::models::{Call, Channel},
discord::{images, sanitizing::SanitizeDiscordMarkdown},
framework::{
events::traits::{EventResult, OnMessageHandler},
runtime::Runtime,
}, groups::calls::moderation::escape_message, state::State
},
groups::calls::moderation::escape_message,
state::State,
};
#[derive(Debug)]