aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-05-30 22:27:32 -0500
committerZeyla Hellyer <[email protected]>2017-05-30 20:27:32 -0700
commit921f7f42d87e7c727b5a87802d7738f8081b600a (patch)
treebef042679b0c46d528a14ea20af9d15388967403 /src
parentAdd _line + _line_safe methods to MessageBuilder (diff)
downloadserenity-921f7f42d87e7c727b5a87802d7738f8081b600a.tar.xz
serenity-921f7f42d87e7c727b5a87802d7738f8081b600a.zip
Add docs for CurrentUser
Diffstat (limited to 'src')
-rw-r--r--src/model/user.rs103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/model/user.rs b/src/model/user.rs
index f356d5d..e590a6f 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -36,6 +36,24 @@ impl CurrentUser {
/// Returns the formatted URL of the user's icon, if one exists.
///
/// This will produce a WEBP image URL, or GIF if the user has a GIF avatar.
+ ///
+ /// # Examples
+ ///
+ /// Print out the current user's avatar url if one is set:
+ ///
+ /// ```rust,no_run
+ /// # use serenity::client::CACHE;
+ /// #
+ /// # let cache = CACHE.read().unwrap();
+ /// #
+ /// // assuming the cache has been unlocked
+ /// let user = &cache.user;
+ ///
+ /// match user.avatar_url() {
+ /// Some(url) => println!("{}'s avatar can be found at {}", user.name, url),
+ /// None => println!("{} does not have an avatar set.", user.name)
+ /// }
+ /// ```
pub fn avatar_url(&self) -> Option<String> {
self.avatar.as_ref()
.map(|av| {
@@ -50,6 +68,19 @@ impl CurrentUser {
}
/// Returns the DiscordTag of a User.
+ ///
+ /// # Examples
+ ///
+ /// Print out the current user's distinct identifier (i.e., Username#1234):
+ ///
+ /// ```rust,no_run
+ /// # use serenity::client::CACHE;
+ /// #
+ /// # let cache = CACHE.read().unwrap();
+ /// #
+ /// // assuming the cache has been unlocked
+ /// println!("Current user's distinct identifier is {}", cache.user.distinct());
+ /// ```
#[inline]
pub fn distinct(&self) -> String {
format!("{}#{}", self.name, self.discriminator)
@@ -92,6 +123,25 @@ impl CurrentUser {
}
/// Gets a list of guilds that the current user is in.
+ ///
+ /// # Examples
+ ///
+ /// Print out the names of all guilds the current user is in:
+ ///
+ /// ```rust,no_run
+ /// # use serenity::client::CACHE;
+ /// #
+ /// # let cache = CACHE.read().unwrap();
+ /// #
+ /// // assuming the cache has been unlocked
+ /// let user = &cache.user;
+ ///
+ /// if let Ok(guilds) = user.guilds() {
+ /// for (index, guild) in guilds.into_iter().enumerate() {
+ /// println!("{}: {}", index, guild.name);
+ /// }
+ /// }
+ /// ```
pub fn guilds(&self) -> Result<Vec<GuildInfo>> {
http::get_guilds(&GuildPagination::After(GuildId(1)), 100)
}
@@ -99,6 +149,24 @@ impl CurrentUser {
/// Returns a static formatted URL of the user's icon, if one exists.
///
/// This will always produce a WEBP image URL.
+ ///
+ /// # Examples
+ ///
+ /// Print out the current user's static avatar url if one is set:
+ ///
+ /// ```rust,no_run
+ /// # use serenity::client::CACHE;
+ /// #
+ /// # let cache = CACHE.read().unwrap();
+ /// #
+ /// // assuming the cache has been unlocked
+ /// let user = &cache.user;
+ ///
+ /// match user.static_avatar_url() {
+ /// Some(url) => println!("{}'s static avatar can be found at {}", user.name, url),
+ /// None => println!("Could not get static avatar for {}.", user.name)
+ /// }
+ /// ```
pub fn static_avatar_url(&self) -> Option<String> {
self.avatar.as_ref()
.map(|av| format!(cdn!("/avatars/{}/{}.webp?size=1024"), self.id.0, av))
@@ -107,8 +175,43 @@ impl CurrentUser {
/// Returns the invite url for the bot with the given permissions.
///
/// If the permissions passed are empty, the permissions part will be dropped.
+ ///
+ /// # Examples
+ ///
+ /// Get the invite url with no permissions set:
+ ///
+ /// ```rust
+ /// # use serenity::client::CACHE;
+ /// #
+ /// # let mut cache = CACHE.write().unwrap();
+ /// # cache.user.id.0 = 249608697955745802;
+ /// #
+ /// use serenity::model::permissions::Permissions;
+ ///
+ /// // assuming the cache has been unlocked
+ /// let url = cache.user.invite_url(Permissions::empty());
+ ///
+ /// assert_eq!(url, "https://discordapp.com/api/oauth2/authorize?client_id=249608697955745802&scope=bot");
+ /// ```
+ ///
+ /// Get the invite url with some basic permissions set:
+ ///
+ /// ```rust
+ /// # use serenity::client::CACHE;
+ /// #
+ /// # let mut cache = CACHE.write().unwrap();
+ /// # cache.user.id.0 = 249608697955745802;
+ /// #
+ /// use serenity::model::permissions::*;
+ ///
+ /// // assuming the cache has been unlocked
+ /// let url = cache.user.invite_url(READ_MESSAGES | SEND_MESSAGES | EMBED_LINKS);
+ ///
+ /// assert_eq!(url, "https://discordapp.com/api/oauth2/authorize?client_id=249608697955745802&scope=bot&permissions=19456");
+ /// ```
pub fn invite_url(&self, permissions: Permissions) -> String {
let bits = permissions.bits();
+
if bits == 0 {
format!("https://discordapp.com/api/oauth2/authorize?client_id={}&scope=bot", self.id)
} else {