aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-04-09 10:44:43 -0700
committerZeyla Hellyer <[email protected]>2017-04-09 10:44:43 -0700
commitc74cc15f8969c8db68119d07a4f273a0d3fc44f4 (patch)
treea37a4989a4af4b6d78fe1d40a62a329ae336578c /src
parentRemove selfbot support (diff)
downloadserenity-c74cc15f8969c8db68119d07a4f273a0d3fc44f4.tar.xz
serenity-c74cc15f8969c8db68119d07a4f273a0d3fc44f4.zip
Remove support for group calls and guild sync
Calls and guild sync are essentially leftovers from selfbot support removal, the former moreso. Removes the following `model::event` structs: - CallCreateEvent - CallDeleteEvent - CallUpdateEvent - GuildSyncEvent which also removes the following `model::event::Event` variants: `client::gateway::Shard::sync_calls` has been removed. The following `client::Client` methods have been removed: - `on_call_create` - `on_call_delete` - `on_call_update` - `on_guild_sync` Removes the following items on `ext::cache::Cache`: ``` ext::cache::Cache::{ // fields calls, // methods get_call, update_with_call_create, update_with_call_delete, update_with_call_update, update_with_guild_sync, } ``` Voice structs and methods now take solely a `guild_id` instead of a `target`, due to the handling of 1-on-1 and group calls being removed. This continues off commit d9118c0.<Paste>
Diffstat (limited to 'src')
-rw-r--r--src/client/dispatch.rs57
-rw-r--r--src/client/event_store.rs24
-rw-r--r--src/client/gateway/shard.rs18
-rw-r--r--src/client/mod.rs80
-rw-r--r--src/constants.rs6
-rw-r--r--src/ext/cache/mod.rs103
-rw-r--r--src/ext/voice/connection_info.rs4
-rw-r--r--src/ext/voice/handler.rs51
-rw-r--r--src/ext/voice/manager.rs72
-rw-r--r--src/ext/voice/mod.rs31
-rw-r--r--src/ext/voice/payload.rs2
-rw-r--r--src/ext/voice/threading.rs12
-rw-r--r--src/model/event.rs151
13 files changed, 58 insertions, 553 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index 49dbdb0..fd46394 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -121,56 +121,6 @@ fn handle_event(event: Event,
data: &Arc<Mutex<ShareMap>>,
event_store: &Arc<RwLock<EventStore>>) {
match event {
- Event::CallCreate(event) => {
- if let Some(handler) = handler!(on_call_create, event_store) {
- update!(update_with_call_create, event);
-
- let context = context(None, conn, data);
-
- thread::spawn(move || (handler)(context, event.call));
- } else {
- update!(update_with_call_create, event);
- }
- },
- Event::CallDelete(event) => {
- if let Some(handler) = handler!(on_call_delete, event_store) {
- let context = context(None, conn, data);
-
- feature_cache! {{
- let call = update!(update_with_call_delete, event);
-
- thread::spawn(move || (handler)(context, event.channel_id, call));
- } else {
- thread::spawn(move || (handler)(context, event.channel_id));
- }}
- } else {
- update!(update_with_call_delete, event);
- }
- },
- Event::CallUpdate(event) => {
- if let Some(handler) = handler!(on_call_update, event_store) {
- let context = context(None, conn, data);
-
- feature_cache! {{
- let before = update!(update_with_call_update, event, true);
- let after = CACHE
- .read()
- .unwrap()
- .calls
- .get(&event.channel_id)
- .cloned();
-
- thread::spawn(move || (handler)(context, before, after));
- } else {
- thread::spawn(move || (handler)(context, event));
- }}
- } else {
- #[cfg(feature="cache")]
- {
- update!(update_with_call_update, event, false);
- }
- }
- },
Event::ChannelCreate(event) => {
if let Some(handler) = handler!(on_channel_create, event_store) {
update!(update_with_channel_create, event);
@@ -403,13 +353,6 @@ fn handle_event(event: Event,
}
}
},
- Event::GuildSync(event) => {
- if let Some(handler) = handler!(on_guild_sync, event_store) {
- let context = context(None, conn, data);
-
- thread::spawn(move || (handler)(context, event));
- }
- },
Event::GuildUnavailable(event) => {
update!(update_with_guild_unavailable, event);
diff --git a/src/client/event_store.rs b/src/client/event_store.rs
index cc74d63..9ec465c 100644
--- a/src/client/event_store.rs
+++ b/src/client/event_store.rs
@@ -2,24 +2,12 @@ use serde_json::Value;
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
use super::context::Context;
-use ::model::event::{
- ChannelPinsAckEvent,
- ChannelPinsUpdateEvent,
- GuildSyncEvent,
- MessageUpdateEvent,
- PresenceUpdateEvent,
- ResumedEvent,
- TypingStartEvent,
- VoiceServerUpdateEvent,
-};
+use ::model::event::*;
use ::model::*;
#[cfg(feature="cache")]
use std::sync::RwLock;
-#[cfg(not(feature="cache"))]
-use ::model::event::{CallUpdateEvent, GuildMemberUpdateEvent};
-
// This should use type macros when stable receives the type macro
// stabilization patch.
//
@@ -41,15 +29,6 @@ use ::model::event::{CallUpdateEvent, GuildMemberUpdateEvent};
#[allow(type_complexity)]
#[derive(Default)]
pub struct EventStore {
- pub on_call_create: Option<Arc<Fn(Context, Call) + Send + Sync + 'static>>,
- #[cfg(feature="cache")]
- pub on_call_delete: Option<Arc<Fn(Context, ChannelId, Option<Arc<RwLock<Call>>>) + Send + Sync + 'static>>,
- #[cfg(not(feature="cache"))]
- pub on_call_delete: Option<Arc<Fn(Context, ChannelId) + Send + Sync + 'static>>,
- #[cfg(feature="cache")]
- pub on_call_update: Option<Arc<Fn(Context, Option<Arc<RwLock<Call>>>, Option<Arc<RwLock<Call>>>) + Send + Sync + 'static>>,
- #[cfg(not(feature="cache"))]
- pub on_call_update: Option<Arc<Fn(Context, CallUpdateEvent) + Send + Sync + 'static>>,
pub on_channel_create: Option<Arc<Fn(Context, Channel) + Send + Sync + 'static>>,
pub on_channel_delete: Option<Arc<Fn(Context, Channel) + Send + Sync + 'static>>,
pub on_channel_pins_ack: Option<Arc<Fn(Context, ChannelPinsAckEvent) + Send + Sync + 'static>>,
@@ -88,7 +67,6 @@ pub struct EventStore {
pub on_guild_role_update: Option<Arc<Fn(Context, GuildId, Option<Role>, Role) + Send + Sync + 'static>>,
#[cfg(not(feature="cache"))]
pub on_guild_role_update: Option<Arc<Fn(Context, GuildId, Role) + Send + Sync + 'static>>,
- 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<Arc<RwLock<Guild>>>, PartialGuild) + Send + Sync + 'static>>,
diff --git a/src/client/gateway/shard.rs b/src/client/gateway/shard.rs
index f42c52a..627ba52 100644
--- a/src/client/gateway/shard.rs
+++ b/src/client/gateway/shard.rs
@@ -18,7 +18,7 @@ use ::constants::OpCode;
use ::internal::prelude::*;
use ::internal::ws_impl::{ReceiverExt, SenderExt};
use ::model::event::{Event, GatewayEvent, ReadyEvent};
-use ::model::{ChannelId, Game, GuildId, OnlineStatus};
+use ::model::{Game, GuildId, OnlineStatus};
#[cfg(feature="cache")]
use ::client::CACHE;
@@ -483,22 +483,6 @@ impl Shard {
Ok(())
}
- /// Syncs a number of [`Call`]s, given by their associated channel Ids. This
- /// will allow the current user to know what calls are currently occurring,
- /// as otherwise events will not be received.
- pub fn sync_calls(&self, channels: &[ChannelId]) {
- for &channel in channels {
- let msg = ObjectBuilder::new()
- .insert("op", OpCode::SyncCall.num())
- .insert_object("d", |obj| obj
- .insert("channel_id", channel.0)
- )
- .build();
-
- let _ = self.keepalive_channel.send(GatewayStatus::SendMessage(msg));
- }
- }
-
/// Requests that one or multiple [`Guild`]s be synced.
///
/// This will ask Discord to start sending member chunks for large guilds
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 9286379..8c073b1 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -44,19 +44,7 @@ use websocket::result::WebSocketError;
use websocket::stream::WebSocketStream;
use ::internal::prelude::{Error, Result, Value};
use ::internal::ws_impl::ReceiverExt;
-use ::model::event::{
- ChannelPinsAckEvent,
- ChannelPinsUpdateEvent,
- Event,
- GatewayEvent,
- GuildSyncEvent,
- MessageUpdateEvent,
- PresenceUpdateEvent,
- ReadyEvent,
- ResumedEvent,
- TypingStartEvent,
- VoiceServerUpdateEvent,
-};
+use ::model::event::*;
use ::model::*;
#[cfg(feature="framework")]
@@ -65,9 +53,6 @@ use ::ext::framework::Framework;
#[cfg(feature="cache")]
use ::ext::cache::Cache;
-#[cfg(not(feature="cache"))]
-use ::model::event::{CallUpdateEvent, GuildMemberUpdateEvent};
-
#[cfg(feature="cache")]
lazy_static! {
/// A mutable and lazily-initialized static binding. It can be accessed
@@ -326,16 +311,6 @@ impl Client {
self.start_connection(Some([range[0], range[1], total_shards]), rest::get_gateway()?.url)
}
- /// Attaches a handler for when a [`CallCreate`] is received.
- ///
- /// [`CallCreate`]: ../model/event/enum.Event.html#variant.CallCreate
- pub fn on_call_create<F>(&mut self, handler: F)
- where F: Fn(Context, Call) + Send + Sync + 'static {
- self.event_store.write()
- .unwrap()
- .on_call_create = Some(Arc::new(handler));
- }
-
/// Attaches a handler for when a [`ChannelCreate`] is received.
///
/// [`ChannelCreate`]: ../model/event/enum.Event.html#variant.ChannelCreate
@@ -438,16 +413,6 @@ impl Client {
.on_guild_role_create = Some(Arc::new(handler));
}
- /// Attaches a handler for when a [`GuildRoleSync`] is received.
- ///
- /// [`GuildRoleSync`]: ../model/event/enum.Event.html#variant.GuildRoleSync
- pub fn on_guild_sync<F>(&mut self, handler: F)
- where F: Fn(Context, GuildSyncEvent) + Send + Sync + 'static {
- self.event_store.write()
- .unwrap()
- .on_guild_sync = Some(Arc::new(handler));
- }
-
/// Attaches a handler for when a [`GuildUnavailable`] is received.
///
/// [`GuildUnavailable`]: ../model/event/enum.Event.html#variant.GuildUnavailable
@@ -809,29 +774,6 @@ impl Client {
#[cfg(feature="cache")]
impl Client {
- /// Attaches a handler for when a [`CallDelete`] is received.
- ///
- /// The `ChannelId` is the Id of the channel hosting the call. Returns the
- /// call from the cache - optionally - if the call was in it.
- ///
- /// [`CallDelete`]: ../model/event/enum.Event.html#variant.CallDelete
- pub fn on_call_delete<F>(&mut self, handler: F)
- where F: Fn(Context, ChannelId, Option<Arc<RwLock<Call>>>) + Send + Sync + 'static {
- self.event_store.write()
- .unwrap()
- .on_call_delete = Some(Arc::new(handler));
- }
-
- /// Attaches a handler for when a [`CallUpdate`] is received.
- ///
- /// [`CallUpdate`]: ../model/event/enum.Event.html#variant.CallUpdate
- pub fn on_call_update<F>(&mut self, handler: F)
- where F: Fn(Context, Option<Arc<RwLock<Call>>>, Option<Arc<RwLock<Call>>>) + Send + Sync + 'static {
- self.event_store.write()
- .unwrap()
- .on_call_update = Some(Arc::new(handler));
- }
-
/// Attaches a handler for when a [`ChannelUpdate`] is received.
///
/// Optionally provides the version of the channel before the update.
@@ -936,26 +878,6 @@ impl Client {
#[cfg(not(feature="cache"))]
impl Client {
- /// Attaches a handler for when a [`CallDelete`] is received.
- ///
- /// [`CallDelete`]: ../model/event/enum.Event.html#variant.CallDelete
- pub fn on_call_delete<F>(&mut self, handler: F)
- where F: Fn(Context, ChannelId) + Send + Sync + 'static {
- self.event_store.write()
- .unwrap()
- .on_call_delete = Some(Arc::new(handler));
- }
-
- /// Attaches a handler for when a [`CallUpdate`] is received.
- ///
- /// [`CallUpdate`]: ../model/event/enum.Event.html#variant.CallUpdate
- pub fn on_call_update<F>(&mut self, handler: F)
- where F: Fn(Context, CallUpdateEvent) + Send + Sync + 'static {
- self.event_store.write()
- .unwrap()
- .on_call_update = Some(Arc::new(handler));
- }
-
/// Attaches a handler for when a [`ChannelUpdate`] is received.
///
/// [`ChannelUpdate`]: ../model/event/enum.Event.html#variant.ChannelUpdate
diff --git a/src/constants.rs b/src/constants.rs
index 115263d..99327b7 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -70,8 +70,6 @@ pub enum OpCode {
InvalidSession,
Hello,
HeartbeatAck,
- SyncGuild,
- SyncCall,
}
impl OpCode {
@@ -89,8 +87,6 @@ impl OpCode {
9 => Some(OpCode::InvalidSession),
10 => Some(OpCode::Hello),
11 => Some(OpCode::HeartbeatAck),
- 12 => Some(OpCode::SyncGuild),
- 13 => Some(OpCode::SyncCall),
_ => None,
}
}
@@ -109,8 +105,6 @@ impl OpCode {
OpCode::InvalidSession => 9,
OpCode::Hello => 10,
OpCode::HeartbeatAck => 11,
- OpCode::SyncGuild => 12,
- OpCode::SyncCall => 13,
}
}
}
diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs
index 7bb9dd8..ee26816 100644
--- a/src/ext/cache/mod.rs
+++ b/src/ext/cache/mod.rs
@@ -49,7 +49,6 @@
//! while needing to hit the REST API as little as possible, then the answer
//! is "yes".
//!
-//! [`Call`]: ../../model/struct.Call.html
//! [`Context`]: ../../client/struct.Context.html
//! [`Context::get_channel`]: ../../client/struct.Context.html#method.get_channel
//! [`Emoji`]: ../../model/struct.Emoji.html
@@ -103,16 +102,6 @@ use ::model::event::*;
/// [`rest`]: ../../client/rest/index.html
#[derive(Clone, Debug)]
pub struct Cache {
- /// A map of the currently active calls that the current user knows about,
- /// where the key is the Id of the [`PrivateChannel`] or [`Group`] hosting
- /// the call.
- ///
- /// For bot users this will always be empty, except for in [special cases].
- ///
- /// [`Group`]: ../../model/struct.Group.html
- /// [`PrivateChannel`]: ../../model/struct.PrivateChannel.html
- /// [special cases]: index.html#special-cases-in-the-cache
- pub calls: HashMap<ChannelId, Arc<RwLock<Call>>>,
/// A map of channels in [`Guild`]s that the current user has received data
/// for.
///
@@ -264,16 +253,6 @@ impl Cache {
.collect()
}
- /// Retrieves a reference to a [`Call`] from the cache based on the
- /// associated [`Group`]'s channel Id.
- ///
- /// [`Call`]: ../../model/struct.Call.html
- /// [`Group`]: ../../model/struct.Group.html
- #[inline]
- pub fn get_call<C: Into<ChannelId>>(&self, group_id: C) -> Option<Arc<RwLock<Call>>> {
- self.calls.get(&group_id.into()).cloned()
- }
-
/// Retrieves a [`Channel`] from the cache based on the given Id.
///
/// This will search the [`channels`] map, the [`private_channels`] map, and
@@ -465,45 +444,6 @@ impl Cache {
}
#[doc(hidden)]
- pub fn update_with_call_create(&mut self, event: &CallCreateEvent) {
- match self.calls.entry(event.call.channel_id) {
- Entry::Vacant(e) => {
- e.insert(Arc::new(RwLock::new(event.call.clone())));
- },
- Entry::Occupied(mut e) => {
- *e.get_mut() = Arc::new(RwLock::new(event.call.clone()));
- },
- }
- }
-
- #[doc(hidden)]
- pub fn update_with_call_delete(&mut self, event: &CallDeleteEvent)
- -> Option<Arc<RwLock<Call>>> {
- self.calls.remove(&event.channel_id)
- }
-
- #[doc(hidden)]
- pub fn update_with_call_update(&mut self, event: &CallUpdateEvent, old: bool)
- -> Option<Arc<RwLock<Call>>> {
- let item = if old {
- self.calls.get(&event.channel_id).cloned()
- } else {
- None
- };
-
- self.calls
- .get_mut(&event.channel_id)
- .map(|call| {
- let mut call = call.write().unwrap();
-
- call.region.clone_from(&event.region);
- call.ringing.clone_from(&event.ringing);
- });
-
- item
- }
-
- #[doc(hidden)]
pub fn update_with_channel_create(&mut self, event: &ChannelCreateEvent) -> Option<Channel> {
match event.channel {
Channel::Group(ref group) => {
@@ -833,23 +773,6 @@ impl Cache {
}
#[doc(hidden)]
- pub fn update_with_guild_sync(&mut self, event: &GuildSyncEvent) {
- for member in event.members.values() {
- self.update_user_entry(&member.user.read().unwrap());
- }
-
- self.guilds
- .get_mut(&event.guild_id)
- .map(|guild| {
- let mut guild = guild.write().unwrap();
-
- guild.large = event.large;
- guild.members.clone_from(&event.members);
- guild.presences.clone_from(&event.presences);
- });
- }
-
- #[doc(hidden)]
pub fn update_with_guild_unavailable(&mut self, event: &GuildUnavailableEvent) {
self.unavailable_guilds.insert(event.guild_id);
self.guilds.remove(&event.guild_id);
@@ -988,31 +911,6 @@ impl Cache {
return;
}
-
- if let Some(channel) = event.voice_state.channel_id {
- // channel id available, insert voice state
- if let Some(call) = self.calls.get_mut(&channel) {
- let mut call = call.write().unwrap();
-
- {
- let finding = call.voice_states
- .get_mut(&event.voice_state.user_id);
-
- if let Some(group_state) = finding {
- group_state.clone_from(&event.voice_state);
-
- return;
- }
- }
-
- call.voice_states.insert(event.voice_state.user_id, event.voice_state.clone());
- }
- } else {
- // delete this user from any group call containing them
- for call in self.calls.values_mut() {
- call.write().unwrap().voice_states.remove(&event.voice_state.user_id);
- }
- }
}
// Adds or updates a user entry in the [`users`] map with a received user.
@@ -1033,7 +931,6 @@ impl Cache {
impl Default for Cache {
fn default() -> Cache {
Cache {
- calls: HashMap::default(),
channels: HashMap::default(),
groups: HashMap::default(),
guilds: HashMap::default(),
diff --git a/src/ext/voice/connection_info.rs b/src/ext/voice/connection_info.rs
index 282b5f1..d0364ce 100644
--- a/src/ext/voice/connection_info.rs
+++ b/src/ext/voice/connection_info.rs
@@ -1,10 +1,10 @@
-use ::model::UserId;
+use ::model::{GuildId, UserId};
#[derive(Clone, Debug)]
pub struct ConnectionInfo {
pub endpoint: String,
+ pub guild_id: GuildId,
pub session_id: String,
- pub target_id: u64,
pub token: String,
pub user_id: UserId,
}
diff --git a/src/ext/voice/handler.rs b/src/ext/voice/handler.rs
index 0ef518a..cb5838c 100644
--- a/src/ext/voice/handler.rs
+++ b/src/ext/voice/handler.rs
@@ -2,7 +2,7 @@ use serde_json::builder::ObjectBuilder;
use std::sync::mpsc::{self, Sender as MpscSender};
use super::{AudioReceiver, AudioSource};
use super::connection_info::ConnectionInfo;
-use super::{Status as VoiceStatus, Target};
+use super::Status as VoiceStatus;
use ::client::gateway::GatewayStatus;
use ::constants::VoiceOpCode;
use ::model::{ChannelId, GuildId, UserId, VoiceState};
@@ -59,7 +59,7 @@ pub struct Handler {
///
/// [`Call`]: ../../model/struct.Call.html
/// [`Group`]: ../../model/struct.Group.html
- pub guild_id: Option<GuildId>,
+ pub guild_id: GuildId,
/// Whether the current handler is set to deafen voice connections.
///
/// **Note**: This _must not_ be manually mutated. Call [`deafen`] to
@@ -114,8 +114,8 @@ impl Handler {
/// [`Manager::join`]: struct.Manager.html#method.join
#[doc(hidden)]
#[inline]
- pub fn new(target: Target, ws: MpscSender<GatewayStatus>, user_id: UserId) -> Self {
- Self::new_raw(target, Some(ws), user_id)
+ pub fn new(guild_id: GuildId, ws: MpscSender<GatewayStatus>, user_id: UserId) -> Self {
+ Self::new_raw(guild_id, Some(ws), user_id)
}
/// Creates a new, standalone Handler which is not connected to the primary
@@ -128,8 +128,8 @@ impl Handler {
/// For most use cases you do not want this. Only use it if you are using
/// the voice component standalone from the rest of the library.
#[inline]
- pub fn standalone(target: Target, user_id: UserId) -> Self {
- Self::new_raw(target, None, user_id)
+ pub fn standalone(guild_id: GuildId, user_id: UserId) -> Self {
+ Self::new_raw(guild_id, None, user_id)
}
/// Connects to the voice channel if the following are present:
@@ -154,29 +154,19 @@ impl Handler {
return false;
}
- let target_id = if let Some(guild_id) = self.guild_id {
- guild_id.0
- } else if let Some(channel_id) = self.channel_id {
- channel_id.0
- } else {
- // Theoretically never happens? This needs to be researched more.
- error!("(╯°□°)╯︵ ┻━┻ No guild/channel ID when connecting");
-
- return false;
- };
-
- // Safe as all of these being present was already checked.
let endpoint = self.endpoint.clone().unwrap();
+ let guild_id = self.guild_id;
let session_id = self.session_id.clone().unwrap();
let token = self.token.clone().unwrap();
let user_id = self.user_id;
+ // Safe as all of these being present was already checked.
self.send(VoiceStatus::Connect(ConnectionInfo {
- endpoint: endpoint,
- session_id: session_id,
- target_id: target_id,
- token: token,
- user_id: user_id,
+ endpoint,
+ guild_id,
+ session_id,
+ token,
+ user_id,
}));
true
@@ -368,18 +358,13 @@ impl Handler {
}
}
- fn new_raw(target: Target, ws: Option<MpscSender<GatewayStatus>>, user_id: UserId) -> Self {
+ fn new_raw(guild_id: GuildId, ws: Option<MpscSender<GatewayStatus>>, user_id: UserId) -> Self {
let (tx, rx) = mpsc::channel();
- let (channel_id, guild_id) = match target {
- Target::Channel(channel_id) => (Some(channel_id), None),
- Target::Guild(guild_id) => (None, Some(guild_id)),
- };
-
- threading::start(target, rx);
+ threading::start(guild_id, rx);
Handler {
- channel_id: channel_id,
+ channel_id: None,
endpoint: None,
guild_id: guild_id,
self_deaf: false,
@@ -401,7 +386,7 @@ impl Handler {
self.sender = tx;
self.sender.send(status).unwrap();
- threading::start(Target::Guild(self.guild_id.unwrap()), rx);
+ threading::start(self.guild_id, rx);
self.update();
}
@@ -428,7 +413,7 @@ impl Handler {
.insert("op", VoiceOpCode::SessionDescription.num())
.insert_object("d", |o| o
.insert("channel_id", self.channel_id.map(|c| c.0))
- .insert("guild_id", self.guild_id.map(|g| g.0))
+ .insert("guild_id", self.guild_id.0)
.insert("self_deaf", self.self_deaf)
.insert("self_mute", self.self_mute))
.build();
diff --git a/src/ext/voice/manager.rs b/src/ext/voice/manager.rs
index 44530c1..4ba7bfb 100644
--- a/src/ext/voice/manager.rs
+++ b/src/ext/voice/manager.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::sync::mpsc::Sender as MpscSender;
-use super::{Handler, Target};
+use super::Handler;
use ::client::gateway::GatewayStatus;
use ::model::{ChannelId, GuildId, UserId};
@@ -21,7 +21,7 @@ use ::model::{ChannelId, GuildId, UserId};
/// [guild's channel]: ../../model/enum.ChannelType.html#variant.Voice
/// [WebSocket connection]: ../../client/struct.Connection.html
pub struct Manager {
- handlers: HashMap<Target, Handler>,
+ handlers: HashMap<GuildId, Handler>,
user_id: UserId,
ws: MpscSender<GatewayStatus>,
}
@@ -37,8 +37,8 @@ impl Manager {
}
/// Retrieves a mutable handler for the given target, if one exists.
- pub fn get<T: Into<Target>>(&mut self, target_id: T) -> Option<&mut Handler> {
- self.handlers.get_mut(&target_id.into())
+ pub fn get<G: Into<GuildId>>(&mut self, guild_id: G) -> Option<&mut Handler> {
+ self.handlers.get_mut(&guild_id.into())
}
/// Connects to a target by retrieving its relevant [`Handler`] and
@@ -63,45 +63,33 @@ impl Manager {
/// [`Handler`]: struct.Handler.html
/// [`get`]: #method.get
#[allow(map_entry)]
- pub fn join(&mut self, guild_id: Option<GuildId>, channel_id: ChannelId) -> &mut Handler {
- if let Some(guild_id) = guild_id {
- let target = Target::Guild(guild_id);
+ pub fn join<C, G>(&mut self, guild_id: G, channel_id: C) -> &mut Handler
+ where C: Into<ChannelId>, G: Into<GuildId> {
+ let channel_id = channel_id.into();
+ let guild_id = guild_id.into();
- {
- let mut found = false;
+ {
+ let mut found = false;
- if let Some(handler) = self.handlers.get_mut(&target) {
- handler.switch_to(channel_id);
+ if let Some(handler) = self.handlers.get_mut(&guild_id) {
+ handler.switch_to(channel_id);
- found = true;
- }
-
- if found {
- // Actually safe, as the key has already been found above.
- return self.handlers.get_mut(&target).unwrap();
- }
+ found = true;
}
- let mut handler = Handler::new(target, self.ws.clone(), self.user_id);
- handler.join(channel_id);
-
- self.handlers.insert(target, handler);
-
- // Actually safe, as the key would have been inserted above.
- self.handlers.get_mut(&target).unwrap()
- } else {
- let target = Target::Channel(channel_id);
+ if found {
+ // Actually safe, as the key has already been found above.
+ return self.handlers.get_mut(&guild_id).unwrap();
+ }
+ }
- if !self.handlers.contains_key(&target) {
- let mut handler = Handler::new(target, self.ws.clone(), self.user_id);
- handler.join(channel_id);
+ let mut handler = Handler::new(guild_id, self.ws.clone(), self.user_id);
+ handler.join(channel_id);
- self.handlers.insert(target, handler);
- }
+ self.handlers.insert(guild_id, handler);
- // Actually safe, as the key would have been inserted above.
- self.handlers.get_mut(&target).unwrap()
- }
+ // Actually safe, as the key would have been inserted above.
+ self.handlers.get_mut(&guild_id).unwrap()
}
/// Retrieves the [handler][`Handler`] for the given target and leaves the
@@ -115,10 +103,8 @@ impl Manager {
/// [`Handler`]: struct.Handler.html
/// [`get`]: #method.get
/// [`leave`]: struct.Handler.html#method.leave
- pub fn leave<T: Into<Target>>(&mut self, target_id: T) {
- let target = target_id.into();
-
- if let Some(handler) = self.handlers.get_mut(&target) {
+ pub fn leave<G: Into<GuildId>>(&mut self, guild_id: G) {
+ if let Some(handler) = self.handlers.get_mut(&guild_id.into()) {
handler.leave();
}
}
@@ -129,11 +115,11 @@ impl Manager {
/// The handler is then dropped, removing settings for the target.
///
/// [`Handler`]: struct.Handler.html
- pub fn remove<T: Into<Target>>(&mut self, target_id: T) {
- let target = target_id.into();
+ pub fn remove<G: Into<GuildId>>(&mut self, guild_id: G) {
+ let guild_id = guild_id.into();
- self.leave(target);
+ self.leave(guild_id);
- self.handlers.remove(&target);
+ self.handlers.remove(&guild_id);
}
}
diff --git a/src/ext/voice/mod.rs b/src/ext/voice/mod.rs
index 9ccb1d9..94e3b40 100644
--- a/src/ext/voice/mod.rs
+++ b/src/ext/voice/mod.rs
@@ -17,7 +17,6 @@ pub use self::manager::Manager;
pub use self::streamer::{ffmpeg, pcm, ytdl};
use self::connection_info::ConnectionInfo;
-use ::model::{ChannelId, GuildId};
const CRYPTO_MODE: &'static str = "xsalsa20_poly1305";
@@ -28,33 +27,3 @@ pub enum Status {
SetReceiver(Option<Box<AudioReceiver>>),
SetSender(Option<Box<AudioSource>>),
}
-
-/// Denotes the target to manage a connection for.
-///
-/// For most cases, targets should entirely be guilds, except for the one case
-/// where a user account can be in a 1-to-1 or group call.
-///
-/// It _may_ be possible in the future for bots to be in multiple groups. If
-/// this turns out to be the case, supporting that now rather than messily in
-/// the future is the best option. Thus, these types of calls are specified by
-/// the group's channel Id.
-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
-pub enum Target {
- /// Used for managing a voice handler for a 1-on-1 (user-to-user) or group
- /// call.
- Channel(ChannelId),
- /// Used for managing a voice handler for a guild.
- Guild(GuildId),
-}
-
-impl From<ChannelId> for Target {
- fn from(channel_id: ChannelId) -> Target {
- Target::Channel(channel_id)
- }
-}
-
-impl From<GuildId> for Target {
- fn from(guild_id: GuildId) -> Target {
- Target::Guild(guild_id)
- }
-}
diff --git a/src/ext/voice/payload.rs b/src/ext/voice/payload.rs
index 5086b08..964d6d2 100644
--- a/src/ext/voice/payload.rs
+++ b/src/ext/voice/payload.rs
@@ -8,7 +8,7 @@ pub fn build_identify(info: &ConnectionInfo) -> Value {
ObjectBuilder::new()
.insert("op", VoiceOpCode::Identify.num())
.insert_object("d", |o| o
- .insert("server_id", info.target_id)
+ .insert("server_id", info.guild_id.0)
.insert("session_id", &info.session_id)
.insert("token", &info.token)
.insert("user_id", info.user_id.0))
diff --git a/src/ext/voice/threading.rs b/src/ext/voice/threading.rs
index 0aaafba..3986f48 100644
--- a/src/ext/voice/threading.rs
+++ b/src/ext/voice/threading.rs
@@ -1,19 +1,17 @@
use std::sync::mpsc::{Receiver as MpscReceiver, TryRecvError};
use std::thread::Builder as ThreadBuilder;
use super::connection::Connection;
-use super::{Status, Target};
+use super::Status;
use ::internal::Timer;
+use ::model::GuildId;
-pub fn start(target_id: Target, rx: MpscReceiver<Status>) {
- let name = match target_id {
- Target::Channel(channel_id) => format!("Serenity Voice (C{})", channel_id),
- Target::Guild(guild_id) => format!("Serenity Voice (G{})", guild_id),
- };
+pub fn start(guild_id: GuildId, rx: MpscReceiver<Status>) {
+ let name = format!("Serenity Voice (G{})", guild_id);
ThreadBuilder::new()
.name(name)
.spawn(move || runner(rx))
- .expect(&format!("[Voice] Error starting target: {:?}", target_id));
+ .expect(&format!("[Voice] Error starting guild: {:?}", guild_id));
}
fn runner(rx: MpscReceiver<Status>) {
diff --git a/src/model/event.rs b/src/model/event.rs
index a39fa2a..f57cb55 100644
--- a/src/model/event.rs
+++ b/src/model/event.rs
@@ -9,110 +9,6 @@ use ::utils::decode_array;
type Map = BTreeMap<String, Value>;
-/// Event data for the call creation event.
-///
-/// This is fired when:
-///
-/// - a [`Call`] in a [`Group`] is created
-/// - a [`Call`] in a [`PrivateChannel`] is created
-///
-/// [`Call`]: ../struct.Call.html
-/// [`Group`]: ../struct.Group.html
-/// [`PrivateChannel`]: ../struct.PrivateChannel.html
-#[derive(Clone, Debug)]
-pub struct CallCreateEvent {
- /// Information about the created call.
- pub call: Call,
-}
-
-impl CallCreateEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(map: Map) -> Result<Self> {
- Ok(CallCreateEvent {
- call: Call::decode(Value::Object(map))?,
- })
- }
-}
-
-/// Event data for the call deletion event.
-///
-/// This is fired when:
-///
-/// - A [`Call`] in a [`Group`] has ended
-/// - A [`Call`] in a [`PrivateChannel`] has ended
-///
-/// [`Call`]: ../struct.Call.html
-/// [`Group`]: ../struct.Group.html
-/// [`PrivateChannel`]: ../struct.PrivateChannel.html
-#[derive(Clone, Debug)]
-pub struct CallDeleteEvent {
- /// The Id of the [`Channel`] that the call took place in.
- ///
- /// [`Channel`]: ../enum.Channel.html
- pub channel_id: ChannelId,
-}
-
-impl CallDeleteEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(CallDeleteEvent {
- channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?,
- })
- }
-}
-
-/// Event data for the call update event.
-///
-/// This is fired when:
-///
-/// - A member of a [`Group`] has been rung
-/// - The voice [`region`] of the [`Call`] has been updated
-///
-/// [`Call`]: ../struct.Call.html
-/// [`Group`]: ../srruct.Group.html
-/// [`region`]: #structfield.region
-#[derive(Clone, Debug)]
-pub struct CallUpdateEvent {
- /// The Id of the [channel][`Channel`] that the [call][`Call`] is taking
- /// place in.
- ///
- /// [`Call`]: ../struct.Call.html
- /// [`Channel`]: ../enum.Channel.html
- pub channel_id: ChannelId,
- /// The Id in the [channel][`Channel`] - mapped by the [`channel_id`] -
- /// denoting the beginning of the [call][`Call`].
- ///
- /// [`Channel`]: ../enum.Channel.html
- /// [`Call`]: ../struct.Call.html
- /// [`channel_id`]: #structfield.channel_id
- pub message_id: MessageId,
- /// The voice region that the [call][`Call`] is hosted in.
- ///
- /// [`Call`]: ../struct.Call.html
- pub region: String,
- /// A list of [user][`User`]s currently being rung who have not declined or
- /// accepted the [call][`Call`].
- ///
- /// [`Call`]: ../struct.Call.html
- /// [`User`]: ../struct.User.html
- pub ringing: Vec<UserId>,
-}
-
-impl CallUpdateEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(CallUpdateEvent {
- channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?,
- message_id: remove(&mut map, "message_id").and_then(MessageId::decode)?,
- region: remove(&mut map, "region").and_then(into_string)?,
- ringing: decode_array(remove(&mut map, "ringing")?, UserId::decode)?,
- })
- }
-}
-
/// Event data for the channel creation event.
///
/// This is fired when:
@@ -464,27 +360,6 @@ impl GuildRoleUpdateEvent {
}
#[derive(Clone, Debug)]
-pub struct GuildSyncEvent {
- pub guild_id: GuildId,
- pub large: bool,
- pub members: HashMap<UserId, Member>,
- pub presences: HashMap<UserId, Presence>,
-}
-
-impl GuildSyncEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(GuildSyncEvent {
- guild_id: remove(&mut map, "id").and_then(GuildId::decode)?,
- large: req!(remove(&mut map, "large")?.as_bool()),
- members: remove(&mut map, "members").and_then(decode_members)?,
- presences: remove(&mut map, "presences").and_then(decode_presences)?,
- })
- }
-}
-
-#[derive(Clone, Debug)]
pub struct GuildUnavailableEvent {
pub guild_id: GuildId,
}
@@ -862,27 +737,6 @@ impl GatewayEvent {
#[allow(large_enum_variant)]
#[derive(Clone, Debug)]
pub enum Event {
- /// A new [`Call`] has been created.
- ///
- /// Fires the [`Client::on_call_create`] event.
- ///
- /// [`Call`]: ../struct.Call.html
- /// [`Client::on_call_create`]: ../../client/struct.Client.html#on_call_create
- CallCreate(CallCreateEvent),
- /// A [`Call`] has ended.
- ///
- /// Fires the [`Client::on_call_delete`] event.
- ///
- /// [`Call`]: ../struct.Call.html
- /// [`Client::on_call_delete`]: ../../client/struct.Client.html#method.on_call_delete
- CallDelete(CallDeleteEvent),
- /// A [`Call`] was updated.
- ///
- /// Fires the [`Client::on_call_update`] event.
- ///
- /// [`Call`]: ../struct.Call.html
- /// [`Client::on_call_update`]: ../../client/struct.Client.html#method.on_call_update
- CallUpdate(CallUpdateEvent),
/// A [`Channel`] was created.
///
/// Fires the [`Client::on_channel_create`] event.
@@ -945,7 +799,6 @@ pub enum Event {
GuildRoleCreate(GuildRoleCreateEvent),
GuildRoleDelete(GuildRoleDeleteEvent),
GuildRoleUpdate(GuildRoleUpdateEvent),
- GuildSync(GuildSyncEvent),
/// When a guild is unavailable, such as due to a Discord server outage.
GuildUnavailable(GuildUnavailableEvent),
GuildUpdate(GuildUpdateEvent),
@@ -1011,9 +864,6 @@ impl Event {
let mut value = into_map(value)?;
Ok(match &kind[..] {
- "CALL_CREATE" => Event::CallCreate(CallCreateEvent::decode(value)?),
- "CALL_DELETE" => Event::CallDelete(CallDeleteEvent::decode(value)?),
- "CALL_UPDATE" => Event::CallUpdate(CallUpdateEvent::decode(value)?),
"CHANNEL_CREATE" => Event::ChannelCreate(ChannelCreateEvent::decode(value)?),
"CHANNEL_DELETE" => Event::ChannelDelete(ChannelDeleteEvent::decode(value)?),
"CHANNEL_PINS_ACK" => Event::ChannelPinsAck(ChannelPinsAckEvent::decode(value)?),
@@ -1046,7 +896,6 @@ impl Event {
"GUILD_ROLE_CREATE" => Event::GuildRoleCreate(GuildRoleCreateEvent::decode(value)?),
"GUILD_ROLE_DELETE" => Event::GuildRoleDelete(GuildRoleDeleteEvent::decode(value)?),
"GUILD_ROLE_UPDATE" => Event::GuildRoleUpdate(GuildRoleUpdateEvent::decode(value)?),
- "GUILD_SYNC" => Event::GuildSync(GuildSyncEvent::decode(value)?),
"GUILD_UPDATE" => Event::GuildUpdate(GuildUpdateEvent::decode(value)?),
"MESSAGE_CREATE" => Event::MessageCreate(MessageCreateEvent::decode(value)?),
"MESSAGE_DELETE" => Event::MessageDelete(MessageDeleteEvent::decode(value)?),