|
@@ -18,7 +18,7 @@ use tokio::sync::Mutex;
|
|
use tokio::time::sleep;
|
|
use tokio::time::sleep;
|
|
|
|
|
|
pub struct AudioState {
|
|
pub struct AudioState {
|
|
- queue: SongQueue,
|
|
|
|
|
|
+ queue: Arc<Mutex<SongQueue>>,
|
|
handler: Arc<SerenityMutex<Call>>,
|
|
handler: Arc<SerenityMutex<Call>>,
|
|
current_song: Mutex<Option<Song>>,
|
|
current_song: Mutex<Option<Song>>,
|
|
track_handle: Mutex<Option<TrackHandle>>,
|
|
track_handle: Mutex<Option<TrackHandle>>,
|
|
@@ -31,7 +31,7 @@ pub struct AudioState {
|
|
impl AudioState {
|
|
impl AudioState {
|
|
pub fn new(handler: Arc<SerenityMutex<Call>>, ctx: &Context, msg: &Message) -> Arc<AudioState> {
|
|
pub fn new(handler: Arc<SerenityMutex<Call>>, ctx: &Context, msg: &Message) -> Arc<AudioState> {
|
|
let audio_state = AudioState {
|
|
let audio_state = AudioState {
|
|
- queue: SongQueue::new(),
|
|
|
|
|
|
+ queue: Arc::new(Mutex::new(SongQueue::new())),
|
|
handler,
|
|
handler,
|
|
current_song: Mutex::new(None),
|
|
current_song: Mutex::new(None),
|
|
track_handle: Mutex::new(None),
|
|
track_handle: Mutex::new(None),
|
|
@@ -69,11 +69,12 @@ impl AudioState {
|
|
|
|
|
|
async fn play_audio(audio_state: Arc<AudioState>) {
|
|
async fn play_audio(audio_state: Arc<AudioState>) {
|
|
let is_looping = audio_state.is_looping.lock().await;
|
|
let is_looping = audio_state.is_looping.lock().await;
|
|
|
|
+ let mut queue = audio_state.queue.lock().await;
|
|
let song = if *is_looping {
|
|
let song = if *is_looping {
|
|
let mut current_song = audio_state.current_song.lock().await;
|
|
let mut current_song = audio_state.current_song.lock().await;
|
|
current_song.take()
|
|
current_song.take()
|
|
} else {
|
|
} else {
|
|
- audio_state.queue.pop().await
|
|
|
|
|
|
+ queue.pop().await
|
|
};
|
|
};
|
|
drop(is_looping);
|
|
drop(is_looping);
|
|
|
|
|
|
@@ -129,7 +130,8 @@ impl AudioState {
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn add_audio(audio_state: Arc<AudioState>, song: Song) {
|
|
pub async fn add_audio(audio_state: Arc<AudioState>, song: Song) {
|
|
- audio_state.queue.push(vec![song]).await;
|
|
|
|
|
|
+ let mut queue = audio_state.queue.lock().await;
|
|
|
|
+ queue.push(vec![song]).await;
|
|
let current_song = audio_state.current_song.lock().await;
|
|
let current_song = audio_state.current_song.lock().await;
|
|
if current_song.is_none() {
|
|
if current_song.is_none() {
|
|
let audio_state = audio_state.clone();
|
|
let audio_state = audio_state.clone();
|
|
@@ -154,11 +156,13 @@ impl AudioState {
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn shuffle(audio_state: Arc<AudioState>) -> Result<(), String> {
|
|
pub async fn shuffle(audio_state: Arc<AudioState>) -> Result<(), String> {
|
|
- audio_state.queue.shuffle().await
|
|
|
|
|
|
+ let mut queue = audio_state.queue.lock().await;
|
|
|
|
+ queue.shuffle().await
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn clear(audio_state: Arc<AudioState>) -> Result<(), String> {
|
|
pub async fn clear(audio_state: Arc<AudioState>) -> Result<(), String> {
|
|
- audio_state.queue.clear().await
|
|
|
|
|
|
+ let mut queue = audio_state.queue.lock().await;
|
|
|
|
+ queue.clear().await
|
|
}
|
|
}
|
|
|
|
|
|
// on success, returns a bool that specifies whether the queue is now being looped
|
|
// on success, returns a bool that specifies whether the queue is now being looped
|
|
@@ -180,10 +184,11 @@ impl AudioState {
|
|
Some(song) => song.get_string().await,
|
|
Some(song) => song.get_string().await,
|
|
None => "*Not playing*\n".to_string(),
|
|
None => "*Not playing*\n".to_string(),
|
|
};
|
|
};
|
|
|
|
+ let queue = audio_state.queue.lock().await;
|
|
format!(
|
|
format!(
|
|
"**Current Song:**\n{}\n\n**Queue:**\n{}",
|
|
"**Current Song:**\n{}\n\n**Queue:**\n{}",
|
|
current_song,
|
|
current_song,
|
|
- audio_state.queue.get_string().await
|
|
|
|
|
|
+ queue.get_string().await
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|