Skip to content

Commit

Permalink
project: add model
Browse files Browse the repository at this point in the history
Signed-off-by: Zeyla Hellyer <zeyla@hellyer.dev>
  • Loading branch information
zeylahellyer committed Sep 3, 2019
1 parent f7beb72 commit 1d3f210
Show file tree
Hide file tree
Showing 134 changed files with 2,562 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lmao/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ authors = ["Zeyla Hellyer <zeyla@hellyer.dev>"]
documentation = "https://docs.rs/lmao"
edition = "2018"
homepage = "https://github.com/zeyla/lmao"
include = ["src/*.rs", "Cargo.toml"]
keywords = ["discord", "discord-api", "lmao"]
license = "ISC"
name = "lmao"
publish = false
Expand Down
23 changes: 23 additions & 0 deletions model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = ["Zeyla Hellyer <zeyla@hellyer.dev>"]
documentation = "https://docs.rs/lmao-model"
edition = "2018"
homepage = "https://github.com/lmao-rs/lmao"
include = ["src/*.rs", "Cargo.toml"]
keywords = ["discord", "discord-api", "lmao"]
license = "ISC"
name = "lmao-model"
publish = false
readme = "README.md"
repository = "https://github.com/lmao-rs/lmao.git"
version = "0.1.0"

[dependencies]
bitflags = "1"
chrono = { features = ["serde"], optional = true, version = "0.4" }
serde = { features = ["derive"], version = "1" }
serde_json = "1"
serde_repr = "0.1"

[features]
default = ["chrono", "chrono/serde"]
1 change: 1 addition & 0 deletions model/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../LICENSE.md
43 changes: 43 additions & 0 deletions model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[![license badge][]][license link] [![rust badge]][rust link]

# lmao-model

See the [`lmao`] documentation for more information.

`lmao-model` is a crate of only serde models defining the Discord APIs with
no implementations on top of them or functions to work with them.

These are in a single crate for ease of use, a single point of definition,
and a sort of versioning of the Discord API. Similar to how a database
schema progresses in versions, the definition of the API also progresses in
versions.

The types in this crate are reproducible: deserializing a payload into a
type, serializing it, and then deserializing it again will work.

Defined are a number of modules defining types returned by or owned by
resource categories. For example, `gateway` are types used to interact with
and returned by the gateway API. `guild` contains types owned by the Guild
resource category. These types may be directly returned by, built on top of,
or extended by other crates.

### Installation

This crate requires Rust 1.31+.

Add the following to your `Cargo.toml`:

```toml
lmao-model = "0.1"
```

## License

[ISC][LICENSE.md]

