aboutsummaryrefslogtreecommitdiff
path: root/src/client/context.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-15 11:36:53 -0800
committerAustin Hellyer <[email protected]>2016-11-15 11:36:53 -0800
commit5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4 (patch)
tree7cf531e4790109d6d7edd26bc5b483378d5ba5ac /src/client/context.rs
parentEmbed Author: everything but 'name' is optional (diff)
downloadserenity-5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4.tar.xz
serenity-5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4.zip
Add state/framework/etc. conditional compile flags
This adds conditional compilation for the following features, in addition to the voice conditional compilation flag: - extras (message builder) - framework - methods - state These 4 are enabled _by default_, while the `voice` feature flag is disabled. Disabling the state will allow incredibly low-memory bots.
Diffstat (limited to 'src/client/context.rs')
-rw-r--r--src/client/context.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 0507bc3..6443efa 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::io::Read;
use std::sync::{Arc, Mutex};
use super::connection::Connection;
-use super::{STATE, http};
+use super::http;
use super::login_type::LoginType;
use ::utils::builder::{
CreateInvite,
@@ -19,6 +19,9 @@ use ::internal::prelude::*;
use ::model::*;
use ::utils;
+#[cfg(feature = "state")]
+use super::STATE;
+
#[derive(Clone)]
pub struct Context {
channel_id: Option<ChannelId>,
@@ -553,7 +556,7 @@ impl Context {
let guild_id = guild_id.into();
let role_id = role_id.into();
- let map = {
+ let map = feature_state! {{
let state = STATE.lock().unwrap();
let role = if let Some(role) = {
@@ -565,7 +568,9 @@ impl Context {
};
f(EditRole::new(role)).0.build()
- };
+ } else {
+ f(EditRole::default()).0.build()
+ }};
http::edit_role(guild_id.0, role_id.0, map)
}
@@ -601,9 +606,11 @@ impl Context {
where C: Into<ChannelId> {
let channel_id = channel_id.into();
- if let Some(channel) = STATE.lock().unwrap().find_channel(channel_id) {
- return Ok(channel.clone())
- }
+ feature_state_enabled! {{
+ if let Some(channel) = STATE.lock().unwrap().find_channel(channel_id) {
+ return Ok(channel.clone())
+ }
+ }}
http::get_channel(channel_id.0)
}
@@ -612,13 +619,13 @@ impl Context {
-> Result<HashMap<ChannelId, PublicChannel>> where G: Into<GuildId> {
let guild_id = guild_id.into();
- {
+ feature_state_enabled! {{
let state = STATE.lock().unwrap();
if let Some(guild) = state.find_guild(guild_id) {
return Ok(guild.channels.clone());
}
- }
+ }}
let mut channels = HashMap::new();
@@ -677,13 +684,13 @@ impl Context {
let guild_id = guild_id.into();
let user_id = user_id.into();
- {
+ feature_state_enabled! {{
let state = STATE.lock().unwrap();
if let Some(member) = state.find_member(guild_id, user_id) {
return Ok(member.clone());
}
- }
+ }}
http::get_member(guild_id.0, user_id.0)
}