moved disconnect loop to new thread to hopefully prevent shards dying

This commit is contained in:
jude-lafitteIII 2020-06-05 17:43:03 +01:00
parent 461326be30
commit 7cbbe5c354

View File

@ -145,8 +145,6 @@ async fn role_check(ctx: &Context, msg: &Message, _args: &mut Args) -> CheckResu
.collect::<Vec<String>>()
.join(", ");
println!("{}", user_roles);
let guild_id = *msg.guild_id.unwrap().as_u64();
let role_res = sqlx::query!(
@ -394,15 +392,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cvm = Arc::clone(&client.voice_manager);
tokio::spawn(async {
let disconnect_cycle_delay = env::var("DISCONNECT_CYCLE_DELAY")
.unwrap_or("300".to_string())
.parse::<u64>()?;
.parse::<u64>().expect("DISCONNECT_CYCLE_DELAY invalid");
// select on the client and client auto disconnector (when the client terminates, terminate the disconnector
tokio::select! {
_ = client.start_autosharded() => {}
_ = disconnect_from_inactive(cvm, voice_guilds, disconnect_cycle_delay) => {}
};
disconnect_from_inactive(cvm, voice_guilds, disconnect_cycle_delay).await
});
client.start_autosharded().await?;
Ok(())
}