diff options
| author | Illia <[email protected]> | 2016-12-10 22:25:55 +0200 |
|---|---|---|
| committer | zeyla <[email protected]> | 2016-12-10 12:25:55 -0800 |
| commit | e44838f4339b90817b5eba5df16230b02487f0cc (patch) | |
| tree | 8513ab3d9d3f9c8826f85630524cca1e4a7e188d /src/model/user.rs | |
| parent | Fix no-cache+method conditional compiles (diff) | |
| download | serenity-e44838f4339b90817b5eba5df16230b02487f0cc.tar.xz serenity-e44838f4339b90817b5eba5df16230b02487f0cc.zip | |
More config for CreateCommand, add various methods
Adds multiple configurations to the command builder, and adds methods
to various structs.
Context::get_current_user is a shortcut to retrieve the current user
from the cache.
Message::get_member retrieves the member object of the message, if sent
in a guild. Message::is_private checks if the message was sent in a
Group or PrivateChannel.
User::member retrieves the user's member object in a guild by Id;
Adds 6 configurations to the command builder:
- dm_only: whether the command can only be used in direct messages;
- guild_only: whether the command can only be used in guilds;
- help_available: whether the command should be displayed in the help
list;
- max_args: specify the maximum number of arguments a command must be
given;
- min_args: specify the minimum number of arguments a command must be
given;
- required_permissions: the permissions a member must have to be able
to use the command;
Diffstat (limited to 'src/model/user.rs')
| -rw-r--r-- | src/model/user.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/model/user.rs b/src/model/user.rs index adc766f..c249631 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -13,22 +13,24 @@ use ::internal::prelude::*; use ::utils::decode_array; use ::model::misc::Mentionable; -#[cfg(feature = "methods")] +#[cfg(feature="methods")] use serde_json::builder::ObjectBuilder; #[cfg(feature="methods")] use std::mem; #[cfg(feature = "methods")] use super::Message; -#[cfg(feature = "methods")] +#[cfg(all(feature = "cache", feature = "methods"))] +use super::Member; +#[cfg(feature="methods")] use time::Timespec; -#[cfg(feature = "methods")] +#[cfg(feature="methods")] use ::client::rest::{self, GuildPagination}; #[cfg(feature="methods")] use super::GuildInfo; #[cfg(feature="methods")] use ::utils::builder::EditProfile; -#[cfg(feature = "cache")] +#[cfg(feature="cache")] use ::client::CACHE; impl CurrentUser { @@ -59,7 +61,7 @@ impl CurrentUser { /// .edit(|p| p /// .avatar(Some(&avatar))); /// ``` - #[cfg(feature = "methods")] + #[cfg(feature="methods")] pub fn edit<F>(&mut self, f: F) -> Result<()> where F: FnOnce(EditProfile) -> EditProfile { let mut map = ObjectBuilder::new() @@ -102,8 +104,17 @@ impl User { format!(cdn!("/avatars/{}/{}.jpg"), self.id, av)) } + /// Gets user as `Member` of a server. + #[cfg(all(feature="cache", feature="methods"))] + pub fn member<G>(&self, guild_id: G) -> Option<Member> + where G: Into<GuildId> { + let cache = CACHE.read().unwrap(); + + cache.get_member(guild_id.into(), self.id).cloned() + } + /// Retrieves the time that this user was created at. - #[cfg(feature = "methods")] + #[cfg(feature="methods")] #[inline] pub fn created_at(&self) -> Timespec { self.id.created_at() |