aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2017-01-03 19:40:26 -0800
committerAustin Hellyer <[email protected]>2017-01-04 11:58:34 -0800
commit9b4e9390b956fbcaadab34f4d318822e54b54984 (patch)
treee1df4568f935f836b805d1d116fc5198247b2b72 /src
parentReturn a User from rest::get_user (diff)
downloadserenity-9b4e9390b956fbcaadab34f4d318822e54b54984.tar.xz
serenity-9b4e9390b956fbcaadab34f4d318822e54b54984.zip
Add Context::get_user
Diffstat (limited to 'src')
-rw-r--r--src/client/context.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index ccf05fc..0acc960 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -1335,6 +1335,28 @@ impl Context {
after.map(|u| u.into().0))
}
+ /// Gets a [`User`] by its Id.
+ ///
+ /// [`User`]: ../model/struct.User.html
+ ///
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidOperationAsUser`] if the current user is
+ /// not a bot user.
+ ///
+ /// [`ClientError::InvalidOperationAsUser`]: enum.ClientError.html#variant.InvalidOperationAsUser
+ #[inline]
+ pub fn get_user<U: Into<UserId>>(&self, user_id: U) -> Result<User> {
+ #[cfg(feature="cache")]
+ {
+ if !CACHE.read().unwrap().user.bot {
+ return Err(Error::Client(ClientError::InvalidOperationAsUser));
+ }
+ }
+
+ rest::get_user(user_id.into().0)
+ }
+
/// Kicks a [`Member`] from the specified [`Guild`] if they are in it.
///
/// Requires the [Kick Members] permission.