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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
use crate::json::Nullable;
use crate::gateway::{User, PartialUser, PartialVoiceState, Channel};
use crate::Snowflake;

#[object(server)]
pub struct Guild {
    pub id: Snowflake,
    pub name: String,
    pub icon: Nullable<String>,
    pub splash: Nullable<String>,
    pub owner: Option<bool>,
    pub owner_id: Snowflake,
    pub permissions: Option<u32>,
    pub region: String,
    pub afk_channel_id: Nullable<Snowflake>,
    pub afk_timeout: i32,
    pub embed_enabled: Option<bool>,
    pub embed_channel_id: Option<Snowflake>,
    pub verification_level: VerificationLevel,
    pub default_message_notifications: DefaultMessageNotificationLevel,
    pub explicit_content_filter: ExplicitContentFilterLevel,
    pub roles: Vec<Role>,
    pub emojis: Vec<Emoji>,
    pub features: Vec<GuildFeature>,
    pub mfa_level: MFALevel,
    pub application_id: Nullable<Snowflake>,
    pub widget_enabled: Option<bool>,
    pub widget_channel_id: Option<Snowflake>,
    pub system_channel_id: Nullable<Snowflake>,
    pub joined_at: Option<String>,
    pub large: Option<bool>,
    pub unavailable: Option<bool>,
    pub member_count: Option<i32>,
    pub voice_states: Option<Vec<PartialVoiceState>>,
    pub members: Option<Vec<GuildMember>>,
    pub channels: Option<Vec<Channel>>,
    pub presences: Option<Vec<PartialPresenceUpdate>>,
    pub max_presences: Option<Nullable<i32>>,
    pub max_members: Option<i32>,
    pub vanity_url_code: Nullable<String>,
    pub description: Nullable<String>,
    pub banner: Nullable<String>,
    pub premium_tier: PremiumTier,
    pub premium_subscription_count: Nullable<i32>,
    pub preferred_locale: String,
    pub lazy: bool,
    pub rules_channel_id: Nullable<Snowflake>
}

#[object(server)]
pub struct PartialGuild {
    pub id: Snowflake,
    pub name: String,
    pub icon: Nullable<String>,
    pub splash: Nullable<String>
}

#[object(server)]
pub struct UnavailableGuild {
    pub id: Snowflake,
    pub unavailable: bool
}

#[convert(u32)]
pub enum Permission {
    CreateInstantInvite = 1 << 0,
    KickMembers = 1 << 1,
    BanMembers = 1 << 2,
    Administrator = 1 << 3,
    ManageChannels = 1 << 4,
    ManageGuild = 1 << 5,
    AddReactions = 1 << 6,
    ViewAuditLog = 1 << 7,
    PrioritySpeaker = 1 << 8,
    Stream = 1 << 9,
    ViewChannel = 1 << 10,
    SendMessages = 1 << 11,
    SendTTSMessages = 1 << 12,
    ManageMessages = 1 << 13,
    EmbedLinks = 1 << 14,
    AttachFiles = 1 << 15,
    ReadMessageHistory = 1 << 16,
    MentionEveryone = 1 << 17,
    UseExternalEmojis = 1 << 18,
    Connect = 1 << 20,
    Speak = 1 << 21,
    MuteMembers = 1 << 22,
    DeafenMembers = 1 << 23,
    MoveMembers = 1 << 24,
    UseVAD = 1 << 25,
    ChangeNickname = 1 << 26,
    ManageNicknames = 1 << 27,
    ManageRoles = 1 << 28,
    ManageWebhooks = 1 << 29,
    ManageEmojis = 1 << 30,
}

#[convert(u8)]
pub enum VerificationLevel {
    None = 0,
    Low = 1,
    Medium = 2,
    High = 3,
    VeryHigh = 4
}

#[convert(u8)]
pub enum DefaultMessageNotificationLevel {
    AllMessages = 0,
    OnlyMentions = 1,
}

#[convert(u8)]
pub enum ExplicitContentFilterLevel {
    Disabled = 0,
    MembersWithoutRoles = 1,
    AllMembers = 2
}

#[stringify(upper_snake_case)]
pub enum GuildFeature {
    InviteSplash,
    VipRegions,
    VanityUrl,
    Verified,
    Partnered,
    Lurkable,
    Commerce,
    News,
    Discoverable,
    Featurable,
    AnimatedIcon,
    Banner
}

#[convert(u8)]
pub enum MFALevel {
    None = 0,
    Elevated = 1,
}

#[convert(u8)]
pub enum PremiumTier {
    None = 0,
    Tier1 = 1,
    Tier2 = 2,
    Tier3 = 3,
}

#[object(both)]
pub struct Role {
    pub id: Snowflake,
    pub name: String,
    pub color: i32,
    pub hoist: bool,
    pub position: i32,
    pub permissions: u32,
    pub managed: bool,
    pub mentionable: bool
}

#[object(server)]
pub struct PartialRole {
    pub id: Snowflake,
    pub name: String,
}

