diff options
| author | Zeyla Hellyer <[email protected]> | 2017-12-16 08:39:36 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-12-16 08:45:26 -0800 |
| commit | bcd16dddb8cc3086a13524c79676f3a8bebbc524 (patch) | |
| tree | 42d254fb4738df957c4b7d9e5766d1cb5bd47323 /src/model/guild/mod.rs | |
| parent | Fix guild deserialization tests (diff) | |
| download | serenity-bcd16dddb8cc3086a13524c79676f3a8bebbc524.tar.xz serenity-bcd16dddb8cc3086a13524c79676f3a8bebbc524.zip | |
Break up the model module
The `model` module has historically been one giant module re-exporting
all of the model types, which is somewhere around 100 types. This can be
a lot to look at for a new user and somewhat overwhelming, especially
with a large number of fine-grained imports from the module.
The module is now neatly split up into submodules, mostly like it has
been internally since the early versions of the library. The submodules
are:
- application
- channel
- error
- event
- gateway
- guild
- id
- invite
- misc
- permissions
- prelude
- user
- voice
- webhook
Each submodule contains types that are "owned" by the module. For
example, the `guild` submodule contains, but not limited to, Emoji,
AuditLogsEntry, Role, and Member. `channel` contains, but not limited
to, Attachment, Embed, Message, and Reaction.
Upgrade path:
Instead of glob importing the models via `use serenity::model::*;`,
instead glob import via the prelude:
```rust
use serenity::model::prelude::*;
```
Instead of importing from the root model module:
```rust
use serenity::model::{Guild, Message, OnlineStatus, Role, User};
```
instead import from the submodules like so:
```rust
use serenity::model::channel::Message;
use serenity::model::guild::{Guild, Role};
use serenity::model::user::{OnlineStatus, User};
```
Diffstat (limited to 'src/model/guild/mod.rs')
| -rw-r--r-- | src/model/guild/mod.rs | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 32b5ee2..d6a2c50 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -1,3 +1,5 @@ +//! Models relating to guilds and types that it owns. + mod emoji; mod guild_id; mod integration; @@ -15,7 +17,7 @@ pub use self::role::*; pub use self::audit_log::*; use chrono::{DateTime, FixedOffset}; -use model::*; +use model::prelude::*; use serde::de::Error as DeError; use serde_json; use super::utils::*; @@ -1363,7 +1365,7 @@ impl Guild { /// Obtain a reference to a [`Role`] by its name. /// /// ```rust,no_run - /// use serenity::model::*; + /// use serenity::model::prelude::*; /// use serenity::prelude::*; /// /// struct Handler; @@ -1583,6 +1585,19 @@ fn closest_to_origin(origin: &str, word_a: &str, word_b: &str) -> std::cmp::Orde value_a.cmp(&value_b) } +/// A container for guilds. +/// +/// This is used to differentiate whether a guild itself can be used or whether +/// a guild needs to be retrieved from the cache. +#[allow(large_enum_variant)] +#[derive(Clone, Debug)] +pub enum GuildContainer { + /// A guild which can have its contents directly searched. + Guild(PartialGuild), + /// A guild's id, which can be used to search the cache for a guild. + Id(GuildId), +} + /// Information relating to a guild's widget embed. #[derive(Clone, Copy, Debug, Deserialize)] pub struct GuildEmbed { @@ -1747,6 +1762,46 @@ impl MfaLevel { } } +/// The name of a region that a voice server can be located in. +#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize)] +pub enum Region { + #[serde(rename = "amsterdam")] Amsterdam, + #[serde(rename = "brazil")] Brazil, + #[serde(rename = "eu-central")] EuCentral, + #[serde(rename = "eu-west")] EuWest, + #[serde(rename = "frankfurt")] Frankfurt, + #[serde(rename = "london")] London, + #[serde(rename = "sydney")] Sydney, + #[serde(rename = "us-central")] UsCentral, + #[serde(rename = "us-east")] UsEast, + #[serde(rename = "us-south")] UsSouth, + #[serde(rename = "us-west")] UsWest, + #[serde(rename = "vip-amsterdam")] VipAmsterdam, + #[serde(rename = "vip-us-east")] VipUsEast, + #[serde(rename = "vip-us-west")] VipUsWest, +} + +impl Region { + pub fn name(&self) -> &str { + match *self { + Region::Amsterdam => "amsterdam", + Region::Brazil => "brazil", + Region::EuCentral => "eu-central", + Region::EuWest => "eu-west", + Region::Frankfurt => "frankfurt", + Region::London => "london", + Region::Sydney => "sydney", + Region::UsCentral => "us-central", + Region::UsEast => "us-east", + Region::UsSouth => "us-south", + Region::UsWest => "us-west", + Region::VipAmsterdam => "vip-amsterdam", + Region::VipUsEast => "vip-us-east", + Region::VipUsWest => "vip-us-west", + } + } +} + enum_number!( #[doc="The level to set as criteria prior to a user being able to send messages in a [`Guild`]. |