diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-10 11:38:54 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-10 11:38:54 -0800 |
| commit | 062ea86d5b0d9932207636d4a44a5357b079e79a (patch) | |
| tree | 7f4eeb11801df6ea8648c7aa660e4bbef815f621 | |
| parent | Fix docs for User::has_role (diff) | |
| download | serenity-062ea86d5b0d9932207636d4a44a5357b079e79a.tar.xz serenity-062ea86d5b0d9932207636d4a44a5357b079e79a.zip | |
Add `Client::user_id`
Add the user ID to the client. This can be used when initializing the
framework on connection start, as well as the future voice manager.
| -rw-r--r-- | src/client/mod.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index f56aa66..064e27f 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -39,6 +39,7 @@ pub use CACHE; use http; use internal::prelude::*; +use model::id::UserId; use parking_lot::Mutex; use self::bridge::gateway::{ShardManager, ShardManagerMonitor}; use std::sync::Arc; @@ -276,6 +277,10 @@ pub struct Client { pub threadpool: ThreadPool, /// The token in use by the client. pub token: Arc<Mutex<String>>, + /// The ID of the user for this client. + /// + /// This is retrieved when the client is created using the given token. + pub user_id: UserId, /// URI that the client's shards will use to connect to the gateway. /// /// This is likely not important for production usage and is, at best, used @@ -327,6 +332,8 @@ impl Client { }; http::set_token(&token); + let user_id = http::get_current_user()?.id; + let locked = Arc::new(Mutex::new(token)); let name = "serenity client".to_owned(); @@ -358,6 +365,7 @@ impl Client { shard_manager, shard_manager_worker, threadpool, + user_id, } } else { let (shard_manager, shard_manager_worker) = ShardManager::new( @@ -378,6 +386,7 @@ impl Client { shard_manager, shard_manager_worker, threadpool, + user_id, } }}) } @@ -817,10 +826,8 @@ impl Client { // This also acts as a form of check to ensure the token is correct. #[cfg(all(feature = "standard_framework", feature = "framework"))] { - let user = http::get_current_user()?; - if let Some(ref mut framework) = *self.framework.lock() { - framework.update_current_user(user.id); + framework.update_current_user(self.user_id); } } |