aboutsummaryrefslogtreecommitdiff
path: root/src/cache
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-11-04 20:06:40 +0100
committeracdenisSK <[email protected]>2017-11-04 20:06:40 +0100
commit0bd519f4ef9784d0fb5663d74db0d567f0bb1ae5 (patch)
treecc2a6f44e97e42420507964dab4662fcccd9beb3 /src/cache
parentFix Help-Commands to list all eligible commands in DMs. (#212) (diff)
parentBump to v0.4.3 (diff)
downloadserenity-0bd519f4ef9784d0fb5663d74db0d567f0bb1ae5.tar.xz
serenity-0bd519f4ef9784d0fb5663d74db0d567f0bb1ae5.zip
Merge v0.4.3
Diffstat (limited to 'src/cache')
-rw-r--r--src/cache/mod.rs62
1 files changed, 44 insertions, 18 deletions
diff --git a/src/cache/mod.rs b/src/cache/mod.rs
index 730d169..e23e17e 100644
--- a/src/cache/mod.rs
+++ b/src/cache/mod.rs
@@ -171,7 +171,9 @@ impl Cache {
/// # use serenity::prelude::*;
/// # use serenity::model::*;
/// #
- /// use serenity::client::CACHE;
+ /// # #[cfg(feature = "client")]
+ /// # fn main() {
+ /// use serenity::CACHE;
/// use std::thread;
/// use std::time::Duration;
///
@@ -194,9 +196,13 @@ impl Cache {
/// }
/// }
///
- /// let mut client = Client::new("token", Handler).unwrap();
- ///
+ /// let mut client = Client::new("token", Handler).unwrap();
+ ///
/// client.start().unwrap();
+ /// # }
+ /// #
+ /// # #[cfg(not(feature = "client"))]
+ /// # fn main() { }
/// ```
///
/// [`Member`]: ../model/struct.Member.html
@@ -229,7 +235,7 @@ impl Cache {
/// Printing the count of all private channels and groups:
///
/// ```rust,no_run
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// let amount = CACHE.read().all_private_channels().len();
///
@@ -256,18 +262,26 @@ impl Cache {
/// Print all of the Ids of guilds in the Cache:
///
/// ```rust,no_run
+ /// # #[cfg(feature = "client")]
+ /// # fn main() {
/// # use serenity::prelude::*;
/// # use serenity::model::*;
/// #
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// struct Handler;
+ ///
/// impl EventHandler for Handler {
- /// fn ready(&self, _: Context, _: Ready) {
- /// println!("Guilds in the Cache: {:?}", CACHE.read().all_guilds());
+ /// fn on_ready(&self, _: Context, _: Ready) {
+ /// let guilds = CACHE.read().unwrap().guilds.len();
+ ///
+ /// println!("Guilds in the Cache: {}", guilds);
/// }
/// }
- /// let mut client = Client::new("token", Handler);
+ /// # }
+ /// #
+ /// # #[cfg(not(feature = "client"))]
+ /// # fn main() { }
/// ```
///
/// [`Context`]: ../client/struct.Context.html
@@ -334,7 +348,7 @@ impl Cache {
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// if let Some(guild) = CACHE.read().guild(7) {
/// println!("Guild name: {}", guild.read().name);
@@ -363,10 +377,12 @@ impl Cache {
/// [`Client::on_message`] event dispatch:
///
/// ```rust,no_run
+ /// # #[cfg(feature = "client")]
+ /// # fn main() {
/// # use serenity::prelude::*;
/// # use serenity::model::*;
/// #
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// struct Handler;
///
@@ -389,8 +405,12 @@ impl Cache {
/// }
///
/// let mut client = Client::new("token", Handler).unwrap();
- ///
+ ///
/// client.start().unwrap();
+ /// # }
+ /// #
+ /// # #[cfg(not(feature = "client"))]
+ /// # fn main() { }
/// ```
///
/// [`ChannelId`]: ../model/struct.ChannelId.html
@@ -419,7 +439,7 @@ impl Cache {
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// if let Some(group) = CACHE.read().group(7) {
/// println!("Owner Id: {}", group.read().owner_id);
@@ -496,16 +516,22 @@ impl Cache {
///
/// # Examples
///
- /// Retrieve a private channel from the cache and send a message:
+ /// Retrieve a private channel from the cache and print its recipient's
+ /// name:
///
/// ```rust,no_run
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
+ ///
+ /// let cache = CACHE.read()?;
///
- /// if let Some(channel) = CACHE.read().private_channel(7) {
- /// channel.read().say("Hello there!");
+ /// if let Some(channel) = cache.private_channel(7) {
+ /// let channel_reader = channel.read().unwrap();
+ /// let user_reader = channel_reader.recipient.read().unwrap();
+ ///
+ /// println!("The recipient is {}", user_reader.name);
/// }
/// # Ok(())
/// # }
@@ -537,7 +563,7 @@ impl Cache {
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// if let Some(role) = CACHE.read().role(7, 77) {
/// println!("Role with Id 77 is called {}", role.name);
@@ -572,7 +598,7 @@ impl Cache {
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// if let Some(user) = CACHE.read().user(7) {
/// println!("User with Id 7 is currently named {}", user.read().name);