#[object(both)]
pub struct Emoji {
    pub id: Nullable<Snowflake>,
    pub name: String,
    pub roles: Option<Vec<Role>>,
    pub user: Option<User>,
    pub require_colons: Option<bool>,
    pub managed: Option<bool>,
    pub animated: Option<bool>,
    pub available: bool
}

#[object(both)]
pub struct PartialEmoji {
    pub id: Option<Nullable<Snowflake>>,
    pub name: String,
    pub roles: Option<Vec<Role>>,
    pub user: Option<User>,
    pub require_colons: Option<bool>,
    pub managed: Option<bool>,
    pub animated: Option<bool>
}

#[object(server)]
pub struct GuildMember {
    pub user: User,
    pub nick: Option<Nullable<String>>,
    pub roles: Vec<Snowflake>,
    pub joined_at: String,
    pub premium_since: Option<Nullable<String>>,
    pub hoisted_role: Nullable<Snowflake>,
    pub deaf: bool,
    pub mute: bool
}

#[object(server)]
pub struct PartialGuildMember {
    pub user: Option<User>,
    pub nick: Option<Nullable<String>>,
    pub roles: Vec<Snowflake>,
    pub joined_at: String,
    pub premium_since: Option<Nullable<String>>,
    pub hoisted_role: Nullable<Snowflake>,
    pub deaf: bool,
    pub mute: bool
}

/// A user's presence is their current state on a guild.
/// This event is sent when a user's presence or info,
/// such as name or avatar, is updated.
///
/// The user object within this event can be partial,
/// the only field which must be sent is the `id`
/// field, everything else is optional. Along with this
/// limitation, no fields are required, and the types of
/// the fields are not validated. Your client should
/// expect any combination of fields and types within
/// this event.
///
/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#presence-update)
#[object(server)]
pub struct PresenceUpdate {
    pub user: PartialUser,
    pub nick: Option<Nullable<String>>,
    pub roles: Vec<Snowflake>,
    pub game: Nullable<Activity>,
    pub guild_id: Snowflake,
    pub status: String,
    pub activities: Vec<Activity>,
    pub client_status: ClientStatus,
    pub premium_since: Option<Nullable<String>>
}

/// A user's presence is their current state on a guild.
/// This event is sent when a user's presence or info,
/// such as name or avatar, is updated.
///
/// The user object within this event can be partial,
/// the only field which must be sent is the `id`
/// field, everything else is optional. Along with this
/// limitation, no fields are required, and the types of
/// the fields are not validated. Your client should
/// expect any combination of fields and types within
/// this event.
///
/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#presence-update)
#[object(server)]
pub struct PartialPresenceUpdate {
    pub user: Option<PartialUser>,
    pub roles: Option<Vec<Snowflake>>,
    pub game: Option<Nullable<Activity>>,
    pub guild_id: Option<Snowflake>,
    pub status: Option<String>,
    pub activities: Option<Vec<Activity>>,
    pub client_status: Option<ClientStatus>
}

/// Active sessions are indicated with an "online",
/// "idle", or "dnd" string per platform. If a user
/// is offline or invisible, the corresponding
/// field is not present.
///
/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#client-status-object)
#[object(server)]
pub struct ClientStatus {
    pub desktop: Option<String>,
    pub mobile: Option<String>,
    pub web: Option<String>
}

/// A user's displayed activity.
///
/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#activity-object)
#[object(both)]
pub struct Activity {
    pub id: String,
    pub name: String,
    pub _type: ActivityType,
    pub url: Option<Nullable<String>>,
    pub timestamps: Option<ActivityTimestamps>,
    pub application_id: Option<Snowflake>,
    pub details: Option<Nullable<String>>,
    pub state: Option<Nullable<String>>,
    pub emoji: Option<PartialEmoji>,
    pub party: Option<ActivityParty>,
    pub assets: Option<ActivityAssets>,
    pub secrets: Option<ActivitySecrets>,
    pub instance: Option<bool>,
    pub flags: Option<u32>,
    pub sync_id: Option<String>,
    pub session_id: Option<String>,
    pub created_at: u64
}

#[convert(u8)]
pub enum ActivityType {
    Game = 0,
    Streaming = 1,
    Listening = 2,
    Custom = 4
}

#[convert(u32)]
pub enum ActivityFlags {
    Instance = 1 << 0,
    Join = 1 << 1,
    Spectate = 1 << 2,
    JoinRequest = 1 << 3,
    Sync = 1 << 4,
    Play = 1 << 5,
}

/// The unix timestamps of the start and the
/// end of the activity in milliseconds.
///
/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-timestamps)
#[object(both)]
pub struct ActivityTimestamps {
    pub start: Option<u64>,
    pub end: Option<u64>
}

/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-party)
#[object(both)]
pub struct ActivityParty {
    pub id: Option<String>,
    pub size: Option<[i32; 2]>
}

/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-assets)
#[object(both)]
pub struct ActivityAssets {
    pub large_image: Option<String>,
    pub large_text: Option<String>,
    pub small_image: Option<String>,
    pub small_text: Option<String>,
}

/// More information on [Discord's documentation](https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-secrets)
#[object(both)]
pub struct ActivitySecrets {
    pub join: Option<String>,
    pub spectate: Option<String>,
    pub _match: Option<String>,
}