inital webhook support

This commit is contained in:
Zomatree
2022-11-26 23:07:22 +00:00
parent ee1c4cc2d5
commit 5cb2320760
31 changed files with 653 additions and 38 deletions

View File

@@ -7,7 +7,7 @@ use revolt_quark::{
},
perms,
web::idempotency::IdempotencyKey,
Db, Error, Permission, Ref, Result,
Db, Error, Permission, Ref, Result, types::push::MessageAuthor,
};
use regex::Regex;
@@ -22,31 +22,31 @@ pub struct DataMessageSend {
///
/// **This is deprecated and replaced by `Idempotency-Key`!**
#[validate(length(min = 1, max = 64))]
nonce: Option<String>,
pub nonce: Option<String>,
/// Message content to send
#[validate(length(min = 0, max = 2000))]
content: Option<String>,
pub content: Option<String>,
/// Attachments to include in message
#[validate(length(min = 1, max = 128))]
attachments: Option<Vec<String>>,
pub attachments: Option<Vec<String>>,
/// Messages to reply to
replies: Option<Vec<Reply>>,
pub replies: Option<Vec<Reply>>,
/// Embeds to include in message
///
/// Text embed content contributes to the content length cap
#[validate(length(min = 1, max = 10))]
embeds: Option<Vec<SendableEmbed>>,
pub embeds: Option<Vec<SendableEmbed>>,
/// Masquerade to apply to this message
#[validate]
masquerade: Option<Masquerade>,
pub masquerade: Option<Masquerade>,
/// Information about how this message should be interacted with
interactions: Option<Interactions>,
pub interactions: Option<Interactions>,
}
lazy_static! {
// ignoring I L O and U is intentional
static ref RE_MENTION: Regex = Regex::new(r"<@([0-9A-HJKMNP-TV-Z]{26})>").unwrap();
pub static ref RE_MENTION: Regex = Regex::new(r"<@([0-9A-HJKMNP-TV-Z]{26})>").unwrap();
}
/// # Send Message
@@ -86,7 +86,7 @@ pub async fn message_send(
let mut message = Message {
id: message_id.clone(),
channel: channel.id().to_string(),
author: user.id.clone(),
author: Some(user.id.clone()),
masquerade: data.masquerade,
interactions: data.interactions.unwrap_or_default(),
..Default::default()
@@ -128,11 +128,11 @@ pub async fn message_send(
for Reply { id, mention } in entries {
let message = Ref::from_unchecked(id).as_message(db).await?;
replies.insert(message.id);
if mention {
mentions.insert(message.author);
mentions.insert(message.author_id().to_owned());
}
replies.insert(message.id);
}
}
@@ -195,7 +195,7 @@ pub async fn message_send(
// 8. Pass-through nonce value for clients
message.nonce = Some(idempotency.into_key());
message.create(db, &channel, Some(&user)).await?;
message.create(db, &channel, Some(MessageAuthor::User(&user))).await?;
// Queue up a task for processing embeds
if let Some(content) = &message.content {