[LICENSE.md]: https://github.com/zeyla/lmao/blob/master/LICENSE.md
[`lmao`]: https://docs.rs/lmao
[license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square
[license link]: https://opensource.org/licenses/ISC
[rust badge]: https://img.shields.io/badge/rust-1.31+-93450a.svg?style=flat-square
[rust link]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
13 changes: 13 additions & 0 deletions model/src/channel/attachment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::id::AttachmentId;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Attachment {
pub id: AttachmentId,
pub filename: String,
pub height: Option<u64>,
pub proxy_url: String,
pub size: u64,
pub url: String,
pub width: Option<u64>,
}
21 changes: 21 additions & 0 deletions model/src/channel/category_channel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::{
channel::{
permission_overwrite::PermissionOverwrite,
ChannelType,
},
id::ChannelId,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CategoryChannel {
pub id: ChannelId,
#[serde(rename = "type")]
pub kind: ChannelType,
pub name: String,
#[serde(default)]
pub nsfw: bool,
pub parent_id: Option<ChannelId>,
pub permission_overwrites: Vec<PermissionOverwrite>,
pub position: i64,
}
14 changes: 14 additions & 0 deletions model/src/channel/channel_mention.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::{
channel::ChannelType,
id::{ChannelId, GuildId},
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ChannelMention {
pub guild_id: GuildId,
pub id: ChannelId,
#[serde(rename = "type")]
pub kind: ChannelType,
pub name: String,
}
13 changes: 13 additions & 0 deletions model/src/channel/channel_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(Clone, Copy, Debug, Deserialize_repr, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize_repr)]
#[repr(u8)]
pub enum ChannelType {
GuildText = 0,
Private = 1,
GuildVoice = 2,
Group = 3,
GuildCategory = 4,
GuildNews = 5,
GuildStore = 6,
}
9 changes: 9 additions & 0 deletions model/src/channel/embed/author.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedAuthor {
pub icon_url: Option<String>,
pub name: String,
pub proxy_icon_url: Option<String>,
pub url: Option<String>,
}
9 changes: 9 additions & 0 deletions model/src/channel/embed/field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedField {
#[serde(default)]
pub inline: bool,
pub name: String,
pub value: String,
}
8 changes: 8 additions & 0 deletions model/src/channel/embed/footer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedFooter {
pub icon_url: Option<String>,
pub proxy_icon_url: Option<String>,
pub text: String,
}
9 changes: 9 additions & 0 deletions model/src/channel/embed/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedImage {
pub height: u64,
pub proxy_url: String,
pub url: String,
pub width: u64,
}
38 changes: 38 additions & 0 deletions model/src/channel/embed/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
mod author;
mod field;
mod footer;
mod image;
mod provider;
mod thumbnail;
mod video;

pub use self::{
author::EmbedAuthor,
field::EmbedField,
footer::EmbedFooter,
image::EmbedImage,
provider::EmbedProvider,
thumbnail::EmbedThumbnail,
video::EmbedVideo,
};

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Embed {
pub author: Option<EmbedAuthor>,
pub color: u32,
pub description: Option<String>,
#[serde(default)]
pub fields: Vec<EmbedField>,
pub footer: Option<EmbedFooter>,
pub image: Option<EmbedImage>,
#[serde(rename = "type")]
pub kind: String,
pub provider: Option<EmbedProvider>,
pub thumbnail: Option<EmbedThumbnail>,
pub timestamp: Option<String>,
pub title: Option<String>,
pub url: Option<String>,
pub video: Option<EmbedVideo>,
}
7 changes: 7 additions & 0 deletions model/src/channel/embed/provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedProvider {
pub name: String,
pub url: Option<String>,
}
9 changes: 9 additions & 0 deletions model/src/channel/embed/thumbnail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedThumbnail {
pub height: u64,
pub proxy_url: String,
pub url: String,
pub width: u64,
}
8 changes: 8 additions & 0 deletions model/src/channel/embed/video.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EmbedVideo {
pub height: u64,
pub url: String,
pub width: u64,
}
23 changes: 23 additions & 0 deletions model/src/channel/group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::{
channel::ChannelType,
id::{ApplicationId, ChannelId, MessageId, UserId},
user::User,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Group {
pub id: ChannelId,
pub application_id: Option<ApplicationId>,
pub icon: Option<String>,
#[serde(rename = "type")]
pub kind: ChannelType,
pub last_message_id: Option<MessageId>,
#[cfg(feature = "chrono")]
pub last_pin_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
#[cfg(not(feature = "chrono"))]
pub last_pin_timestamp: Option<String>,
pub name: Option<String>,
pub owner_id: UserId,
pub recipients: Vec<User>,
}
8 changes: 8 additions & 0 deletions model/src/channel/message/activity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};
use super::MessageActivityType;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MessageActivity {
pub kind: MessageActivityType,
pub party_id: Option<String>,
}
10 changes: 10 additions & 0 deletions model/src/channel/message/activity_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(Clone, Copy, Debug, Deserialize_repr, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize_repr)]
#[repr(u8)]
pub enum MessageActivityType {
Join = 1,
Spectate = 2,
Listen = 3,
JoinRequest = 5,
}
11 changes: 11 additions & 0 deletions model/src/channel/message/application.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::id::ApplicationId;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MessageApplication {
pub id: ApplicationId,
pub cover_image: Option<String>,
pub description: String,
pub icon: Option<String>,
pub name: String,
}
11 changes: 11 additions & 0 deletions model/src/channel/message/flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use bitflags::bitflags;
use serde::{Deserialize, Serialize};

bitflags! {
#[derive(Deserialize, Serialize)]
pub struct MessageFlags: u64 {
const CROSSPOSTED = 1;
const IS_CROSSPOST = 1 << 1;
const SUPPRESS_EMBEDS = 1 << 2;
}
}
19 changes: 19 additions & 0 deletions model/src/channel/message/kind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(Clone, Copy, Debug, Deserialize_repr, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize_repr)]
#[repr(u8)]
pub enum MessageType {
Regular = 0,
RecipientAdd = 1,
RecipientRemove = 2,
Call = 3,
ChannelNameChange = 4,
ChannelIconChange = 5,
ChannelMessagePinned = 6,
GuildMemberJoin = 7,
UserPremiumSub = 8,
UserPremiumSubTier1 = 9,
UserPremiumSubTier2 = 10,
UserPremiumSubTier3 = 11,
ChannelFollowAdd = 12,
}
Loading

0 comments on commit 1d3f210

Please sign in to comment.