Gateway: Generic Shard and Twilight v0.8 Support (#109)

This PR adds support for twilight v0.8, mainly adapting to significant API changes introduced by v0.7. As a result of these, twilight no longer accepts arbitrary JSON input, so it seemed sensible to adapt our `Shard` design to no longer require the same.

Adding to this, I've added in a trait to allow an arbitrary `Shard` to be installed, given only an implementation of a method to send a `VoiceStateUpdate`. Together, `Sharder::Generic` (songbird::shards::VoiceUpdate) and `Shard::Generic` (songbird::shards::GenericSharder) should allow any library to be hooked in to Songbird.

This PR was tested using `cargo make ready` and by manually testing `examples/twilight`.
This commit is contained in:
Kyle Simpson
2022-01-13 12:17:41 +00:00
parent 12c76a9046
commit b4ce84546b
9 changed files with 187 additions and 54 deletions

View File

@@ -87,7 +87,7 @@ impl Songbird {
/// [`process`].
///
/// [`process`]: Songbird::process
pub fn twilight<U>(cluster: Cluster, user_id: U) -> Self
pub fn twilight<U>(cluster: Arc<Cluster>, user_id: U) -> Self
where
U: Into<UserId>,
{
@@ -102,7 +102,7 @@ impl Songbird {
/// [`process`].
///
/// [`process`]: Songbird::process
pub fn twilight_from_config<U>(cluster: Cluster, user_id: U, config: Config) -> Self
pub fn twilight_from_config<U>(cluster: Arc<Cluster>, user_id: U, config: Config) -> Self
where
U: Into<UserId>,
{
@@ -117,7 +117,7 @@ impl Songbird {
user_id: user_id.into(),
}),
calls: Default::default(),
sharder: Sharder::Twilight(cluster),
sharder: Sharder::TwilightCluster(cluster),
config: Some(config).into(),
}
}
@@ -378,7 +378,7 @@ impl Songbird {
}
},
TwilightEvent::VoiceStateUpdate(v) => {
if v.0.user_id.0 != self.client_data.read().user_id.0 {
if v.0.user_id.0.get() != self.client_data.read().user_id.0 {
return;
}