diff options
| author | Austin Hellyer <[email protected]> | 2016-11-22 07:57:51 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-22 07:57:51 -0800 |
| commit | d4726f899cf6b86d805a8a2a77ec57782ec3bdd6 (patch) | |
| tree | 7966be3c6d6c4284bb618b88b3f146dd412af677 /src/client/context.rs | |
| parent | Don't typo CreateEmbed::image field (diff) | |
| download | serenity-d4726f899cf6b86d805a8a2a77ec57782ec3bdd6.tar.xz serenity-d4726f899cf6b86d805a8a2a77ec57782ec3bdd6.zip | |
Rename the State to Cache
Diffstat (limited to 'src/client/context.rs')
| -rw-r--r-- | src/client/context.rs | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index 04f08e0..67c0146 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -20,8 +20,8 @@ use ::internal::prelude::*; use ::model::*; use ::utils; -#[cfg(feature = "state")] -use super::STATE; +#[cfg(feature = "cache")] +use super::CACHE; /// The context is a general utility struct provided on event dispatches, which /// helps with dealing with the current "context" of the event dispatch, @@ -41,12 +41,12 @@ use super::STATE; /// A context will only live for the event it was dispatched for. After the /// event handler finished, it is destroyed and will not be re-used. /// -/// # Automatically using the State +/// # Automatically using the Cache /// -/// The context makes use of the [`State`] being global, and will first check -/// the state for associated data before hitting the REST API. This is to save +/// The context makes use of the [`Cache`] being global, and will first check +/// the cache for associated data before hitting the REST API. This is to save /// Discord requests, and ultimately save your bot bandwidth and time. This also -/// acts as a clean interface for retrieving from the state without needing to +/// acts as a clean interface for retrieving from the cache without needing to /// check it yourself first, and then performing a request if it does not exist. /// The context ultimately acts as a means to simplify these two operations into /// one. @@ -54,13 +54,13 @@ use super::STATE; /// For example, if you are needing information about a /// [channel][`PublicChannel`] within a [guild][`LiveGuild`], then you can /// use [`get_channel`] to retrieve it. Under most circumstances, the guild and -/// its channels will be cached within the state, and `get_channel` will just -/// pull from the state. If it does not exist, it will make a request to the -/// REST API, and then insert a clone of the channel into the state, returning +/// its channels will be cached within the cache, and `get_channel` will just +/// pull from the cache. If it does not exist, it will make a request to the +/// REST API, and then insert a clone of the channel into the cache, returning /// you the channel. /// -/// In this scenario, now that the state has the channel, performing the same -/// request to `get_channel` will instead pull from the state, as it is now +/// In this scenario, now that the cache has the channel, performing the same +/// request to `get_channel` will instead pull from the cache, as it is now /// cached. /// /// [`Channel`]: ../model/enum.Channel.html @@ -69,7 +69,7 @@ use super::STATE; /// [`Message`]: ../model/struct.Message.html /// [`PublicChannel`]: ../model/struct.PublicChannel.html /// [`Shard`]: gateway/struct.Shard.html -/// [`State`]: ../ext/state/struct.State.html +/// [`Cache`]: ../ext/cache/struct.Cache.html /// [`get_channel`]: #method.get_channel /// [`http`]: http/index.html /// [`say`]: #method.say @@ -761,11 +761,11 @@ impl Context { let guild_id = guild_id.into(); let role_id = role_id.into(); - feature_state! {{ - let state = STATE.lock().unwrap(); + feature_cache! {{ + let cache = CACHE.lock().unwrap(); let role = if let Some(role) = { - state.get_role(guild_id.0, role_id.0) + cache.get_role(guild_id.0, role_id.0) } { role } else { @@ -824,8 +824,8 @@ impl Context { where C: Into<ChannelId> { let channel_id = channel_id.into(); - feature_state_enabled! {{ - if let Some(channel) = STATE.lock().unwrap().get_channel(channel_id) { + feature_cache_enabled! {{ + if let Some(channel) = CACHE.lock().unwrap().get_channel(channel_id) { return Ok(channel.clone()); } }} @@ -837,10 +837,10 @@ impl Context { -> Result<HashMap<ChannelId, PublicChannel>> where G: Into<GuildId> { let guild_id = guild_id.into(); - feature_state_enabled! {{ - let state = STATE.lock().unwrap(); + feature_cache_enabled! {{ + let cache = CACHE.lock().unwrap(); - if let Some(guild) = state.get_guild(guild_id) { + if let Some(guild) = cache.get_guild(guild_id) { return Ok(guild.channels.clone()); } }} @@ -902,10 +902,10 @@ impl Context { let guild_id = guild_id.into(); let user_id = user_id.into(); - feature_state_enabled! {{ - let state = STATE.lock().unwrap(); + feature_cache_enabled! {{ + let cache = CACHE.lock().unwrap(); - if let Some(member) = state.get_member(guild_id, user_id) { + if let Some(member) = cache.get_member(guild_id, user_id) { return Ok(member.clone()); } }} @@ -1132,7 +1132,7 @@ impl Context { /// information was generated by them. /// /// ```rust,no_run - /// use serenity::client::{STATE, Client, Context}; + /// use serenity::client::{CACHE, Client, Context}; /// use serenity::model::{Channel, Message}; /// use serenity::utils::Colour; /// use std::env; @@ -1149,8 +1149,8 @@ impl Context { /// let _ = client.start(); /// /// fn ping(context: Context, message: Message, _arguments: Vec<String>) { - /// let state = STATE.lock().unwrap(); - /// let ch = state.get_channel(message.channel_id); + /// let cache = CACHE.lock().unwrap(); + /// let ch = cache.get_channel(message.channel_id); /// let name = match ch { /// Some(Channel::Public(ch)) => ch.name.clone(), /// _ => "Unknown".to_owned(), @@ -1181,9 +1181,9 @@ impl Context { /// .name("Channel name:") /// .value(&name)) /// .footer(|mut f| { - /// f = f.text(&format!("Generated by {}", state.user.name)); + /// f = f.text(&format!("Generated by {}", cache.user.name)); /// - /// if let Some(avatar) = state.user.avatar_url() { + /// if let Some(avatar) = cache.user.avatar_url() { /// f = f.icon_url(&avatar); /// } /// |