Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
add server member and user objects
Browse files Browse the repository at this point in the history
  • Loading branch information
HTGAzureX1212 committed Mar 23, 2022
1 parent 8533a70 commit fe19dc8
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 9 deletions.
4 changes: 2 additions & 2 deletions guilded/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! # gwilight
//! # guilded
//!
//! `gwilight` is a powerful, flexible, and scalable ecosystem of Rust libraries for the Guilded
//! `guilded` is a powerful, flexible, and scalable ecosystem of Rust libraries for the Guilded
//! API.
1 change: 1 addition & 0 deletions http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
license = "ISC"
repository = "https://github.com/HarTexTeam/guilded-rs"
rust-version = "1.57.0"
version = "0.1.0-dev.1"
version = "0.1.0-dev.2"

[dependencies]
uuid = { default-features = false, features = [ "v5" ], version = "0.8.2" }
time = { default-features = false, features = [ "parsing", "std" ], version = "0.3.5" }
uuid = { default-features = false, features = [ "v5" ], version = "0.8.2" }
10 changes: 7 additions & 3 deletions model/src/id/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub struct ChannelMarker;

/// A marker for document IDs.
///
/// Document IDs on guilded are unique numerical IDs (for example, `123456`).
/// Document IDs on Guilded are unique numerical IDs (for example, `123456`).
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct DocumentMarker;

/// A marker for forum thread IDs.
///
/// Forum thread IDs on guilded are unique numerical IDs (for example, `123456`).
/// Forum thread IDs on Guilded are unique numerical IDs (for example, `123456`).
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct ForumThreadMarker;
Expand Down Expand Up @@ -46,11 +46,15 @@ pub struct UserMarker;

/// A marker for reaction IDs.
///
/// Reaction IDs on guilded are unique numerical IDs (for example, `123456`).
/// Reaction IDs on Guilded are unique numerical IDs (for example, `123456`).
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct ReactionMarker;

#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct RoleMarker;

/// A marker for server IDs.
///
/// Server IDs on Guilded are unique 8-character IDs (for example, `Ann6LewA`).
Expand Down
6 changes: 4 additions & 2 deletions model/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # gwilight_model
//! # guilded_model
//!
//! `gwilight_model` is a crate of models for the Guilded API.
//! `guilded_model` is a crate of models for the Guilded API.
pub mod datetime;
pub mod docs;
Expand All @@ -9,3 +9,5 @@ pub mod id;
pub mod list;
pub mod messaging;
pub mod reactions;
pub mod server;
pub mod user;
32 changes: 32 additions & 0 deletions model/src/server/member/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! The member object.
use crate::datetime::Timestamp;
use crate::id::{marker::RoleMarker, Id};
use crate::user::User;

/// Represents a server member.
#[derive(Clone, Debug)]
pub struct Member {
user: User,
role_ids: Vec<Id<RoleMarker>>,
nickname: Option<String>,
joined_at: Timestamp
}

impl Member {
pub fn user(&self) -> User {
self.user.clone()
}

pub fn role_ids(&self) -> Vec<Id<RoleMarker>> {
self.role_ids.clone()
}

pub fn nickname(&self) -> Option<&str> {
self.nickname.as_deref()
}

pub fn joined_at(&self) -> Timestamp {
self.joined_at
}
}
1 change: 1 addition & 0 deletions model/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod member;
37 changes: 37 additions & 0 deletions model/src/user/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! The user object.
use crate::datetime::Timestamp;
use crate::id::{marker::UserMarker, Id};

#[derive(Clone, Debug)]
pub struct User {
id: Id<UserMarker>,
r#type: UserType,
name: String,
created_at: Timestamp,
}

impl User {
pub fn id(&self) -> Id<UserMarker> {
self.id.clone()
}

pub fn r#type(&self) -> UserType {
self.r#type.clone()
}

pub fn name(&self) -> &str {
self.name.as_ref()
}

pub fn created_at(&self) -> Timestamp {
self.created_at
}
}

/// Represents the type of a user.
#[derive(Clone, Debug)]
pub enum UserType {
Bot,
User
}

0 comments on commit fe19dc8

Please sign in to comment.