aboutsummaryrefslogtreecommitdiff
path: root/src/client/context.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-21 19:17:57 -0800
committerAustin Hellyer <[email protected]>2016-11-21 19:17:57 -0800
commit6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078 (patch)
treea6f0303ebcf4a474f603aaa5c8fff67409d42a17 /src/client/context.rs
parentAdd support for creating embed images (diff)
downloadserenity-6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078.tar.xz
serenity-6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078.zip
Re-organize the client module
Re-organize the client module, creating a `gateway` submodule, and splitting the connection into separate files in it. The connection was a conglomeration of a number of purposes, most of which are actually used elsewhere in the library and/or exposed to the user. Thus, it makes sense to separate each item in a gateway-specific module. By splitting the client module further, this is a re-organization for preliminary RPC support WRT the Client. Additionally, rename the Connection struct to a Shard. The Connection itself was not the actual connection, and was a higher-level interface to the real connection logic. A Shard is a more accurate representation of what it actually is.
Diffstat (limited to 'src/client/context.rs')
-rw-r--r--src/client/context.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index b1cc57f..7008f9b 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -2,7 +2,7 @@ use serde_json::builder::ObjectBuilder;
use std::collections::HashMap;
use std::io::Read;
use std::sync::{Arc, Mutex};
-use super::connection::Connection;
+use super::gateway::Shard;
use super::http;
use super::login_type::LoginType;
use ::utils::builder::{
@@ -26,7 +26,7 @@ use super::STATE;
/// The context is a general utility struct provided on event dispatches, which
/// helps with dealing with the current "context" of the event dispatch,
/// and providing helper methods where possible. The context also acts as a
-/// general high-level interface over the associated [`Connection`] which
+/// general high-level interface over the associated [`Shard`] which
/// received the event, or the low-level [`http`] module.
///
/// For example, when the [`Client::on_message`] handler is dispatched to, the
@@ -35,8 +35,8 @@ use super::STATE;
/// post its given argument to the associated channel for you as a [`Message`].
///
/// Additionally, the context contains "shortcuts", like for interacting with
-/// the connection. Methods like [`set_game`] will unlock the connection and
-/// perform an update for you to save a bit of work.
+/// the shard. Methods like [`set_game`] will unlock the shard and perform an
+/// update for you to save a bit of work.
///
/// A context will only live for the event it was dispatched for. After the
/// event handler finished, it is destroyed and will not be re-used.
@@ -65,10 +65,10 @@ use super::STATE;
///
/// [`Channel`]: ../model/enum.Channel.html
/// [`Client::on_message`]: struct.Client.html#method.on_message
-/// [`Connection`]: struct.Connection.html
/// [`LiveGuild`]: ../model/struct.LiveGuild.html
/// [`Message`]: ../model/struct.Message.html
/// [`PublicChannel`]: ../model/struct.PublicChannel.html
+/// [`Shard`]: gateway/struct.Shard.html
/// [`State`]: ../ext/state/struct.State.html
/// [`get_channel`]: #method.get_channel
/// [`http`]: http/index.html
@@ -81,11 +81,11 @@ pub struct Context {
///
/// [`on_message`]: struct.Client.html#method.on_message
pub channel_id: Option<ChannelId>,
- /// The associated connection which dispatched the event handler.
+ /// The associated shard which dispatched the event handler.
///
/// Note that if you are sharding, in relevant terms, this is the shard
/// which received the event being dispatched.
- pub connection: Arc<Mutex<Connection>>,
+ pub shard: Arc<Mutex<Shard>>,
login_type: LoginType,
}
@@ -99,11 +99,11 @@ impl Context {
/// documentation.
#[doc(hidden)]
pub fn new(channel_id: Option<ChannelId>,
- connection: Arc<Mutex<Connection>>,
+ shard: Arc<Mutex<Shard>>,
login_type: LoginType) -> Context {
Context {
channel_id: channel_id,
- connection: connection,
+ shard: shard,
login_type: login_type,
}
}
@@ -1227,7 +1227,7 @@ impl Context {
///
/// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
pub fn online(&self) {
- self.connection.lock().unwrap().set_status(OnlineStatus::Online);
+ self.shard.lock().unwrap().set_status(OnlineStatus::Online);
}
/// Sets the current user as being [`Idle`]. This maintains the current
@@ -1235,7 +1235,7 @@ impl Context {
///
/// [`Idle`]: ../model/enum.OnlineStatus.html#variant.Idle
pub fn idle(&self) {
- self.connection.lock().unwrap().set_status(OnlineStatus::Idle);
+ self.shard.lock().unwrap().set_status(OnlineStatus::Idle);
}
/// Sets the current user as being [`DoNotDisturb`]. This maintains the
@@ -1243,7 +1243,7 @@ impl Context {
///
/// [`DoNotDisturb`]: ../model/enum.OnlineStatus.html#variant.DoNotDisturb
pub fn dnd(&self) {
- self.connection.lock().unwrap().set_status(OnlineStatus::DoNotDisturb);
+ self.shard.lock().unwrap().set_status(OnlineStatus::DoNotDisturb);
}
/// Sets the current user as being [`Invisible`]. This maintains the current
@@ -1251,7 +1251,7 @@ impl Context {
///
/// [`Invisible`]: ../model/enum.OnlineStatus.html#variant.Invisible
pub fn invisible(&self) {
- self.connection.lock().unwrap().set_status(OnlineStatus::Invisible);
+ self.shard.lock().unwrap().set_status(OnlineStatus::Invisible);
}
/// "Resets" the current user's presence, by setting the game to `None`,
@@ -1262,7 +1262,7 @@ impl Context {
/// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
/// [`set_presence`]: #method.set_presence
pub fn reset_presence(&self) {
- self.connection.lock()
+ self.shard.lock()
.unwrap()
.set_presence(None, OnlineStatus::Online, false)
}
@@ -1284,7 +1284,7 @@ impl Context {
///
/// [`Online`]: ../model/enum.OnlineStatus.html#variant.Online
pub fn set_game(&self, game: Game) {
- self.connection.lock()
+ self.shard.lock()
.unwrap()
.set_presence(Some(game), OnlineStatus::Online, false);
}
@@ -1309,7 +1309,7 @@ impl Context {
url: None,
};
- self.connection.lock()
+ self.shard.lock()
.unwrap()
.set_presence(Some(game), OnlineStatus::Online, false);
}
@@ -1349,7 +1349,7 @@ impl Context {
game: Option<Game>,
status: OnlineStatus,
afk: bool) {
- self.connection.lock()
+ self.shard.lock()
.unwrap()
.set_presence(game, status, afk)
}