push 1 checkpoiint *holy hell i sure hope it works*

This commit is contained in:
Anish Nayak
2025-08-12 18:01:01 +01:00
parent 79f0ca08b2
commit 9549e70593
8 changed files with 310 additions and 67 deletions
+65 -2
View File
@@ -3,11 +3,74 @@ use scc::HashSet;
use twilight_model::id::Id;
use crate::{
database::models::{Call, Channel},
database::models::{Call, Channel, Message, Report},
framework::commands::{Command, CommandError, context::CommandContext},
framework::interactions::{message_command::MessageCommand, InteractionError, context::InteractionContext},
state::State,
utils::Bye,
utils::{Bye, get_random_u64},
};
#[derive(Debug, Default)]
pub struct ReportMessageCommand;
#[async_trait]
impl MessageCommand<State> for ReportMessageCommand {
fn name(&self) -> &'static str {
"Report Message"
}
fn description(&self) -> &'static str {
"Report a message to the moderators."
}
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())
.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)?;
// Fetch the message from the database
let message = Message::get_by_id(call_id, target_message_id, db)
.await
.map_err(|_| InteractionError::InteractionNotFound)?
.ok_or(InteractionError::InteractionNotFound)?;
// Build the report using the new UDT-based message metadata
let report = Report {
report_id: get_random_u64(),
message: message.message_metadata.clone(),
created_at: time::OffsetDateTime::now_utc(),
reviewed_at: None,
created_by_ids: vec![ctx.event.author_id().map(|id| id.get()).unwrap_or(0)],
reviewed_by_id: None,
resolution: None,
};
// Insert the report
report.insert(db).await.map_err(|_| InteractionError::DeferringFailed)?;
// 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)?;
Ok(())
}
}
#[derive(Default, Debug)]
pub struct CallCommand {