Fix potential issue where bot doesn't leave automatically

main
DaXcess 2022-11-10 16:38:53 +01:00
parent 854724b389
commit 78962772e7
3 changed files with 19 additions and 1 deletions

View File

@ -112,6 +112,7 @@ async fn main() {
_ = tokio::time::sleep(std::time::Duration::from_secs(60)) => {
let guild_count = cache.guilds().len();
let active_count = session_manager.get_active_session_count().await;
let total_count = session_manager.get_session_count().await;
if let Err(why) = stats_manager.set_server_count(guild_count) {
error!("Failed to update server count: {}", why);
@ -122,7 +123,15 @@ async fn main() {
}
// Yes, I like to handle my s's when I'm working with amounts
debug!("Updated stats: {} guild{}, {} active session{}", guild_count, if guild_count == 1 { "" } else { "s" }, active_count, if active_count == 1 { "" } else { "s" });
debug!(
"Updated stats: {} guild{}, {} active session{}, {} total session{}",
guild_count,
if guild_count == 1 { "" } else { "s" },
active_count,
if active_count == 1 { "" } else { "s" },
total_count,
if total_count == 1 { "" } else { "s" }
);
}
_ = tokio::signal::ctrl_c() => {

View File

@ -108,6 +108,13 @@ impl SessionManager {
sessions.get(&guild_id).cloned()
}
/// Get the amount of sessions
pub async fn get_session_count(&self) -> usize {
let sessions = self.sessions.read().await;
sessions.len()
}
/// Get the amount of sessions with an owner
pub async fn get_active_session_count(&self) -> usize {
let sessions = self.sessions.read().await;

View File

@ -306,6 +306,8 @@ impl SpoticordSession {
IpcPacket::Stopped => {
check_result(ipc_track.pause());
ipc_instance.playback_info.write().await.take();
ipc_instance.start_disconnect_timer().await;
}