From e44838f4339b90817b5eba5df16230b02487f0cc Mon Sep 17 00:00:00 2001 From: Illia Date: Sat, 10 Dec 2016 22:25:55 +0200 Subject: 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; --- src/client/context.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/client/context.rs') diff --git a/src/client/context.rs b/src/client/context.rs index eb7246b..e646ec6 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -22,7 +22,7 @@ use ::internal::prelude::*; use ::model::*; use ::utils; -#[cfg(feature = "cache")] +#[cfg(feature="cache")] use super::CACHE; /// The context is a general utility struct provided on event dispatches, which @@ -1077,6 +1077,15 @@ impl Context { Ok(channels) } + /// Gets information about the current user. + /// + /// Note this is shorthand for retrieving the current user through the + /// cache, and will perform a clone. + #[cfg(all(feature = "cache", feature = "methods"))] + pub fn get_current_user(&self) -> CurrentUser { + CACHE.read().unwrap().user.clone() + } + /// Gets an [`Guild`]'s emoji by Id. /// /// Requires the [Manage Emojis] permission. -- cgit v1.2.3