Nah that didn't work, here's some auto-disconnect bugfixes
parent
d93758e250
commit
4a90cb8718
|
@ -531,9 +531,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.0.0"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
|
||||
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
|
@ -2400,9 +2400,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.28"
|
||||
version = "0.3.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48"
|
||||
checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
|
@ -2413,15 +2413,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.14"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572"
|
||||
checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
|
||||
dependencies = [
|
||||
"time-core",
|
||||
]
|
||||
|
|
|
@ -318,13 +318,13 @@ impl PlayerTask {
|
|||
match pbi.as_mut() {
|
||||
Some(pbi) => {
|
||||
pbi.update_track(spotify_id, current);
|
||||
pbi.update_pos_dur(position_ms, duration_ms, true);
|
||||
pbi.update_pos_dur(position_ms, duration_ms, playing);
|
||||
}
|
||||
None => {
|
||||
*pbi = Some(PlaybackInfo::new(
|
||||
duration_ms,
|
||||
position_ms,
|
||||
true,
|
||||
playing,
|
||||
current,
|
||||
spotify_id,
|
||||
));
|
||||
|
|
|
@ -56,11 +56,9 @@ impl InnerSessionManager {
|
|||
session: SpoticordSession,
|
||||
guild_id: GuildId,
|
||||
owner_id: UserId,
|
||||
) -> Result<(), SessionCreateError> {
|
||||
) {
|
||||
self.sessions.insert(guild_id, session);
|
||||
self.owner_map.insert(owner_id, guild_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a session
|
||||
|
@ -147,7 +145,9 @@ impl SessionManager {
|
|||
.write()
|
||||
.await
|
||||
.create_session(session, guild_id, owner_id)
|
||||
.await
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a session
|
||||
|
|
|
@ -24,7 +24,7 @@ use songbird::{
|
|||
create_player,
|
||||
input::{Codec, Container, Input, Reader},
|
||||
tracks::TrackHandle,
|
||||
Call, Event, EventContext, EventHandler, Songbird,
|
||||
Call, Event, EventContext, EventHandler,
|
||||
};
|
||||
use std::{
|
||||
ops::{Deref, DerefMut},
|
||||
|
@ -36,6 +36,12 @@ use tokio::sync::{Mutex, RwLockReadGuard, RwLockWriteGuard};
|
|||
#[derive(Clone)]
|
||||
pub struct SpoticordSession(Arc<RwLock<InnerSpoticordSession>>);
|
||||
|
||||
impl Drop for SpoticordSession {
|
||||
fn drop(&mut self) {
|
||||
log::trace!("drop SpoticordSession");
|
||||
}
|
||||
}
|
||||
|
||||
struct InnerSpoticordSession {
|
||||
owner: Option<UserId>,
|
||||
guild_id: GuildId,
|
||||
|
@ -46,7 +52,6 @@ struct InnerSpoticordSession {
|
|||
|
||||
session_manager: SessionManager,
|
||||
|
||||
songbird: Arc<Songbird>,
|
||||
call: Arc<Mutex<Call>>,
|
||||
track: Option<TrackHandle>,
|
||||
player: Option<Player>,
|
||||
|
@ -90,7 +95,6 @@ impl SpoticordSession {
|
|||
text_channel_id,
|
||||
http: ctx.http.clone(),
|
||||
session_manager: session_manager.clone(),
|
||||
songbird: songbird.clone(),
|
||||
call: call.clone(),
|
||||
track: None,
|
||||
player: None,
|
||||
|
@ -342,6 +346,8 @@ impl SpoticordSession {
|
|||
timer.tick().await;
|
||||
timer.tick().await;
|
||||
|
||||
trace!("Ring ring, time to check :)");
|
||||
|
||||
// Make sure this task has not been aborted, if it has this will automatically stop execution.
|
||||
tokio::task::yield_now().await;
|
||||
|
||||
|
@ -351,6 +357,8 @@ impl SpoticordSession {
|
|||
.map(|pbi| pbi.is_playing)
|
||||
.unwrap_or(false);
|
||||
|
||||
trace!("is_playing = {is_playing}");
|
||||
|
||||
if !is_playing {
|
||||
info!("Player is not playing, disconnecting");
|
||||
session
|
||||
|
@ -511,9 +519,13 @@ impl InnerSpoticordSession {
|
|||
}
|
||||
};
|
||||
|
||||
if let Err(why) = self.songbird.remove(self.guild_id).await {
|
||||
let mut call = self.call.lock().await;
|
||||
|
||||
if let Err(why) = call.leave().await {
|
||||
error!("Failed to leave voice channel: {:?}", why);
|
||||
}
|
||||
|
||||
call.remove_all_global_events();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -523,10 +535,12 @@ impl EventHandler for SpoticordSession {
|
|||
match ctx {
|
||||
EventContext::DriverDisconnect(_) => {
|
||||
debug!("Driver disconnected, leaving voice channel");
|
||||
trace!("Arc strong count: {}", Arc::strong_count(&self.0));
|
||||
self.disconnect().await;
|
||||
}
|
||||
EventContext::ClientDisconnect(who) => {
|
||||
trace!("Client disconnected, {}", who.user_id.to_string());
|
||||
trace!("Arc strong count: {}", Arc::strong_count(&self.0));
|
||||
|
||||
if let Some(session) = self
|
||||
.session_manager()
|
||||
|
@ -547,3 +561,9 @@ impl EventHandler for SpoticordSession {
|
|||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for InnerSpoticordSession {
|
||||
fn drop(&mut self) {
|
||||
log::trace!("drop InnerSpoticordSession");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue