aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-22 07:57:51 -0800
committerAustin Hellyer <[email protected]>2016-11-22 07:57:51 -0800
commitd4726f899cf6b86d805a8a2a77ec57782ec3bdd6 (patch)
tree7966be3c6d6c4284bb618b88b3f146dd412af677 /src/model
parentDon't typo CreateEmbed::image field (diff)
downloadserenity-d4726f899cf6b86d805a8a2a77ec57782ec3bdd6.tar.xz
serenity-d4726f899cf6b86d805a8a2a77ec57782ec3bdd6.zip
Rename the State to Cache
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel.rs16
-rw-r--r--src/model/gateway.rs4
-rw-r--r--src/model/guild.rs30
-rw-r--r--src/model/id.rs18
-rw-r--r--src/model/invite.rs16
-rw-r--r--src/model/mod.rs4
-rw-r--r--src/model/user.rs22
-rw-r--r--src/model/utils.rs14
8 files changed, 62 insertions, 62 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index ddbd565..0513966 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -31,7 +31,7 @@ use super::utils;
#[cfg(feature = "methods")]
use ::utils::builder::{CreateEmbed, CreateInvite, EditChannel};
#[cfg(feature = "methods")]
-use ::client::{STATE, http};
+use ::client::{CACHE, http};
impl Attachment {
/// If this attachment is an image, then a tuple of the width and height
@@ -436,7 +436,7 @@ impl Message {
#[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
let req = permissions::MANAGE_MESSAGES;
- let is_author = self.author.id != STATE.lock().unwrap().user.id;
+ let is_author = self.author.id != CACHE.lock().unwrap().user.id;
if is_author {
return Err(Error::Client(ClientError::InvalidUser));
@@ -503,7 +503,7 @@ impl Message {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
}
- if self.author.id != STATE.lock().unwrap().user.id {
+ if self.author.id != CACHE.lock().unwrap().user.id {
return Err(Error::Client(ClientError::InvalidUser));
}
@@ -720,7 +720,7 @@ impl PrivateChannel {
/// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
#[cfg(feature = "methods")]
pub fn delete_messages(&self, message_ids: &[MessageId]) -> Result<()> {
- if !STATE.lock().unwrap().user.bot {
+ if !CACHE.lock().unwrap().user.bot {
return Err(Error::Client(ClientError::InvalidOperationAsUser));
}
@@ -883,13 +883,13 @@ impl PublicChannel {
}
}
- /// Attempts to find this channel's guild in the State.
+ /// Attempts to find this channel's guild in the Cache.
///
/// **Note**: Right now this performs a clone of the guild. This will be
/// optimized in the future.
- #[cfg(all(feature = "methods", feature = "state"))]
+ #[cfg(all(feature = "cache", feature = "methods"))]
pub fn guild(&self) -> Option<LiveGuild> {
- STATE.lock().unwrap().get_guild(self.guild_id).cloned()
+ CACHE.lock().unwrap().get_guild(self.guild_id).cloned()
}
/// Return a [`Mention`] which will link to this channel.
@@ -978,7 +978,7 @@ impl Reaction {
/// [permissions]: permissions
#[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
- let user = if self.user_id == STATE.lock().unwrap().user.id {
+ let user = if self.user_id == CACHE.lock().unwrap().user.id {
None
} else {
Some(self.user_id.0)
diff --git a/src/model/gateway.rs b/src/model/gateway.rs
index 5fdfdfe..113bb2f 100644
--- a/src/model/gateway.rs
+++ b/src/model/gateway.rs
@@ -239,7 +239,7 @@ pub struct ReactionRemoveAllEvent {
pub message_id: MessageId,
}
-/// The "Ready" event, containing initial state
+/// The "Ready" event, containing initial ready cache
#[derive(Clone, Debug)]
pub struct ReadyEvent {
pub ready: Ready,
@@ -440,7 +440,7 @@ pub enum Event {
/// [`Reaction`]: struct.Reaction.html
/// [`on_reaction_remove_all`]: ../client/struct.Clint.html#method.on_reaction_remove_all
ReactionRemoveAll(ReactionRemoveAllEvent),
- /// The first event in a connection, containing the initial state.
+ /// The first event in a connection, containing the initial ready cache.
///
/// May also be received at a later time in the event of a reconnect.
Ready(ReadyEvent),
diff --git a/src/model/guild.rs b/src/model/guild.rs
index 1c4ffe4..704a93b 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -25,8 +25,8 @@ use ::utils::builder::{EditGuild, EditMember, EditRole};
#[cfg(feature = "methods")]
use ::client::http;
-#[cfg(feature = "state")]
-use ::client::STATE;
+#[cfg(feature = "cache")]
+use ::client::CACHE;
impl From<Guild> for GuildContainer {
fn from(guild: Guild) -> GuildContainer {
@@ -47,12 +47,12 @@ impl From<u64> for GuildContainer {
}
impl Emoji {
- /// Finds the [`Guild`] that owns the emoji by looking through the state.
+ /// Finds the [`Guild`] that owns the emoji by looking through the Cache.
///
/// [`Guild`]: struct.Guild.html
#[cfg(feature = "methods")]
pub fn find_guild_id(&self) -> Option<GuildId> {
- STATE.lock()
+ CACHE.lock()
.unwrap()
.guilds
.values()
@@ -165,9 +165,9 @@ impl Guild {
}
impl LiveGuild {
- #[cfg(feature = "state")]
+ #[cfg(feature = "cache")]
fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
- let member = match self.get_member(STATE.lock().unwrap().user.id) {
+ let member = match self.get_member(CACHE.lock().unwrap().user.id) {
Some(member) => member,
None => return Err(Error::Client(ClientError::ItemMissing)),
};
@@ -179,7 +179,7 @@ impl LiveGuild {
Ok(permissions.is_empty())
}
- #[cfg(not(feature = "state"))]
+ #[cfg(not(feature = "cache"))]
fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
Ok(true)
}
@@ -379,7 +379,7 @@ impl LiveGuild {
/// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
#[cfg(feature = "methods")]
pub fn delete(&self) -> Result<Guild> {
- if self.owner_id != STATE.lock().unwrap().user.id {
+ if self.owner_id != CACHE.lock().unwrap().user.id {
let req = permissions::MANAGE_GUILD;
return Err(Error::Client(ClientError::InvalidPermissions(req)));
@@ -856,7 +856,7 @@ impl Member {
/// [`Guild`]: struct.Guild.html
#[cfg(feature = "methods")]
pub fn find_guild(&self) -> Result<GuildId> {
- STATE.lock()
+ CACHE.lock()
.unwrap()
.guilds
.values()
@@ -926,12 +926,12 @@ impl Member {
/// Retrieves the full role data for the user's roles.
///
- /// This is shorthand for manually searching through the state.
+ /// This is shorthand for manually searching through the CACHE.
///
/// If role data can not be found for the member, then `None` is returned.
- #[cfg(all(feature = "methods", feature = "state"))]
+ #[cfg(all(feature = "cache", feature = "methods"))]
pub fn roles(&self) -> Option<Vec<Role>> {
- STATE.lock().unwrap()
+ CACHE.lock().unwrap()
.guilds
.values()
.find(|g| g.members
@@ -1018,17 +1018,17 @@ impl Role {
http::delete_role(guild_id.0, self.id.0)
}
- /// Searches the state for the guild that owns the role.
+ /// Searches the cache for the guild that owns the role.
///
/// # Errors
///
- /// Returns a [`ClientError::GuildNotFound`] if a guild is not in the state
+ /// Returns a [`ClientError::GuildNotFound`] if a guild is not in the cache
/// that contains the role.
///
/// [`ClientError::GuildNotFound`]: ../client/enum.ClientError.html#variant.GuildNotFound
#[cfg(feature = "methods")]
pub fn find_guild(&self) -> Result<GuildId> {
- STATE.lock()
+ CACHE.lock()
.unwrap()
.guilds
.values()
diff --git a/src/model/id.rs b/src/model/id.rs
index 8c94dec..f055784 100644
--- a/src/model/id.rs
+++ b/src/model/id.rs
@@ -1,22 +1,22 @@
use super::*;
#[cfg(feature = "methods")]
-use ::client::{STATE, http};
+use ::client::{CACHE, http};
#[cfg(feature = "methods")]
use ::internal::prelude::*;
impl ChannelId {
- /// Search the state for the channel with the Id.
+ /// Search the cache for the channel with the Id.
#[cfg(feature="methods")]
pub fn find(&self) -> Option<Channel> {
- STATE.lock().unwrap().get_channel(*self)
+ CACHE.lock().unwrap().get_channel(*self)
}
- /// Search the state for the channel. If it can't be found, the channel is
+ /// Search the cache for the channel. If it can't be found, the channel is
/// requested over REST.
#[cfg(feature="methods")]
pub fn get(&self) -> Result<Channel> {
- if let Some(channel) = STATE.lock().unwrap().get_channel(*self) {
+ if let Some(channel) = CACHE.lock().unwrap().get_channel(*self) {
return Ok(channel.clone());
}
@@ -74,10 +74,10 @@ impl From<Emoji> for EmojiId {
}
impl GuildId {
- /// Search the state for the guild.
+ /// Search the cache for the guild.
#[cfg(feature="methods")]
pub fn find(&self) -> Option<LiveGuild> {
- STATE.lock().unwrap().get_guild(*self).cloned()
+ CACHE.lock().unwrap().get_guild(*self).cloned()
}
/// Requests the guild over REST.
@@ -160,10 +160,10 @@ impl From<Role> for RoleId {
}
impl RoleId {
- /// Search the state for the role.
+ /// Search the cache for the role.
#[cfg(feature="methods")]
pub fn find(&self) -> Option<Role> {
- STATE.lock()
+ CACHE.lock()
.unwrap()
.guilds
.values()
diff --git a/src/model/invite.rs b/src/model/invite.rs
index 58773d1..6552783 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -3,8 +3,8 @@ use ::client::http;
use ::internal::prelude::*;
use super::{permissions, utils};
-#[cfg(feature = "state")]
-use ::client::STATE;
+#[cfg(feature = "cache")]
+use ::client::CACHE;
impl Invite {
/// Accepts the invite, placing the current user in the [`Guild`] that the
@@ -19,7 +19,7 @@ impl Invite {
///
/// # Errors
///
- /// If the `state` features is enabled, then this returns a
+ /// If the `cache` features is enabled, then this returns a
/// [`ClientError::InvalidOperationAsBot`] if the current user does not have
/// the required [permission].
///
@@ -29,8 +29,8 @@ impl Invite {
/// [permission]: permissions/index.html
#[cfg(feature="methods")]
pub fn accept(&self) -> Result<Invite> {
- feature_state_enabled! {{
- if STATE.lock().unwrap().user.bot {
+ feature_cache_enabled! {{
+ if CACHE.lock().unwrap().user.bot {
return Err(Error::Client(ClientError::InvalidOperationAsBot));
}
}}
@@ -83,8 +83,8 @@ impl RichInvite {
/// [`http::accept_invite`]: ../client/http/fn.accept_invite.html
#[cfg(feature="methods")]
pub fn accept(&self) -> Result<Invite> {
- feature_state_enabled! {{
- if STATE.lock().unwrap().user.bot {
+ feature_cache_enabled! {{
+ if CACHE.lock().unwrap().user.bot {
return Err(Error::Client(ClientError::InvalidOperationAsBot));
}
}}
@@ -100,7 +100,7 @@ impl RichInvite {
///
/// # Errors
///
- /// If the `state` feature is enabled, then this returns a
+ /// If the `cache` feature is enabled, then this returns a
/// [`ClientError::InvalidPermissions`] if the current user does not have
/// the required [permission].
///
diff --git a/src/model/mod.rs b/src/model/mod.rs
index 26041a9..7f8a6ea 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -138,11 +138,11 @@ pub enum Channel {
/// 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 state.
+/// a guild needs to be retrieved from the cache.
pub enum GuildContainer {
/// A guild which can have its contents directly searched.
Guild(Guild),
- /// A guild's id, which can be used to search the state for a guild.
+ /// A guild's id, which can be used to search the cache for a guild.
Id(GuildId),
}
diff --git a/src/model/user.rs b/src/model/user.rs
index 412d1ae..9e4c457 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -22,8 +22,8 @@ use time::Timespec;
#[cfg(feature = "methods")]
use ::client::http;
-#[cfg(feature = "state")]
-use ::client::STATE;
+#[cfg(feature = "cache")]
+use ::client::CACHE;
impl CurrentUser {
/// Returns the formatted URL of the user's icon, if one exists.
@@ -56,13 +56,13 @@ impl User {
}
/// Send a direct message to a user. This will create or retrieve the
- /// PrivateChannel over REST if one is not already in the State, and then
+ /// PrivateChannel over REST if one is not already in the cache, and then
/// send a message to it.
#[cfg(feature="methods")]
pub fn direct_message(&self, content: &str)
-> Result<Message> {
let private_channel_id = {
- let finding = STATE.lock()
+ let finding = CACHE.lock()
.unwrap()
.private_channels
.values()
@@ -90,11 +90,11 @@ impl User {
}
/// Check if a user has a [`Role`]. This will retrieve the
- /// [`Guild`] from the [`State`] if
- /// it is available, and then check if that guild has the given [`Role`].
+ /// [`Guild`] from the [`Cache`] if it is available, and then check if that
+ /// guild has the given [`Role`].
///
/// If the [`Guild`] is not present, then the guild will be retrieved from
- /// the API and the state will be updated with it.
+ /// the API and the cache will be updated with it.
///
/// If there are issues with requesting the API, then `false` will be
/// returned.
@@ -114,7 +114,7 @@ impl User {
/// [`Guild`]: struct.Guild.html
/// [`GuildId`]: struct.GuildId.html
/// [`Role`]: struct.Role.html
- /// [`State`]: ../ext/state/struct.State.html
+ /// [`Cache`]: ../ext/cache/struct.Cache.html
pub fn has_role<G, R>(&self, guild: G, role: R) -> bool
where G: Into<GuildContainer>, R: Into<RoleId> {
let role_id = role.into();
@@ -124,10 +124,10 @@ impl User {
guild.roles.get(&role_id).is_some()
},
GuildContainer::Id(guild_id) => {
- feature_state! {{
- let state = STATE.lock().unwrap();
+ feature_cache! {{
+ let cache = CACHE.lock().unwrap();
- state.get_role(guild_id, role_id).is_some()
+ cache.get_role(guild_id, role_id).is_some()
} else {
true
}}
diff --git a/src/model/utils.rs b/src/model/utils.rs
index db39939..60fa892 100644
--- a/src/model/utils.rs
+++ b/src/model/utils.rs
@@ -19,8 +19,8 @@ use ::utils::{decode_array, into_array};
#[cfg(feature = "methods")]
use super::permissions::{self, Permissions};
-#[cfg(feature = "methods")]
-use ::client::STATE;
+#[cfg(all(feature = "cache", feature = "methods"))]
+use ::client::CACHE;
#[macro_escape]
macro_rules! missing {
@@ -271,14 +271,14 @@ pub fn remove(map: &mut BTreeMap<String, Value>, key: &str) -> Result<Value> {
}
#[doc(hidden)]
-#[cfg(feature="methods")]
+#[cfg(all(feature = "cache", feature="methods"))]
pub fn user_has_perms(channel_id: ChannelId,
mut permissions: Permissions)
-> Result<bool> {
- let state = STATE.lock().unwrap();
- let current_user = &state.user;
+ let cache = CACHE.lock().unwrap();
+ let current_user = &cache.user;
- let channel = match state.get_channel(channel_id) {
+ let channel = match cache.get_channel(channel_id) {
Some(channel) => channel,
None => return Err(Error::Client(ClientError::ItemMissing)),
};
@@ -290,7 +290,7 @@ pub fn user_has_perms(channel_id: ChannelId,
Channel::Public(channel) => channel.guild_id,
};
- let guild = match state.get_guild(guild_id) {
+ let guild = match cache.get_guild(guild_id) {
Some(guild) => guild,
None => return Err(Error::Client(ClientError::ItemMissing)),
};