From 9b4e9390b956fbcaadab34f4d318822e54b54984 Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Tue, 3 Jan 2017 19:40:26 -0800 Subject: Add Context::get_user --- src/client/context.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') 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>(&self, user_id: U) -> Result { + #[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. -- cgit v1.2.3