Skip to content

Commit

Permalink
Fix compiling on serenity next (serenity-rs#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored and FelixMcFelix committed Jan 6, 2024
1 parent f2bdd91 commit 201c4c2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rusty_pool = { optional = true, version = "0.7" }
serde = { version = "1", features = ["derive"] }
serde-aux = { optional = true, version = "4"}
serde_json = "1"
serenity = { default-features = false, optional = true, version = "0.12.0", features = ["voice", "gateway"] }
serenity = { default-features = false, optional = true, git = "https://github.com/serenity-rs/serenity", branch = "next", features = ["voice", "gateway"] }
serenity-voice-model = { optional = true, version = "0.2" }
simd-json = { features = ["serde_impl"], optional = true, version = "0.13" }
socket2 = { optional = true, version = "0.5" }
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resolver = "2"

[workspace.dependencies]
reqwest = "0.11"
serenity = { features = ["cache", "framework", "standard_framework", "voice", "http", "rustls_backend"], version = "0.12" }
serenity = { features = ["cache", "framework", "standard_framework", "voice", "http", "rustls_backend"], git = "https://github.com/serenity-rs/serenity", branch = "next" }
songbird = { path = "../", version = "0.4" }
symphonia = { features = ["aac", "mp3", "isomp4", "alac"], version = "0.5.2" }
tokio = { features = ["macros", "rt-multi-thread", "signal", "sync"], version = "1" }
Expand Down
16 changes: 9 additions & 7 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use serenity::{
voice::VoiceState,
},
};
#[cfg(feature = "serenity")]
use std::num::NonZeroU16;
use std::sync::{Arc, OnceLock};
use tokio::sync::Mutex;
#[cfg(feature = "serenity")]
Expand Down Expand Up @@ -415,16 +417,16 @@ impl Songbird {
#[cfg(feature = "serenity")]
#[async_trait]
impl VoiceGatewayManager for Songbird {
async fn initialise(&self, shard_count: u32, user_id: SerenityUser) {
async fn initialise(&self, shard_count: NonZeroU16, user_id: SerenityUser) {
debug!(
"Initialising Songbird for Serenity: ID {:?}, {} Shards",
user_id, shard_count
);
self.initialise_client_data(shard_count as u64, user_id);
self.initialise_client_data(shard_count.get() as u64, user_id);
debug!("Songbird ({:?}) Initialised!", user_id);
}

async fn register_shard(&self, shard_id: u32, sender: Sender<ShardRunnerMessage>) {
async fn register_shard(&self, shard_id: u16, sender: Sender<ShardRunnerMessage>) {
debug!(
"Registering Serenity shard handle {} with Songbird",
shard_id
Expand All @@ -433,7 +435,7 @@ impl VoiceGatewayManager for Songbird {
debug!("Registered shard handle {}.", shard_id);
}

async fn deregister_shard(&self, shard_id: u32) {
async fn deregister_shard(&self, shard_id: u16) {
debug!(
"Deregistering Serenity shard handle {} with Songbird",
shard_id
Expand All @@ -442,11 +444,11 @@ impl VoiceGatewayManager for Songbird {
debug!("Deregistered shard handle {}.", shard_id);
}

async fn server_update(&self, guild_id: SerenityGuild, endpoint: &Option<String>, token: &str) {
async fn server_update(&self, guild_id: SerenityGuild, endpoint: Option<&str>, token: &str) {
if let Some(call) = self.get(guild_id) {
let mut handler = call.lock().await;
if let Some(endpoint) = endpoint {
handler.update_server(endpoint.clone(), token.to_string());
handler.update_server(endpoint.to_string(), token.to_string());
}
}
}
Expand All @@ -460,7 +462,7 @@ impl VoiceGatewayManager for Songbird {

if let Some(call) = self.get(guild_id) {
let mut handler = call.lock().await;
handler.update_state(voice_state.session_id.clone(), voice_state.channel_id);
handler.update_state(voice_state.session_id.to_string(), voice_state.channel_id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/serenity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn register(client_builder: ClientBuilder) -> ClientBuilder {
/// This should be called after any uses of `ClientBuilder::type_map`.
pub fn register_with(client_builder: ClientBuilder, voice: Arc<Songbird>) -> ClientBuilder {
client_builder
.voice_manager_arc(voice.clone())
.voice_manager::<Songbird>(voice.clone())
.type_map_insert::<SongbirdKey>(voice)
}

Expand Down
14 changes: 7 additions & 7 deletions src/shards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Sharder {
match self {
#[cfg(feature = "serenity")]
Sharder::Serenity(s) => Some(Shard::Serenity(
s.get_or_insert_shard_handle(shard_id as u32),
s.get_or_insert_shard_handle(shard_id as u16),
)),
#[cfg(feature = "twilight")]
Sharder::Twilight(t) => Some(Shard::Twilight(t.clone(), shard_id)),
Expand All @@ -99,7 +99,7 @@ impl Sharder {
#[cfg(feature = "serenity")]
impl Sharder {
#[allow(unreachable_patterns)]
pub(crate) fn register_shard_handle(&self, shard_id: u32, sender: Sender<ShardRunnerMessage>) {
pub(crate) fn register_shard_handle(&self, shard_id: u16, sender: Sender<ShardRunnerMessage>) {
if let Sharder::Serenity(s) = self {
s.register_shard_handle(shard_id, sender);
} else {
Expand All @@ -108,7 +108,7 @@ impl Sharder {
}

#[allow(unreachable_patterns)]
pub(crate) fn deregister_shard_handle(&self, shard_id: u32) {
pub(crate) fn deregister_shard_handle(&self, shard_id: u16) {
if let Sharder::Serenity(s) = self {
s.deregister_shard_handle(shard_id);
} else {
Expand All @@ -123,22 +123,22 @@ impl Sharder {
///
/// This is updated and maintained by the library, and is designed to prevent
/// message loss during rebalances and reconnects.
pub struct SerenitySharder(DashMap<u32, Arc<SerenityShardHandle>>);
pub struct SerenitySharder(DashMap<u16, Arc<SerenityShardHandle>>);

#[cfg(feature = "serenity")]
impl SerenitySharder {
fn get_or_insert_shard_handle(&self, shard_id: u32) -> Arc<SerenityShardHandle> {
fn get_or_insert_shard_handle(&self, shard_id: u16) -> Arc<SerenityShardHandle> {
self.0.entry(shard_id).or_default().clone()
}

fn register_shard_handle(&self, shard_id: u32, sender: Sender<ShardRunnerMessage>) {
fn register_shard_handle(&self, shard_id: u16, sender: Sender<ShardRunnerMessage>) {
// Write locks are only used to add new entries to the map.
let handle = self.get_or_insert_shard_handle(shard_id);

handle.register(sender);
}

fn deregister_shard_handle(&self, shard_id: u32) {
fn deregister_shard_handle(&self, shard_id: u16) {
// Write locks are only used to add new entries to the map.
let handle = self.get_or_insert_shard_handle(shard_id);

Expand Down

0 comments on commit 201c4c2

Please sign in to comment.