revolt_models/v0/
bots.rs

1use super::User;
2
3auto_derived!(
4    /// Bot
5    #[derive(Default)]
6    pub struct Bot {
7        /// Bot Id
8        #[cfg_attr(feature = "serde", serde(rename = "_id"))]
9        pub id: String,
10
11        /// User Id of the bot owner
12        #[cfg_attr(feature = "serde", serde(rename = "owner"))]
13        pub owner_id: String,
14        /// Token used to authenticate requests for this bot
15        pub token: String,
16        /// Whether the bot is public
17        /// (may be invited by anyone)
18        pub public: bool,
19
20        /// Whether to enable analytics
21        #[cfg_attr(
22            feature = "serde",
23            serde(skip_serializing_if = "crate::if_false", default)
24        )]
25        pub analytics: bool,
26        /// Whether this bot should be publicly discoverable
27        #[cfg_attr(
28            feature = "serde",
29            serde(skip_serializing_if = "crate::if_false", default)
30        )]
31        pub discoverable: bool,
32        /// Reserved; URL for handling interactions
33        #[cfg_attr(
34            feature = "serde",
35            serde(skip_serializing_if = "String::is_empty", default)
36        )]
37        pub interactions_url: String,
38        /// URL for terms of service
39        #[cfg_attr(
40            feature = "serde",
41            serde(skip_serializing_if = "String::is_empty", default)
42        )]
43        pub terms_of_service_url: String,
44        /// URL for privacy policy
45        #[cfg_attr(
46            feature = "serde",
47            serde(skip_serializing_if = "String::is_empty", default)
48        )]
49        pub privacy_policy_url: String,
50
51        /// Enum of bot flags
52        #[cfg_attr(
53            feature = "serde",
54            serde(skip_serializing_if = "crate::if_zero_u32", default)
55        )]
56        pub flags: u32,
57    }
58
59    /// Optional fields on bot object
60    pub enum FieldsBot {
61        Token,
62        InteractionsURL,
63    }
64
65    /// Flags that may be attributed to a bot
66    #[repr(u32)]
67    pub enum BotFlags {
68        Verified = 1,
69        Official = 2,
70    }
71
72    /// Public Bot
73    pub struct PublicBot {
74        /// Bot Id
75        #[cfg_attr(feature = "serde", serde(rename = "_id"))]
76        pub id: String,
77
78        /// Bot Username
79        pub username: String,
80        /// Profile Avatar
81        #[cfg_attr(
82            feature = "serde",
83            serde(skip_serializing_if = "String::is_empty", default)
84        )]
85        pub avatar: String,
86        /// Profile Description
87        #[cfg_attr(
88            feature = "serde",
89            serde(skip_serializing_if = "String::is_empty", default)
90        )]
91        pub description: String,
92    }
93
94    /// Bot Response
95    pub struct FetchBotResponse {
96        /// Bot object
97        pub bot: Bot,
98        /// User object
99        pub user: User,
100    }
101
102    /// Bot Details
103    #[derive(Default)]
104    #[cfg_attr(feature = "validator", derive(validator::Validate))]
105    pub struct DataCreateBot {
106        /// Bot username
107        #[cfg_attr(
108            feature = "validator",
109            validate(length(min = 2, max = 32), regex = "super::RE_USERNAME")
110        )]
111        pub name: String,
112    }
113
114    /// New Bot Details
115    #[derive(Default)]
116    #[cfg_attr(feature = "validator", derive(validator::Validate))]
117    pub struct DataEditBot {
118        /// Bot username
119        #[cfg_attr(
120            feature = "validator",
121            validate(length(min = 2, max = 32), regex = "super::RE_USERNAME")
122        )]
123        #[serde(skip_serializing_if = "Option::is_none")]
124        pub name: Option<String>,
125        /// Whether the bot can be added by anyone
126        pub public: Option<bool>,
127        /// Whether analytics should be gathered for this bot
128        ///
129        /// Must be enabled in order to show up on [Revolt Discover](https://rvlt.gg).
130        pub analytics: Option<bool>,
131        /// Interactions URL
132        #[cfg_attr(feature = "validator", validate(length(min = 1, max = 2048)))]
133        pub interactions_url: Option<String>,
134        /// Fields to remove from bot object
135        #[cfg_attr(feature = "validator", validate(length(min = 1)))]
136        pub remove: Option<Vec<FieldsBot>>,
137    }
138
139    /// Where we are inviting a bot to
140    #[serde(untagged)]
141    pub enum InviteBotDestination {
142        /// Invite to a server
143        Server {
144            /// Server Id
145            server: String,
146        },
147        /// Invite to a group
148        Group {
149            /// Group Id
150            group: String,
151        },
152    }
153
154    /// Owned Bots Response
155    ///
156    /// Both lists are sorted by their IDs.
157    ///
158    /// TODO: user should be in bot object
159    pub struct OwnedBotsResponse {
160        /// Bot objects
161        pub bots: Vec<Bot>,
162        /// User objects
163        pub users: Vec<User>,
164    }
165
166    /// Bot with user response
167    pub struct BotWithUserResponse {
168        #[serde(flatten)]
169        pub bot: Bot,
170        pub user: User,
171    }
172);