160
crates/core/models/src/v0/embeds.rs
Normal file
160
crates/core/models/src/v0/embeds.rs
Normal file
@@ -0,0 +1,160 @@
|
||||
use super::File;
|
||||
|
||||
auto_derived!(
|
||||
/// Image positioning and size
|
||||
pub enum ImageSize {
|
||||
/// Show large preview at the bottom of the embed
|
||||
Large,
|
||||
/// Show small preview to the side of the embed
|
||||
Preview,
|
||||
}
|
||||
|
||||
/// Image
|
||||
pub struct Image {
|
||||
/// URL to the original image
|
||||
pub url: String,
|
||||
/// Width of the image
|
||||
pub width: isize,
|
||||
/// Height of the image
|
||||
pub height: isize,
|
||||
/// Positioning and size
|
||||
pub size: ImageSize,
|
||||
}
|
||||
|
||||
/// Video
|
||||
pub struct Video {
|
||||
/// URL to the original video
|
||||
pub url: String,
|
||||
/// Width of the video
|
||||
pub width: isize,
|
||||
/// Height of the video
|
||||
pub height: isize,
|
||||
}
|
||||
|
||||
/// Type of remote Twitch content
|
||||
pub enum TwitchType {
|
||||
Channel,
|
||||
Video,
|
||||
Clip,
|
||||
}
|
||||
|
||||
/// Type of remote Lightspeed.tv content
|
||||
pub enum LightspeedType {
|
||||
Channel,
|
||||
}
|
||||
|
||||
/// Type of remote Bandcamp content
|
||||
pub enum BandcampType {
|
||||
Album,
|
||||
Track,
|
||||
}
|
||||
|
||||
/// Information about special remote content
|
||||
#[serde(tag = "type")]
|
||||
pub enum Special {
|
||||
/// No remote content
|
||||
None,
|
||||
/// Content hint that this contains a GIF
|
||||
///
|
||||
/// Use metadata to find video or image to play
|
||||
GIF,
|
||||
/// YouTube video
|
||||
YouTube {
|
||||
id: String,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
timestamp: Option<String>,
|
||||
},
|
||||
/// Lightspeed.tv stream
|
||||
Lightspeed {
|
||||
content_type: LightspeedType,
|
||||
id: String,
|
||||
},
|
||||
/// Twitch stream or clip
|
||||
Twitch {
|
||||
content_type: TwitchType,
|
||||
id: String,
|
||||
},
|
||||
/// Spotify track
|
||||
Spotify { content_type: String, id: String },
|
||||
/// Soundcloud track
|
||||
Soundcloud,
|
||||
/// Bandcamp track
|
||||
Bandcamp {
|
||||
content_type: BandcampType,
|
||||
id: String,
|
||||
},
|
||||
/// Streamable Video
|
||||
Streamable { id: String },
|
||||
}
|
||||
|
||||
/// Website metadata
|
||||
pub struct WebsiteMetadata {
|
||||
/// Direct URL to web page
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
url: Option<String>,
|
||||
/// Original direct URL
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
original_url: Option<String>,
|
||||
/// Remote content
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
special: Option<Special>,
|
||||
|
||||
/// Title of website
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
title: Option<String>,
|
||||
/// Description of website
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
description: Option<String>,
|
||||
/// Embedded image
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
image: Option<Image>,
|
||||
/// Embedded video
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
video: Option<Video>,
|
||||
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// opengraph_type: Option<String>,
|
||||
/// Site name
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
site_name: Option<String>,
|
||||
/// URL to site icon
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
icon_url: Option<String>,
|
||||
/// CSS Colour
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
colour: Option<String>,
|
||||
}
|
||||
|
||||
/// Text Embed
|
||||
pub struct Text {
|
||||
/// URL to icon
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub icon_url: Option<String>,
|
||||
/// URL for title
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub url: Option<String>,
|
||||
/// Title of text embed
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
/// Description of text embed
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
/// ID of uploaded autumn file
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub media: Option<File>,
|
||||
/// CSS Colour
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub colour: Option<String>,
|
||||
}
|
||||
|
||||
/// Embed
|
||||
#[serde(tag = "type")]
|
||||
pub enum Embed {
|
||||
Website(WebsiteMetadata),
|
||||
Image(Image),
|
||||
Video(Video),
|
||||
Text(Text),
|
||||
None,
|
||||
}
|
||||
);
|
||||
139
crates/core/models/src/v0/messages.rs
Normal file
139
crates/core/models/src/v0/messages.rs
Normal file
@@ -0,0 +1,139 @@
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
use super::{Embed, File, MessageWebhook};
|
||||
|
||||
auto_derived_partial!(
|
||||
/// Message
|
||||
pub struct Message {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
/// Unique value generated by client sending this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub nonce: Option<String>,
|
||||
/// Id of the channel this message was sent in
|
||||
pub channel: String,
|
||||
/// Id of the user or webhook that sent this message
|
||||
pub author: String,
|
||||
/// The webhook that sent this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub webhook: Option<MessageWebhook>,
|
||||
/// Message content
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content: Option<String>,
|
||||
/// System message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub system: Option<SystemMessage>,
|
||||
/// Array of attachments
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub attachments: Option<Vec<File>>,
|
||||
/// Time at which this message was last edited
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub edited: Option<Timestamp>,
|
||||
/// Attached embeds to this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub embeds: Option<Vec<Embed>>,
|
||||
/// Array of user ids mentioned in this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mentions: Option<Vec<String>>,
|
||||
/// Array of message ids this message is replying to
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub replies: Option<Vec<String>>,
|
||||
/// Hashmap of emoji IDs to array of user IDs
|
||||
#[serde(skip_serializing_if = "IndexMap::is_empty", default)]
|
||||
pub reactions: IndexMap<String, IndexSet<String>>,
|
||||
/// Information about how this message should be interacted with
|
||||
#[serde(skip_serializing_if = "Interactions::is_default", default)]
|
||||
pub interactions: Interactions,
|
||||
/// Name and / or avatar overrides for this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub masquerade: Option<Masquerade>,
|
||||
},
|
||||
"PartialMessage"
|
||||
);
|
||||
|
||||
auto_derived!(
|
||||
/// System Event
|
||||
#[serde(tag = "type")]
|
||||
pub enum SystemMessage {
|
||||
#[serde(rename = "text")]
|
||||
Text { content: String },
|
||||
#[serde(rename = "user_added")]
|
||||
UserAdded { id: String, by: String },
|
||||
#[serde(rename = "user_remove")]
|
||||
UserRemove { id: String, by: String },
|
||||
#[serde(rename = "user_joined")]
|
||||
UserJoined { id: String },
|
||||
#[serde(rename = "user_left")]
|
||||
UserLeft { id: String },
|
||||
#[serde(rename = "user_kicked")]
|
||||
UserKicked { id: String },
|
||||
#[serde(rename = "user_banned")]
|
||||
UserBanned { id: String },
|
||||
#[serde(rename = "channel_renamed")]
|
||||
ChannelRenamed { name: String, by: String },
|
||||
#[serde(rename = "channel_description_changed")]
|
||||
ChannelDescriptionChanged { by: String },
|
||||
#[serde(rename = "channel_icon_changed")]
|
||||
ChannelIconChanged { by: String },
|
||||
#[serde(rename = "channel_ownership_changed")]
|
||||
ChannelOwnershipChanged { from: String, to: String },
|
||||
}
|
||||
|
||||
/// Name and / or avatar override information
|
||||
pub struct Masquerade {
|
||||
/// Replace the display name shown on this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
/// Replace the avatar shown on this message (URL to image file)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub avatar: Option<String>,
|
||||
/// Replace the display role colour shown on this message
|
||||
///
|
||||
/// Must have `ManageRole` permission to use
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub colour: Option<String>,
|
||||
}
|
||||
|
||||
/// Information to guide interactions on this message
|
||||
#[derive(Default)]
|
||||
pub struct Interactions {
|
||||
/// Reactions which should always appear and be distinct
|
||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||
pub reactions: Option<IndexSet<String>>,
|
||||
/// Whether reactions should be restricted to the given list
|
||||
///
|
||||
/// Can only be set to true if reactions list is of at least length 1
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub restrict_reactions: bool,
|
||||
}
|
||||
|
||||
/// Appended Information
|
||||
pub struct AppendMessage {
|
||||
/// Additional embeds to include in this message
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub embeds: Option<Vec<Embed>>,
|
||||
}
|
||||
|
||||
/// Message Sort
|
||||
///
|
||||
/// Sort used for retrieving messages
|
||||
#[derive(Default)]
|
||||
pub enum MessageSort {
|
||||
/// Sort by the most relevant messages
|
||||
#[default]
|
||||
Relevance,
|
||||
/// Sort by the newest messages first
|
||||
Latest,
|
||||
/// Sort by the oldest messages first
|
||||
Oldest,
|
||||
}
|
||||
);
|
||||
|
||||
impl Interactions {
|
||||
/// Check if default initialisation of fields
|
||||
pub fn is_default(&self) -> bool {
|
||||
!self.restrict_reactions && self.reactions.is_none()
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@ mod channel_invites;
|
||||
mod channel_unreads;
|
||||
mod channel_webhooks;
|
||||
mod channels;
|
||||
mod embeds;
|
||||
mod emojis;
|
||||
mod files;
|
||||
mod messages;
|
||||
mod server_bans;
|
||||
mod server_members;
|
||||
mod servers;
|
||||
@@ -16,8 +18,10 @@ pub use channel_invites::*;
|
||||
pub use channel_unreads::*;
|
||||
pub use channel_webhooks::*;
|
||||
pub use channels::*;
|
||||
pub use embeds::*;
|
||||
pub use emojis::*;
|
||||
pub use files::*;
|
||||
pub use messages::*;
|
||||
pub use server_bans::*;
|
||||
pub use server_members::*;
|
||||
pub use servers::*;
|
||||
|
||||
Reference in New Issue
Block a user