From 6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078 Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Mon, 21 Nov 2016 19:17:57 -0800 Subject: 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. --- examples/02_transparent_guild_sharding.rs | 6 +++--- examples/07_voice.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/02_transparent_guild_sharding.rs b/examples/02_transparent_guild_sharding.rs index d257373..64a5a6f 100644 --- a/examples/02_transparent_guild_sharding.rs +++ b/examples/02_transparent_guild_sharding.rs @@ -30,9 +30,9 @@ fn main() { client.on_message(|context, message| { if message.content == "!ping" { { - let connection = context.connection.lock().unwrap(); + let shard = context.shard.lock().unwrap(); - if let Some(shard_info) = connection.shard_info() { + if let Some(shard_info) = shard.shard_info() { println!("Shard {}", shard_info[0]); } } @@ -46,7 +46,7 @@ fn main() { }); // The total number of shards to use. The "current shard number" of a - // connection - that is, the shard it is assigned to - is indexed at 0, + // shard - that is, the shard it is assigned to - is indexed at 0, // while the total shard count is indexed at 1. // // This means if you have 5 shards, your total shard count will be 5, while diff --git a/examples/07_voice.rs b/examples/07_voice.rs index d570abf..3250512 100644 --- a/examples/07_voice.rs +++ b/examples/07_voice.rs @@ -52,9 +52,9 @@ fn deafen(context: Context, message: Message, _args: Vec) { }, }; - let mut connection = context.connection.lock().unwrap(); + let mut shard = context.shard.lock().unwrap(); - let handler = match connection.manager.get(guild_id) { + let handler = match shard.manager.get(guild_id) { Some(handler) => handler, None => { let _ = message.reply("Not in a voice channel"); @@ -104,8 +104,8 @@ fn join(context: Context, message: Message, args: Vec) { }, }; - let mut connection = context.connection.lock().unwrap(); - let ref mut manager = connection.manager; + let mut shard = context.shard.lock().unwrap(); + let ref mut manager = shard.manager; let _handler = manager.join(Some(guild_id), connect_to); @@ -128,13 +128,13 @@ fn leave(context: Context, message: Message, _args: Vec) { }, }; - let is_connected = match context.connection.lock().unwrap().manager.get(guild_id) { + let is_connected = match context.shard.lock().unwrap().manager.get(guild_id) { Some(handler) => handler.channel().is_some(), None => false, }; if is_connected { - context.connection.lock().unwrap().manager.remove(guild_id); + context.shard.lock().unwrap().manager.remove(guild_id); let _ = context.say("Left voice channel"); } else { @@ -158,9 +158,9 @@ fn mute(context: Context, message: Message, _args: Vec) { }, }; - let mut connection = context.connection.lock().unwrap(); + let mut shard = context.shard.lock().unwrap(); - let handler = match connection.manager.get(guild_id) { + let handler = match shard.manager.get(guild_id) { Some(handler) => handler, None => { let _ = message.reply("Not in a voice channel"); -- cgit v1.2.3