aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-24 11:26:15 -0800
committerAustin Hellyer <[email protected]>2016-11-24 11:26:15 -0800
commit290111a02f59f278374a482a8c8df12147ba4ea9 (patch)
treea27137c29deb678557122119c882c84963d89604 /src/client
parentIgnore WebSocketError::NoDataAvailable (diff)
downloadserenity-290111a02f59f278374a482a8c8df12147ba4ea9.tar.xz
serenity-290111a02f59f278374a482a8c8df12147ba4ea9.zip
Rename guild structs to Guild and PartialGuild
Diffstat (limited to 'src/client')
-rw-r--r--src/client/context.rs31
-rw-r--r--src/client/error.rs4
-rw-r--r--src/client/event_store.rs10
-rw-r--r--src/client/http/mod.rs27
-rw-r--r--src/client/mod.rs10
5 files changed, 48 insertions, 34 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 594de23..7a0dc74 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -52,7 +52,7 @@ use super::CACHE;
/// one.
///
/// For example, if you are needing information about a
-/// [channel][`PublicChannel`] within a [guild][`LiveGuild`], then you can
+/// [channel][`PublicChannel`] within a [guild][`Guild`], then you can
/// use [`get_channel`] to retrieve it. Under most circumstances, the guild and
/// its channels will be cached within the cache, and `get_channel` will just
/// pull from the cache. If it does not exist, it will make a request to the
@@ -65,7 +65,7 @@ use super::CACHE;
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`Client::on_message`]: struct.Client.html#method.on_message
-/// [`LiveGuild`]: ../model/struct.LiveGuild.html
+/// [`Guild`]: ../model/struct.Guild.html
/// [`Message`]: ../model/struct.Message.html
/// [`PublicChannel`]: ../model/struct.PublicChannel.html
/// [`Shard`]: gateway/struct.Shard.html
@@ -263,7 +263,10 @@ impl Context {
http::create_emoji(guild_id.into().0, map)
}
- /// Creates a [`Guild`] with the data provided.
+ /// Creates a guild with the data provided.
+ ///
+ /// Only a [`PartialGuild`] will be immediately returned, and a full
+ /// [`Guild`] will be received over a [`Shard`].
///
/// **Note**: This endpoint is usually only available for user accounts.
/// Refer to Discord's information for the endpoint [here][whitelist] for
@@ -281,10 +284,12 @@ impl Context {
/// ```
///
/// [`Guild`]: ../model/struct.Guild.html
+ /// [`PartialGuild`]: ../model/struct.PartialGuild.html
+ /// [`Shard`]: ../gateway/struct.Shard.html
/// [US West region]: ../model/enum.Region.html#variant.UsWest
/// [whitelist]: https://discordapp.com/developers/docs/resources/guild#create-guild
pub fn create_guild(&self, name: &str, region: Region, icon: Option<&str>)
- -> Result<Guild> {
+ -> Result<PartialGuild> {
let map = ObjectBuilder::new()
.insert("icon", icon)
.insert("name", name)
@@ -493,11 +498,13 @@ impl Context {
http::delete_emoji(guild_id.into().0, emoji_id.into().0)
}
- /// Deletes a [`Guild`]. You must be the guild owner to be able to delete
- /// the guild.
+ /// Deletes a guild. You must be the guild owner to be able to delete it.
///
- /// [`Guild`]: ../model/struct.Guild.html
- pub fn delete_guild<G: Into<GuildId>>(&self, guild_id: G) -> Result<Guild> {
+ /// Only a [`PartialGuild`] will be immediately returned.
+ ///
+ /// [`PartialGuild`]: ../model/struct.PartialGuild.html
+ pub fn delete_guild<G: Into<GuildId>>(&self, guild_id: G)
+ -> Result<PartialGuild> {
http::delete_guild(guild_id.into().0)
}
@@ -707,7 +714,7 @@ impl Context {
http::edit_emoji(guild_id.into().0, emoji_id.into().0, map)
}
- pub fn edit_guild<F, G>(&self, guild_id: G, f: F) -> Result<Guild>
+ pub fn edit_guild<F, G>(&self, guild_id: G, f: F) -> Result<PartialGuild>
where F: FnOnce(EditGuild) -> EditGuild, G: Into<GuildId> {
let map = f(EditGuild::default()).0.build();
@@ -864,7 +871,8 @@ impl Context {
http::get_emojis(guild_id.into().0)
}
- pub fn get_guild<G: Into<GuildId>>(&self, guild_id: G) -> Result<Guild> {
+ pub fn get_guild<G: Into<GuildId>>(&self, guild_id: G)
+ -> Result<PartialGuild> {
http::get_guild(guild_id.into().0)
}
@@ -1016,7 +1024,8 @@ impl Context {
http::kick_member(guild_id.into().0, user_id.into().0)
}
- pub fn leave_guild<G: Into<GuildId>>(&self, guild_id: G) -> Result<Guild> {
+ pub fn leave_guild<G: Into<GuildId>>(&self, guild_id: G)
+ -> Result<PartialGuild> {
http::leave_guild(guild_id.into().0)
}
diff --git a/src/client/error.rs b/src/client/error.rs
index a016e92..76e0d2c 100644
--- a/src/client/error.rs
+++ b/src/client/error.rs
@@ -59,11 +59,11 @@ pub enum Error {
DeleteMessageDaysAmount(u8),
/// When there was an error retrieving the gateway URI from the REST API.
Gateway,
- /// An indication that a [guild][`LiveGuild`] could not be found by
+ /// An indication that a [guild][`Guild`] could not be found by
/// [Id][`GuildId`] in the [`Cache`].
///
+ /// [`Guild`]: ../model/struct.Guild.html
/// [`GuildId`]: ../model/struct.GuildId.html
- /// [`LiveGuild`]: ../model/struct.LiveGuild.html
/// [`Cache`]: ../ext/cache/struct.Cache.html
GuildNotFound,
InvalidOpCode,
diff --git a/src/client/event_store.rs b/src/client/event_store.rs
index 0deaa94..42d4305 100644
--- a/src/client/event_store.rs
+++ b/src/client/event_store.rs
@@ -48,11 +48,11 @@ pub struct EventStore {
pub on_friend_suggestion_delete: Option<Arc<Fn(Context, UserId) + Send + Sync + 'static>>,
pub on_guild_ban_addition: Option<Arc<Fn(Context, GuildId, User) + Send + Sync + 'static>>,
pub on_guild_ban_removal: Option<Arc<Fn(Context, GuildId, User) + Send + Sync + 'static>>,
- pub on_guild_create: Option<Arc<Fn(Context, LiveGuild) + Send + Sync + 'static>>,
+ pub on_guild_create: Option<Arc<Fn(Context, Guild) + Send + Sync + 'static>>,
#[cfg(feature = "cache")]
- pub on_guild_delete: Option<Arc<Fn(Context, Guild, Option<LiveGuild>) + Send + Sync + 'static>>,
+ pub on_guild_delete: Option<Arc<Fn(Context, PartialGuild, Option<Guild>) + Send + Sync + 'static>>,
#[cfg(not(feature = "cache"))]
- pub on_guild_delete: Option<Arc<Fn(Context, Guild) + Send + Sync + 'static>>,
+ pub on_guild_delete: Option<Arc<Fn(Context, PartialGuild) + Send + Sync + 'static>>,
pub on_guild_emojis_update: Option<Arc<Fn(Context, GuildId, HashMap<EmojiId, Emoji>) + Send + Sync + 'static>>,
pub on_guild_integrations_update: Option<Arc<Fn(Context, GuildId) + Send + Sync + 'static>>,
pub on_guild_member_addition: Option<Arc<Fn(Context, GuildId, Member) + Send + Sync + 'static>>,
@@ -77,9 +77,9 @@ pub struct EventStore {
pub on_guild_sync: Option<Arc<Fn(Context, GuildSyncEvent) + Send + Sync + 'static>>,
pub on_guild_unavailable: Option<Arc<Fn(Context, GuildId) + Send + Sync + 'static>>,
#[cfg(feature = "cache")]
- pub on_guild_update: Option<Arc<Fn(Context, Option<LiveGuild>, Guild) + Send + Sync + 'static>>,
+ pub on_guild_update: Option<Arc<Fn(Context, Option<Guild>, PartialGuild) + Send + Sync + 'static>>,
#[cfg(not(feature = "cache"))]
- pub on_guild_update: Option<Arc<Fn(Context, Guild) + Send + Sync + 'static>>,
+ pub on_guild_update: Option<Arc<Fn(Context, PartialGuild) + Send + Sync + 'static>>,
pub on_message: Option<Arc<Fn(Context, Message) + Send + Sync + 'static>>,
pub on_message_ack: Option<Arc<Fn(Context, ChannelId, Option<MessageId>) + Send + Sync + 'static>>,
pub on_message_delete: Option<Arc<Fn(Context, ChannelId, MessageId) + Send + Sync + 'static>>,
diff --git a/src/client/http/mod.rs b/src/client/http/mod.rs
index ea15230..682b69c 100644
--- a/src/client/http/mod.rs
+++ b/src/client/http/mod.rs
@@ -233,7 +233,10 @@ pub fn create_emoji(guild_id: u64, map: Value)
Emoji::decode(try!(serde_json::from_reader(response)))
}
-/// Creates a [`Guild`] with the data provided.
+/// Creates a guild with the data provided.
+///
+/// Only a [`PartialGuild`] will be immediately returned, and a full [`Guild`]
+/// will be received over a [`Shard`], if at least one is running.
///
/// **Note**: This endpoint is usually only available for user accounts. Refer
/// to Discord's documentation for the endpoint [here][whitelist] for more
@@ -260,13 +263,15 @@ pub fn create_emoji(guild_id: u64, map: Value)
/// ```
///
/// [`Guild`]: ../../model/struct.Guild.html
+/// [`PartialGuild`]: ../../model/struct.PartialGuild.html
+/// [`Shard`]: ../gateway/struct.Shard.html
/// [US West Region]: ../../model/enum.Region.html#variant.UsWest
/// [whitelist]: https://discordapp.com/developers/docs/resources/guild#create-guild
-pub fn create_guild(map: Value) -> Result<Guild> {
+pub fn create_guild(map: Value) -> Result<PartialGuild> {
let body = try!(serde_json::to_string(&map));
let response = request!(Route::Guilds, post(body), "/guilds");
- Guild::decode(try!(serde_json::from_reader(response)))
+ PartialGuild::decode(try!(serde_json::from_reader(response)))
}
/// Creates an [`Integration`] for a [`Guild`].
@@ -413,13 +418,13 @@ pub fn delete_emoji(guild_id: u64, emoji_id: u64) -> Result<()> {
emoji_id))
}
-pub fn delete_guild(guild_id: u64) -> Result<Guild> {
+pub fn delete_guild(guild_id: u64) -> Result<PartialGuild> {
let response = request!(Route::GuildsId(guild_id),
delete,
"/guilds/{}",
guild_id);
- Guild::decode(try!(serde_json::from_reader(response)))
+ PartialGuild::decode(try!(serde_json::from_reader(response)))
}
pub fn delete_guild_integration(guild_id: u64, integration_id: u64)
@@ -589,14 +594,14 @@ pub fn edit_emoji(guild_id: u64, emoji_id: u64, map: Value)
Emoji::decode(try!(serde_json::from_reader(response)))
}
-pub fn edit_guild(guild_id: u64, map: Value) -> Result<Guild> {
+pub fn edit_guild(guild_id: u64, map: Value) -> Result<PartialGuild> {
let body = try!(serde_json::to_string(&map));
let response = request!(Route::GuildsId(guild_id),
patch(body),
"/guilds/{}",
guild_id);
- Guild::decode(try!(serde_json::from_reader(response)))
+ PartialGuild::decode(try!(serde_json::from_reader(response)))
}
pub fn edit_member(guild_id: u64, user_id: u64, map: Value)
@@ -934,13 +939,13 @@ pub fn get_emojis(guild_id: u64) -> Result<Vec<Emoji>> {
decode_array(try!(serde_json::from_reader(response)), Emoji::decode)
}
-pub fn get_guild(guild_id: u64) -> Result<Guild> {
+pub fn get_guild(guild_id: u64) -> Result<PartialGuild> {
let response = request!(Route::GuildsId(guild_id),
get,
"/guilds/{}",
guild_id);
- Guild::decode(try!(serde_json::from_reader(response)))
+ PartialGuild::decode(try!(serde_json::from_reader(response)))
}
pub fn get_guild_embed(guild_id: u64) -> Result<GuildEmbed> {
@@ -1194,13 +1199,13 @@ pub fn leave_group(guild_id: u64) -> Result<Group> {
Group::decode(try!(serde_json::from_reader(response)))
}
-pub fn leave_guild(guild_id: u64) -> Result<Guild> {
+pub fn leave_guild(guild_id: u64) -> Result<PartialGuild> {
let response = request!(Route::UsersMeGuildsId,
delete,
"/users/@me/guilds/{}",
guild_id);
- Guild::decode(try!(serde_json::from_reader(response)))
+ PartialGuild::decode(try!(serde_json::from_reader(response)))
}
pub fn logout(map: Value) -> Result<()> {
diff --git a/src/client/mod.rs b/src/client/mod.rs
index a8b44dd..cc7164f 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -379,7 +379,7 @@ impl Client {
///
/// [`GuildCreate`]: ../model/enum.Event.html#variant.GuildCreate
pub fn on_guild_create<F>(&mut self, handler: F)
- where F: Fn(Context, LiveGuild) + Send + Sync + 'static {
+ where F: Fn(Context, Guild) + Send + Sync + 'static {
self.event_store.lock()
.unwrap()
.on_guild_create = Some(Arc::new(handler));
@@ -852,7 +852,7 @@ impl Client {
/// [`Role`]: ../model/struct.Role.html
/// [`Cache`]: ../ext/cache/struct.Cache.html
pub fn on_guild_delete<F>(&mut self, handler: F)
- where F: Fn(Context, Guild, Option<LiveGuild>) + Send + Sync + 'static {
+ where F: Fn(Context, PartialGuild, Option<Guild>) + Send + Sync + 'static {
self.event_store.lock()
.unwrap()
.on_guild_delete = Some(Arc::new(handler));
@@ -919,7 +919,7 @@ impl Client {
///
/// [`GuildUpdate`]: ../model/enum.Event.html#variant.GuildUpdate
pub fn on_guild_update<F>(&mut self, handler: F)
- where F: Fn(Context, Option<LiveGuild>, Guild) + Send + Sync + 'static {
+ where F: Fn(Context, Option<Guild>, PartialGuild) + Send + Sync + 'static {
self.event_store.lock()
.unwrap()
.on_guild_update = Some(Arc::new(handler));
@@ -1001,7 +1001,7 @@ impl Client {
/// [`Role`]: ../model/struct.Role.html
/// [`Cache`]: ../ext/cache/struct.Cache.html
pub fn on_guild_delete<F>(&mut self, handler: F)
- where F: Fn(Context, Guild) + Send + Sync + 'static {
+ where F: Fn(Context, PartialGuild) + Send + Sync + 'static {
self.event_store.lock()
.unwrap()
.on_guild_delete = Some(Arc::new(handler));
@@ -1065,7 +1065,7 @@ impl Client {
///
/// [`GuildUpdate`]: ../model/enum.Event.html#variant.GuildUpdate
pub fn on_guild_update<F>(&mut self, handler: F)
- where F: Fn(Context, Guild) + Send + Sync + 'static {
+ where F: Fn(Context, PartialGuild) + Send + Sync + 'static {
self.event_store.lock()
.unwrap()
.on_guild_update = Some(Arc::new(handler));