robespierre_models/
january.rs

1use serde::{Deserialize, Serialize};
2
3/*
4Types
5*/
6
7// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/January.ts#L1-L12
8
9/// Embedded image
10#[derive(Serialize, Deserialize, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
11#[serde(deny_unknown_fields)]
12pub struct EmbedImage {
13    pub url: String,
14    pub width: u32,
15    pub height: u32,
16    pub size: SizeType,
17}
18
19// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/January.ts#L14-L23
20
21/// Embedded video
22#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
23#[serde(deny_unknown_fields)]
24pub struct EmbedVideo {
25    pub url: String,
26    pub width: u32,
27    pub height: u32,
28}
29
30// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/January.ts#L25-L35
31
32/// Data about an embed of a special website, if it is the case
33#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
34#[serde(tag = "type")]
35#[serde(deny_unknown_fields)]
36pub enum EmbedSpecial {
37    None,
38    YouTube {
39        id: String,
40    },
41    Twitch {
42        content_type: TwitchContentType,
43        id: String,
44    },
45    Spotify {
46        content_type: String,
47        id: String,
48    },
49    Soundcloud,
50    Bandcamp {
51        content_type: BandcampContentType,
52        id: String,
53    },
54}
55
56/// Twich content type
57#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
58pub enum TwitchContentType {
59    Channel,
60    Clip,
61    Video,
62}
63
64/// Bandcamp content type
65#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
66pub enum BandcampContentType {
67    Album,
68    Track,
69}
70
71/// Size type
72#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
73pub enum SizeType {
74    Large,
75    Preview,
76}
77
78// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/January.ts#L37-L66
79
80#[derive(Serialize, Deserialize, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
81#[serde(tag = "type")]
82#[serde(deny_unknown_fields)]
83pub enum Embed {
84    None,
85    Website {
86        #[serde(default, skip_serializing_if = "Option::is_none")]
87        url: Option<String>,
88        #[serde(default, skip_serializing_if = "Option::is_none")]
89        special: Option<EmbedSpecial>,
90        #[serde(default, skip_serializing_if = "Option::is_none")]
91        title: Option<String>,
92        #[serde(default, skip_serializing_if = "Option::is_none")]
93        description: Option<String>,
94        #[serde(default, skip_serializing_if = "Option::is_none")]
95        image: Option<EmbedImage>,
96        #[serde(default, skip_serializing_if = "Option::is_none")]
97        video: Option<EmbedVideo>,
98        #[serde(default, skip_serializing_if = "Option::is_none")]
99        site_name: Option<String>,
100        #[serde(default, skip_serializing_if = "Option::is_none")]
101        icon_url: Option<String>,
102        #[serde(rename = "colour", default, skip_serializing_if = "Option::is_none")]
103        color: Option<String>,
104    },
105    Image(EmbedImage),
106}