Insert messages to DB when sent on call
This commit is contained in:
@@ -5,7 +5,7 @@ use twilight_model::{gateway::payload::incoming::MessageCreate, id::Id};
|
||||
use twilight_validate::request::webhook_username;
|
||||
|
||||
use crate::{
|
||||
database::models::{Call, Channel},
|
||||
database::models::{Call, Channel, Message},
|
||||
discord::images,
|
||||
framework::{
|
||||
events::traits::{EventResult, OnMessageHandler},
|
||||
@@ -99,6 +99,17 @@ impl OnMessageHandler<State> for MessageRedirector {
|
||||
|
||||
let profile = get_display_profile(event);
|
||||
|
||||
Message::build()
|
||||
.call_id(call.id)
|
||||
.message(event.0.clone())
|
||||
.profile(profile.clone())
|
||||
.build()
|
||||
.expect(
|
||||
"The message builder was missing either the call ID, the message, or the profile",
|
||||
)
|
||||
.insert(&rt.state.db)
|
||||
.await?;
|
||||
|
||||
rt.http
|
||||
.execute_webhook(Id::new(webhook_id), &webhook_token)
|
||||
.allowed_mentions(None)
|
||||
@@ -118,9 +129,12 @@ impl OnMessageHandler<State> for MessageRedirector {
|
||||
}
|
||||
}
|
||||
|
||||
struct DisplayProfile {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DisplayProfile {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub avatar_url: String,
|
||||
pub mask: Option<String>,
|
||||
}
|
||||
|
||||
fn get_display_profile(event: &MessageCreate) -> DisplayProfile {
|
||||
@@ -153,5 +167,10 @@ fn get_display_profile(event: &MessageCreate) -> DisplayProfile {
|
||||
event.author.discriminator as u64,
|
||||
);
|
||||
|
||||
DisplayProfile { name, avatar_url }
|
||||
DisplayProfile {
|
||||
id: event.author.id.get(),
|
||||
name,
|
||||
avatar_url,
|
||||
mask: None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user