top_gg/model.rs
1//! Models mapping the top.gg API.
2
3use chrono::{DateTime, FixedOffset};
4use serde::{Deserialize, Serialize};
5
6/// Information about a bot.
7#[derive(Clone, Debug, Deserialize, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Bot {
10 /// The avatar hash of the bot user.
11 pub avatar: Option<String>,
12 /// The certified status of the bot.
13 pub certified_bot: bool,
14 /// The date when the bot was approved.
15 pub date: DateTime<FixedOffset>,
16 /// The CDN hash of the bot's avatar if the bot has none.
17 pub def_avatar: Option<String>,
18 /// The long description of the bot.
19 ///
20 /// Can contain HTML and/or Markdown.
21 #[serde(rename = "longdesc")]
22 pub description_long: Option<String>,
23 /// The short description of the bot.
24 #[serde(rename = "shortdesc")]
25 pub description_short: String,
26 /// The discriminator of the bot.
27 pub discriminator: String,
28 /// The link to the GitHub repo of the bot.
29 pub github: Option<String>,
30 /// The ID of the bot.
31 pub id: String,
32 /// The custom bot invite URL of the bot.
33 pub invite: Option<String>,
34 /// The library of the bot.
35 pub lib: String,
36 /// The owners of the bot. First one in the array is the main owner.
37 pub owners: Vec<String>,
38 /// The amount of upvotes the bot has.
39 pub points: u64,
40 /// The prefix of the bot.
41 pub prefix: String,
42 /// The support server invite code of the bot.
43 pub support: Option<String>,
44 /// The tags of the bot.
45 pub tags: Vec<String>,
46 /// The username of the bot.
47 pub username: String,
48 /// The vanity URL of the bot.
49 pub vanity: Option<String>,
50 /// The website URL of the bot.
51 pub website: Option<String>,
52}
53
54/// Information about a bot's statistics.
55#[derive(Clone, Debug, Deserialize, Serialize)]
56#[serde(rename_all = "camelCase")]
57pub struct BotStats {
58 /// The amount of servers the bot is in.
59 pub server_count: Option<u64>,
60 /// The amount of servers the bot is in per shard.
61 ///
62 /// This is always present, but may be 0-length.
63 pub shards: Vec<u64>,
64 /// The amount of shards a bot has.
65 pub shard_count: Option<u64>,
66}
67
68/// Information about who has voted for a bot.
69#[derive(Clone, Debug, Deserialize, Serialize)]
70#[serde(untagged)]
71pub enum BotVotes {
72 /// A list of IDs of the Discord users who have voted for a bot.
73 Ids(Vec<u64>),
74 /// A list of user objects of the Discord users who have voted for a bot.
75 Users(Vec<DiscordUser>),
76}
77
78/// Information about a Discord user.
79#[derive(Clone, Debug, Deserialize, Serialize)]
80#[serde(rename_all = "camelCase")]
81pub struct DiscordUser {
82 /// The avatar hash of the user's avatar.
83 pub avatar: Option<String>,
84 /// The discriminator of the user.
85 pub discriminator: u16,
86 /// The ID of the user.
87 pub id: String,
88 /// The username of the user.
89 pub username: String,
90}
91
92#[derive(Deserialize)]
93pub(crate) struct ResponseUserVoted {
94 pub voted: u8,
95}
96
97/// Information about a search response.
98#[derive(Clone, Debug, Deserialize, Serialize)]
99#[serde(rename_all = "camelCase")]
100pub struct SearchResponse<T> {
101 /// The length of the results vector.
102 pub count: u64,
103 /// The limit used.
104 pub limit: u64,
105 /// The offset used.
106 pub offset: u64,
107 /// The matching results.
108 pub results: Vec<T>,
109 /// The total number of results matching the search.
110 pub total: u64,
111}
112
113/// Information about one or more shards, used to update a bot's sharding
114/// stats.
115#[derive(Clone, Debug, Deserialize, Serialize)]
116#[serde(untagged)]
117pub enum ShardStats {
118 /// Used to post the cumulative guild information for all of the bot.
119 Cumulative {
120 /// The total number of shards in use.
121 shard_count: Option<u64>,
122 /// The total number of guilds across the entire bot.
123 #[serde(rename = "server_count")]
124 guild_count: u64,
125 },
126 /// Used to post the guild information for a single shard.
127 Shard {
128 /// The total number of guilds in the shard.
129 #[serde(rename = "server_count")]
130 guild_count: u16,
131 /// The total number of shards in use.
132 shard_count: u64,
133 /// The ID of the shard being posted for.
134 shard_id: u64,
135 },
136 /// Used to post the guild information for all shards.
137 ///
138 /// Each vector index is the shard ID mapped to the number of guilds in the
139 /// shard.
140 Shards(Vec<u64>),
141}
142
143/// Social information about a user.
144#[derive(Clone, Debug, Default, Deserialize, Serialize)]
145#[serde(rename_all = "camelCase")]
146pub struct Social {
147 /// The GitHub username of the user.
148 pub github: String,
149 /// The Instagram username of the user.
150 pub instagram: String,
151 /// The Reddit username of the user.
152 pub reddit: String,
153 /// The Twitter username of the user.
154 pub twitter: String,
155 /// The YouTube username of the user.
156 pub youtube: String,
157}
158
159/// Information about a user.
160#[derive(Clone, Debug, Deserialize, Serialize)]
161#[serde(rename_all = "camelCase")]
162pub struct User {
163 /// The admin status of the user.
164 pub admin: bool,
165 /// The avatar hash of the user's avatar.
166 pub avatar: Option<String>,
167 /// The banner image URL of the user.
168 pub banner: Option<String>,
169 /// The bio of the user.
170 pub bio: Option<String>,
171 /// The certified status of the user.
172 pub certified_dev: bool,
173 /// The custom hex colour of the user.
174 #[serde(rename = "color")]
175 pub colour: Option<String>,
176 /// The CDN hash of the user's avatar if the user has none.
177 pub def_avatar: Option<String>,
178 /// The discriminator of the user.
179 pub discriminator: String,
180 /// The ID of the user.
181 pub id: String,
182 /// The mod status of the user.
183 #[serde(rename = "mod")]
184 pub mod_: bool,
185 /// The user's social information.
186 #[serde(default)]
187 pub social: Social,
188 /// Whether the use is a support of the website.
189 pub supporter: bool,
190 /// The username of the user.
191 pub username: String,
192 /// The website moderator status of the user.
193 pub web_mod: bool,
194}
195
196/// Information about an incoming webhook.
197#[derive(Clone, Debug, Deserialize, Serialize)]
198#[serde(rename_all = "camelCase")]
199pub struct Webhook {
200 /// ID of the bot that received a vote.
201 pub bot: String,
202 /// Whether the weekend multiple is in effect.
203 ///
204 /// This means user votes count as two.
205 pub is_weekend: bool,
206 /// The type of the vote.
207 #[serde(rename = "type")]
208 pub kind: WebhookType,
209 /// The query param string found on the vote page.
210 ///
211 /// # Examples
212 ///
213 /// `?a=1&b=2`
214 pub query: String,
215 /// The ID of the user who voted.
216 #[serde(rename = "user")]
217 pub user_id: String,
218}
219
220/// The type of webhook that was received.
221#[derive(Clone, Debug, Deserialize, Serialize)]
222#[serde(rename_all = "camelCase")]
223pub enum WebhookType {
224 /// Indicator that this was a test webhook.
225 Test,
226 /// Indicator that this is a "normal" webhook, i.e. non-testing.
227 Upvote,
228}