1use serde::{Deserialize, Serialize};
2
3pub use stoat_database::events::{
4 client::{EventV1, Ping},
5 server::ClientMessage,
6};
7pub use stoat_models::v0::*;
8pub use stoat_permissions::{
9 ChannelPermission, DataPermissionsValue, Override, OverrideField, PermissionValue,
10 UserPermission,
11};
12
13use crate::Error;
14
15#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
16pub struct CaptchaFeature {
17 pub enabled: bool,
18 pub key: String,
19}
20
21#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
22pub struct Feature {
23 pub enabled: bool,
24 pub url: String,
25}
26
27#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
28pub struct VoiceNode {
29 pub name: String,
30 pub lat: f64,
31 pub lon: f64,
32 pub public_url: String,
33}
34
35#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
36pub struct VoiceFeature {
37 pub enabled: bool,
38 pub nodes: Vec<VoiceNode>,
39}
40
41#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
42pub struct StoatFeatures {
43 pub captcha: CaptchaFeature,
44 pub email: bool,
45 pub invite_only: bool,
46 pub autumn: Feature,
47 pub january: Feature,
48 pub livekit: VoiceFeature,
49}
50
51#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
52pub struct BuildInformation {
53 pub commit_sha: String,
54 pub commit_timestamp: String,
55 pub semver: String,
56 pub origin_url: String,
57 pub timestamp: String,
58}
59
60#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
61pub struct StoatConfig {
62 pub revolt: String,
63 pub features: StoatFeatures,
64 pub ws: String,
65 pub app: String,
66 pub vapid: String,
67 pub build: BuildInformation,
68}
69
70#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
71pub struct AutumnResponse {
72 pub id: String,
73}
74
75#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
76pub struct RatelimitFailure {
77 pub retry_after: u128,
78}
79
80#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
81#[serde(rename = "lowercase")]
82pub enum Tag {
83 Attachments,
84 Avatars,
85 Backgrounds,
86 Icons,
87 Banners,
88 Emojis,
89}
90
91impl Tag {
92 pub fn as_str(self) -> &'static str {
93 self.into()
94 }
95
96 pub fn to_string(self) -> String {
97 self.as_str().to_string()
98 }
99}
100
101impl Into<&'static str> for Tag {
102 fn into(self) -> &'static str {
103 match self {
104 Tag::Attachments => "attachments",
105 Tag::Avatars => "avatars",
106 Tag::Backgrounds => "backgrounds",
107 Tag::Icons => "icons",
108 Tag::Banners => "banners",
109 Tag::Emojis => "emojis",
110 }
111 }
112}
113
114impl TryFrom<&str> for Tag {
115 type Error = Error;
116
117 fn try_from(value: &str) -> Result<Self, Self::Error> {
118 match value {
119 "attachments" => Ok(Tag::Attachments),
120 "avatars" => Ok(Tag::Avatars),
121 "backgrounds" => Ok(Tag::Backgrounds),
122 "icons" => Ok(Tag::Icons),
123 "banners" => Ok(Tag::Banners),
124 "emojis" => Ok(Tag::Emojis),
125 _ => Err(Error::InvalidTag),
126 }
127 }
128}