refactor(core): remove quark references from webhook routes
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use validator::Validate;
|
||||
|
||||
use super::File;
|
||||
|
||||
auto_derived_partial!(
|
||||
@@ -69,13 +71,23 @@ auto_derived!(
|
||||
pub channel_id: String,
|
||||
|
||||
/// The permissions for the webhook
|
||||
pub permissions: u64
|
||||
pub permissions: u64,
|
||||
}
|
||||
|
||||
/// Optional fields on webhook object
|
||||
pub enum FieldsWebhook {
|
||||
Avatar,
|
||||
}
|
||||
|
||||
/// Information for the webhook
|
||||
#[derive(Validate)]
|
||||
pub struct CreateWebhookBody {
|
||||
#[validate(length(min = 1, max = 32))]
|
||||
pub name: String,
|
||||
|
||||
#[validate(length(min = 1, max = 128))]
|
||||
pub avatar: Option<String>,
|
||||
}
|
||||
);
|
||||
|
||||
impl From<Webhook> for MessageWebhook {
|
||||
@@ -94,7 +106,7 @@ impl From<Webhook> for ResponseWebhook {
|
||||
name: value.name,
|
||||
avatar: value.avatar.map(|file| file.id),
|
||||
channel_id: value.channel_id,
|
||||
permissions: value.permissions
|
||||
permissions: value.permissions,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,17 @@ use std::{
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use revolt_config::config;
|
||||
use validator::Validate;
|
||||
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
use super::{Embed, File, MessageWebhook, User, Webhook};
|
||||
use super::{Embed, File, MessageWebhook, User, Webhook, RE_COLOUR};
|
||||
|
||||
pub static RE_MENTION: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"<@([0-9A-HJKMNP-TV-Z]{26})>").unwrap());
|
||||
|
||||
auto_derived_partial!(
|
||||
/// Message
|
||||
@@ -88,7 +94,9 @@ auto_derived!(
|
||||
}
|
||||
|
||||
/// Name and / or avatar override information
|
||||
#[derive(Validate)]
|
||||
pub struct Masquerade {
|
||||
// FIXME: missing validation
|
||||
/// Replace the display name shown on this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
@@ -154,6 +162,58 @@ auto_derived!(
|
||||
/// URL to open when clicking notification
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
/// Representation of a text embed before it is sent.
|
||||
#[derive(Default, Validate)]
|
||||
pub struct SendableEmbed {
|
||||
#[validate(length(min = 1, max = 128))]
|
||||
pub icon_url: Option<String>,
|
||||
#[validate(length(min = 1, max = 256))]
|
||||
pub url: Option<String>,
|
||||
#[validate(length(min = 1, max = 100))]
|
||||
pub title: Option<String>,
|
||||
#[validate(length(min = 1, max = 2000))]
|
||||
pub description: Option<String>,
|
||||
pub media: Option<String>,
|
||||
#[validate(length(min = 1, max = 128), regex = "RE_COLOUR")]
|
||||
pub colour: Option<String>,
|
||||
}
|
||||
|
||||
/// What this message should reply to and how
|
||||
pub struct ReplyIntent {
|
||||
/// Message Id
|
||||
pub id: String,
|
||||
/// Whether this reply should mention the message's author
|
||||
pub mention: bool,
|
||||
}
|
||||
|
||||
/// Message to send
|
||||
#[derive(Validate)]
|
||||
pub struct DataMessageSend {
|
||||
/// Unique token to prevent duplicate message sending
|
||||
///
|
||||
/// **This is deprecated and replaced by `Idempotency-Key`!**
|
||||
#[validate(length(min = 1, max = 64))]
|
||||
pub nonce: Option<String>,
|
||||
|
||||
/// Message content to send
|
||||
#[validate(length(min = 0, max = 2000))]
|
||||
pub content: Option<String>,
|
||||
/// Attachments to include in message
|
||||
pub attachments: Option<Vec<String>>,
|
||||
/// Messages to reply to
|
||||
pub replies: Option<Vec<ReplyIntent>>,
|
||||
/// Embeds to include in message
|
||||
///
|
||||
/// Text embed content contributes to the content length cap
|
||||
#[validate]
|
||||
pub embeds: Option<Vec<SendableEmbed>>,
|
||||
/// Masquerade to apply to this message
|
||||
#[validate]
|
||||
pub masquerade: Option<Masquerade>,
|
||||
/// Information about how this message should be interacted with
|
||||
pub interactions: Option<Interactions>,
|
||||
}
|
||||
);
|
||||
|
||||
/// Message Author Abstraction
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
use super::File;
|
||||
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
|
||||
/// Regex for valid role colours
|
||||
///
|
||||
/// Allows the use of named colours, rgb(a), variables and all gradients.
|
||||
///
|
||||
/// Flags:
|
||||
/// - Case-insensitive (`i`)
|
||||
///
|
||||
/// Source:
|
||||
/// ```regex
|
||||
/// VALUE = [a-z ]+|var\(--[a-z\d-]+\)|rgba?\([\d, ]+\)|#[a-f0-9]+
|
||||
/// ADDITIONAL_VALUE = \d+deg
|
||||
/// STOP = ([ ]+(\d{1,3}%|0))?
|
||||
///
|
||||
/// ^(?:VALUE|(repeating-)?(linear|conic|radial)-gradient\((VALUE|ADDITIONAL_VALUE)STOP(,[ ]*(VALUE)STOP)+\))$
|
||||
/// ```
|
||||
pub static RE_COLOUR: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r"(?i)^(?:[a-z ]+|var\(--[a-z\d-]+\)|rgba?\([\d, ]+\)|#[a-f0-9]+|(repeating-)?(linear|conic|radial)-gradient\(([a-z ]+|var\(--[a-z\d-]+\)|rgba?\([\d, ]+\)|#[a-f0-9]+|\d+deg)([ ]+(\d{1,3}%|0))?(,[ ]*([a-z ]+|var\(--[a-z\d-]+\)|rgba?\([\d, ]+\)|#[a-f0-9]+)([ ]+(\d{1,3}%|0))?)+\))$").unwrap()
|
||||
});
|
||||
|
||||
auto_derived_partial!(
|
||||
/// Server Member
|
||||
|
||||
Reference in New Issue
Block a user