1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//! Models mapping the Discord Bot List API.

use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize};

/// Information about a bot.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Bot {
    /// The avatar hash of the bot user.
    pub avatar: Option<String>,
    /// The certified status of the bot.
    pub certified_bot: bool,
    /// The date when the bot was approved.
    pub date: DateTime<FixedOffset>,
    /// The CDN hash of the bot's avatar if the bot has none.
    pub def_avatar: Option<String>,
    /// The long description of the bot.
    ///
    /// Can contain HTML and/or Markdown.
    #[serde(rename = "longdesc")]
    pub description_long: Option<String>,
    /// The short description of the bot.
    #[serde(rename = "shortdesc")]
    pub description_short: String,
    /// The discriminator of the bot.
    pub discriminator: String,
    /// The link to the GitHub repo of the bot.
    pub github: Option<String>,
    /// The ID of the bot.
    pub id: String,
    /// The custom bot invite URL of the bot.
    pub invite: Option<String>,
    /// The library of the bot.
    pub lib: String,
    /// The owners of the bot. First one in the array is the main owner.
    pub owners: Vec<String>,
    /// The amount of upvotes the bot has.
    pub points: u64,
    /// The prefix of the bot.
    pub prefix: String,
    /// The support server invite code of the bot.
    pub support: Option<String>,
    /// The tags of the bot.
    pub tags: Vec<String>,
    /// The username of the bot.
    pub username: String,
    /// The vanity URL of the bot.
    pub vanity: Option<String>,
    /// The website URL of the bot.
    pub website: Option<String>,
}

/// Information about a bot's statistics.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BotStats {
    /// The amount of servers the bot is in.
    pub server_count: Option<u64>,
    /// The amount of servers the bot is in per shard.
    ///
    /// This is always present, but may be 0-length.
    pub shards: Vec<u64>,
    /// The amount of shards a bot has.
    pub shard_count: Option<u64>,
}

/// Information about who has voted for a bot.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum BotVotes {
    /// A list of IDs of the Discord users who have voted for a bot.
    Ids(Vec<u64>),
    /// A list of user objects of the Discord users who have voted for a bot.
    Users(Vec<DiscordUser>),
}

/// Information about a Discord user.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DiscordUser {
    /// The avatar hash of the user's avatar.
    pub avatar: Option<String>,
    /// The discriminator of the user.
    pub discriminator: u16,
    /// The ID of the user.
    pub id: String,
    /// The username of the user.
    pub username: String,
}

#[derive(Deserialize)]
pub(crate) struct ResponseUserVoted {
    pub voted: u8,
}

/// Information about a search response.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SearchResponse<T> {
    /// The length of the results vector.
    pub count: u64,
    /// The limit used.
    pub limit: u64,
    /// The offset used.
    pub offset: u64,
    /// The matching results.
    pub results: Vec<T>,
    /// The total number of results matching the search.
    pub total: u64,
}

/// Information about one or more shards, used to update a bot's sharding
/// stats.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum ShardStats {
    /// Used to post the cumulative guild information for all of the bot.
    Cumulative {
        /// The total number of shards in use.
        shard_count: Option<u64>,
        /// The total number of guilds across the entire bot.
        #[serde(rename = "server_count")]
        guild_count: u64,
    },
    /// Used to post the guild information for a single shard.
    Shard {
        /// The total number of guilds in the shard.
        #[serde(rename = "server_count")]
        guild_count: u16,
        /// The total number of shards in use.
        shard_count: u64,
        /// The ID of the shard being posted for.
        shard_id: u64,
    },
    /// Used to post the guild information for all shards.
    ///
    /// Each vector index is the shard ID mapped to the number of guilds in the
    /// shard.
    Shards(Vec<u64>),
}

/// Social information about a user.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Social {
    /// The GitHub username of the user.
    pub github: String,
    /// The Instagram username of the user.
    pub instagram: String,
    /// The Reddit username of the user.
    pub reddit: String,
    /// The Twitter username of the user.
    pub twitter: String,
    /// The YouTube username of the user.
    pub youtube: String,
}

/// Information about a user.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct User {
    /// The admin status of the user.
    pub admin: bool,
    /// The avatar hash of the user's avatar.
    pub avatar: Option<String>,
    /// The banner image URL of the user.
    pub banner: Option<String>,
    /// The bio of the user.
    pub bio: Option<String>,
    /// The certified status of the user.
    pub certified_dev: bool,
    /// The custom hex colour of the user.
    #[serde(rename = "color")]
    pub colour: Option<String>,
    /// The CDN hash of the user's avatar if the user has none.
    pub def_avatar: Option<String>,
    /// The discriminator of the user.
    pub discriminator: String,
    /// The ID of the user.
    pub id: String,
    /// The mod status of the user.
    #[serde(rename = "mod")]
    pub mod_: bool,
    /// The user's social information.
    #[serde(default)]
    pub social: Social,
    /// Whether the use is a support of the website.
    pub supporter: bool,
    /// The username of the user.
    pub username: String,
    /// The website moderator status of the user.
    pub web_mod: bool,
}

/// Information about an incoming webhook.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Webhook {
    /// ID of the bot that received a vote.
    pub bot: String,
    /// Whether the weekend multiple is in effect.
    ///
    /// This means user votes count as two.
    pub is_weekend: bool,
    /// The type of the vote.
    #[serde(rename = "type")]
    pub kind: WebhookType,
    /// The query param string found on the vote page.
    ///
    /// # Examples
    ///
    /// `?a=1&b=2`
    pub query: String,
    /// The ID of the user who voted.
    #[serde(rename = "user")]
    pub user_id: String,
}

/// The type of webhook that was received.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum WebhookType {
    /// Indicator that this was a test webhook.
    Test,
    /// Indicator that this is a "normal" webhook, i.e. non-testing.
    Upvote,
}