rearragned some locks
This commit is contained in:
parent
725b9fe5c5
commit
1f01b98ed9
23
src/main.rs
23
src/main.rs
@ -322,9 +322,10 @@ SELECT join_sound_id
|
|||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match join_id_res {
|
if let Ok(join_id_record) = join_id_res {
|
||||||
Ok(join_id_record) => {
|
|
||||||
let join_id = join_id_record.join_sound_id;
|
let join_id = join_id_record.join_sound_id;
|
||||||
|
|
||||||
let mut sound = sqlx::query_as_unchecked!(
|
let mut sound = sqlx::query_as_unchecked!(
|
||||||
Sound,
|
Sound,
|
||||||
"
|
"
|
||||||
@ -340,20 +341,17 @@ SELECT name, id, plays, public, server_id, uploader_id
|
|||||||
let voice_manager_lock = ctx.data.read().await
|
let voice_manager_lock = ctx.data.read().await
|
||||||
.get::<VoiceManager>().cloned().expect("Could not get VoiceManager from data");
|
.get::<VoiceManager>().cloned().expect("Could not get VoiceManager from data");
|
||||||
|
|
||||||
let mut voice_manager = voice_manager_lock.lock().await;
|
|
||||||
|
|
||||||
let voice_guilds_lock = ctx.data.read().await
|
let voice_guilds_lock = ctx.data.read().await
|
||||||
.get::<VoiceGuilds>().cloned().expect("Could not get VoiceGuilds from data");
|
.get::<VoiceGuilds>().cloned().expect("Could not get VoiceGuilds from data");
|
||||||
|
|
||||||
let voice_guilds = voice_guilds_lock.lock().await;
|
let voice_guilds = voice_guilds_lock.lock().await;
|
||||||
|
|
||||||
|
let mut voice_manager = voice_manager_lock.lock().await;
|
||||||
|
|
||||||
if let Some(handler) = voice_manager.join(guild_id, user_channel) {
|
if let Some(handler) = voice_manager.join(guild_id, user_channel) {
|
||||||
let _audio = play_audio(&mut sound, guild_data, handler, voice_guilds, pool).await;
|
let _audio = play_audio(&mut sound, guild_data, handler, voice_guilds, pool).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,12 +489,15 @@ async fn disconnect_from_inactive(voice_manager_mutex: Arc<SerenityMutex<ClientV
|
|||||||
time::delay_for(Duration::from_secs(wait_time)).await;
|
time::delay_for(Duration::from_secs(wait_time)).await;
|
||||||
|
|
||||||
let mut voice_guilds_acquired = voice_guilds.lock().await;
|
let mut voice_guilds_acquired = voice_guilds.lock().await;
|
||||||
let mut voice_manager = voice_manager_mutex.lock().await;
|
|
||||||
|
|
||||||
let mut to_remove = HashSet::new();
|
let mut to_remove = HashSet::new();
|
||||||
|
|
||||||
for (guild, ticker) in voice_guilds_acquired.iter_mut() {
|
for (guild, ticker) in voice_guilds_acquired.iter_mut() {
|
||||||
|
|
||||||
if *ticker == 0 {
|
if *ticker == 0 {
|
||||||
|
|
||||||
|
let mut voice_manager = voice_manager_mutex.lock().await;
|
||||||
|
|
||||||
let manager_opt = voice_manager.get_mut(guild);
|
let manager_opt = voice_manager.get_mut(guild);
|
||||||
|
|
||||||
if let Some(manager) = manager_opt {
|
if let Some(manager) = manager_opt {
|
||||||
@ -504,9 +505,11 @@ async fn disconnect_from_inactive(voice_manager_mutex: Arc<SerenityMutex<ClientV
|
|||||||
}
|
}
|
||||||
to_remove.insert(guild.clone());
|
to_remove.insert(guild.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
*ticker -= 1;
|
*ticker -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for val in to_remove.iter() {
|
for val in to_remove.iter() {
|
||||||
@ -554,8 +557,6 @@ async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||||||
let voice_manager_lock = ctx.data.read().await
|
let voice_manager_lock = ctx.data.read().await
|
||||||
.get::<VoiceManager>().cloned().expect("Could not get VoiceManager from data");
|
.get::<VoiceManager>().cloned().expect("Could not get VoiceManager from data");
|
||||||
|
|
||||||
let mut voice_manager = voice_manager_lock.lock().await;
|
|
||||||
|
|
||||||
let voice_guilds_lock = ctx.data.read().await
|
let voice_guilds_lock = ctx.data.read().await
|
||||||
.get::<VoiceGuilds>().cloned().expect("Could not get VoiceGuilds from data");
|
.get::<VoiceGuilds>().cloned().expect("Could not get VoiceGuilds from data");
|
||||||
|
|
||||||
@ -563,6 +564,8 @@ async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||||||
|
|
||||||
let guild_data = GuildData::get_from_id(guild, pool.clone()).await.unwrap();
|
let guild_data = GuildData::get_from_id(guild, pool.clone()).await.unwrap();
|
||||||
|
|
||||||
|
let mut voice_manager = voice_manager_lock.lock().await;
|
||||||
|
|
||||||
match voice_manager.join(guild_id, user_channel) {
|
match voice_manager.join(guild_id, user_channel) {
|
||||||
Some(handler) => {
|
Some(handler) => {
|
||||||
play_audio(sound, guild_data, handler, voice_guilds, pool).await?;
|
play_audio(sound, guild_data, handler, voice_guilds, pool).await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user