|
@@ -38,6 +38,57 @@ async fn get_audio_state(ctx: &Context, msg: &Message) -> Option<Arc<AudioState>
|
|
|
let guild_id = guild.id;
|
|
|
|
|
|
let mut audio_states = AUDIO_STATES.lock().await;
|
|
|
+ let manager = songbird::get(ctx).await.unwrap();
|
|
|
+ let channel_id = guild
|
|
|
+ .voice_states
|
|
|
+ .get(&msg.author.id)
|
|
|
+ .and_then(|voice_state| voice_state.channel_id);
|
|
|
+
|
|
|
+ let channel_id = match channel_id {
|
|
|
+ Some(channel_id) => channel_id,
|
|
|
+ None => {
|
|
|
+ send_embed(ctx, msg, "Error: please be in a voice channel").await;
|
|
|
+ return None;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if let Some(call_locked) = manager.get(guild_id) {
|
|
|
+ let call = call_locked.lock().await;
|
|
|
+
|
|
|
+ if call.current_channel().is_none() {
|
|
|
+ drop(call);
|
|
|
+ match manager.remove(guild_id).await {
|
|
|
+ Ok(_) => {}
|
|
|
+ Err(err) => {
|
|
|
+ println!("Error leaving call: {:?}", err);
|
|
|
+ return None;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ audio_states.remove(&guild_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let call_lock = match manager.get(guild_id) {
|
|
|
+ Some(call) => call,
|
|
|
+ None => {
|
|
|
+ audio_states.remove(&guild_id);
|
|
|
+ match manager.join(guild_id, channel_id).await {
|
|
|
+ (call, Ok(_)) => call,
|
|
|
+ (_, Err(err)) => {
|
|
|
+ println!("Error joining call: {:?}", err);
|
|
|
+ return None;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ let mut call = call_lock.lock().await;
|
|
|
+
|
|
|
+ if call.current_channel() != Some(channel_id.into()) {
|
|
|
+ if let Err(err) = call.join(channel_id.into()).await {
|
|
|
+ println!("Error joining call: {:?}", err);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
match audio_states.get(&guild_id) {
|
|
|
Some(state) => {
|
|
@@ -46,27 +97,8 @@ async fn get_audio_state(ctx: &Context, msg: &Message) -> Option<Arc<AudioState>
|
|
|
Some(state)
|
|
|
}
|
|
|
None => {
|
|
|
- let channel_id = guild
|
|
|
- .voice_states
|
|
|
- .get(&msg.author.id)
|
|
|
- .and_then(|voice_state| voice_state.channel_id);
|
|
|
- let channel_id = match channel_id {
|
|
|
- Some(channel_id) => channel_id,
|
|
|
- None => {
|
|
|
- send_embed(ctx, msg, "Error: please be in a voice channel").await;
|
|
|
- return None;
|
|
|
- }
|
|
|
- };
|
|
|
- let manager = songbird::get(ctx).await.unwrap().clone();
|
|
|
- let (handle_lock, success) = manager.join(guild_id, channel_id).await;
|
|
|
- if let Err(err) = success {
|
|
|
- println!("Error: {:?}", err);
|
|
|
- return None;
|
|
|
- }
|
|
|
- let audio_state = AudioState::new(handle_lock, ctx, msg);
|
|
|
- {
|
|
|
- audio_states.insert(guild_id, audio_state.clone());
|
|
|
- }
|
|
|
+ let audio_state = AudioState::new(manager.get(guild_id).unwrap(), ctx, msg);
|
|
|
+ audio_states.insert(guild_id, audio_state.clone());
|
|
|
Some(audio_state)
|
|
|
}
|
|
|
}
|
|
@@ -78,15 +110,7 @@ async fn remove_audio_state(ctx: &Context, msg: &Message) -> Result<(), String>
|
|
|
|
|
|
let mut audio_states = AUDIO_STATES.lock().await;
|
|
|
let manager = songbird::get(ctx).await.unwrap();
|
|
|
- if manager
|
|
|
- .get(guild_id)
|
|
|
- .unwrap()
|
|
|
- .lock()
|
|
|
- .await
|
|
|
- .leave()
|
|
|
- .await
|
|
|
- .is_err()
|
|
|
- {
|
|
|
+ if let Err(_) = manager.remove(guild_id).await {
|
|
|
return Err("Could not leave channel".to_string());
|
|
|
}
|
|
|
|