From 69cc20b406a77bebf7ccbd61336e5d149848af08 Mon Sep 17 00:00:00 2001 From: n1c00o Date: Sat, 2 Oct 2021 22:40:23 +0200 Subject: [PATCH] Implement User-related structures --- common/rust/src/discord_models/guild.rs | 47 ++++++++++++++++ common/rust/src/discord_models/mod.rs | 2 + common/rust/src/discord_models/user.rs | 73 +++++++++++++++++++++++++ common/rust/src/lib.rs | 1 + 4 files changed, 123 insertions(+) create mode 100644 common/rust/src/discord_models/guild.rs create mode 100644 common/rust/src/discord_models/mod.rs create mode 100644 common/rust/src/discord_models/user.rs diff --git a/common/rust/src/discord_models/guild.rs b/common/rust/src/discord_models/guild.rs new file mode 100644 index 0000000..92a11e7 --- /dev/null +++ b/common/rust/src/discord_models/guild.rs @@ -0,0 +1,47 @@ +use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; + +use super::user::User; + +#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] +#[repr(u8)] +pub enum IntegrationExpireBehavior { + RemoveRole = 0, + Kick = 1, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct IntegrationAccount { + pub id: String, + pub name: String, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct IntegrationApplication { + pub id: String, + pub name: String, + pub icon: Option, + pub description: String, + pub summary: Option, + pub bot: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct Integration { + pub id: String, + pub name: String, + #[serde(rename = "type")] + pub type_: String, + pub enabled: bool, + pub syncing: Option, + pub role_id: Option, + pub enable_emoticons: Option, + pub expire_behavior: Option, + pub expire_grace_period: Option, + pub user: Option, + pub account: IntegrationAccount, + pub synced_at: Option, + pub subscriber_count: Option, + pub revoked: Option, + pub application: Option, +} diff --git a/common/rust/src/discord_models/mod.rs b/common/rust/src/discord_models/mod.rs new file mode 100644 index 0000000..56d877f --- /dev/null +++ b/common/rust/src/discord_models/mod.rs @@ -0,0 +1,2 @@ +pub mod guild; +pub mod user; diff --git a/common/rust/src/discord_models/user.rs b/common/rust/src/discord_models/user.rs new file mode 100644 index 0000000..36914ce --- /dev/null +++ b/common/rust/src/discord_models/user.rs @@ -0,0 +1,73 @@ +use enumflags2::{bitflags, BitFlags}; +use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; + +use super::guild::Integration; + +#[bitflags] +#[repr(u64)] +#[derive(Debug, Clone, Copy)] +pub enum UserFlags { + // None = 0 << 0, + DiscordEmployee = 1 << 0, + PartneredServerOwner = 1 << 1, + HypesquadEvents = 1 << 2, + BugHunterLevel1 = 1 << 3, + HouseBravery = 1 << 6, + HouseBrilliance = 1 << 7, + HouseBalance = 1 << 8, + EarlySupporter = 1 << 9, + TeamUser = 1 << 10, + BugHunterLevel2 = 1 << 14, + VerifiedBot = 1 << 16, + EarlyVerifiedBotDeveloper = 1 << 17, + DiscordCertifiedModerator = 1 << 18, +} + +#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] +#[repr(u8)] +pub enum PremiumTypes { + None = 0, + NitroClassic = 1, + Nitro = 2, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +/// Represents a User within Discord +pub struct User { + pub id: String, + pub username: String, + pub discriminator: String, + pub avatar: Option, + pub bot: Option, + pub system: Option, + pub mfa_enabled: Option, + pub locale: Option, + pub verified: Option, + pub email: Option, + pub flags: Option>, + pub premium_type: Option, + pub public_flags: Option>, +} + +#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] +#[repr(u8)] +pub enum VisibilityTypes { + None = 0, + Everyone = 1, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +/// The connection object that the user has attached. +pub struct Connection { + pub id: String, + pub name: String, + #[serde(rename = "type")] + pub type_: String, + pub revoked: Option, + pub integrations: Option>, + pub verified: bool, + pub friend_sync: bool, + pub show_activity: bool, + pub visibility: VisibilityTypes, +} diff --git a/common/rust/src/lib.rs b/common/rust/src/lib.rs index 90f4b96..a021e97 100644 --- a/common/rust/src/lib.rs +++ b/common/rust/src/lib.rs @@ -1,6 +1,7 @@ /// This crate contains shared code in all the rust projects /// It contains utilities such as monitoring, logging and more. pub mod config; +pub mod discord_models; pub mod error; pub mod monitoring; pub mod nats; -- 2.39.5