Fix array access

This commit is contained in:
hodasemi 2018-08-14 19:53:09 +02:00
parent 46f2a76cf1
commit dc41eb26f8

View file

@ -15,7 +15,7 @@ macro_rules! check_option {
($v:expr) => {
match $v {
Some(t) => t,
None => return (),
None => return,
}
};
}
@ -69,12 +69,18 @@ impl MediaData {
let audio = song_lock.lock();
if audio.finished {
Self::next_song(
if !Self::next_song(
song,
media_clone.playlist.borrow_mut().deref_mut(),
channel_id,
&manager_clone,
)
) {
manager_clone
.lock()
.remove(check_option!(guild_id(channel_id)));
return;
}
}
continue;
@ -94,6 +100,8 @@ impl MediaData {
"Playing song: {}",
super::youtube::convert_file_name(first.name)
)));
} else {
return;
}
}
@ -109,19 +117,32 @@ impl MediaData {
manager_lock: &Arc<
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
>,
) {
) -> bool {
let mut manager = manager_lock.lock();
if let Some(handler) = handler(check_option!(guild_id(channel_id)), &mut manager) {
let first = playlist.remove(0);
let guild_id = match guild_id(channel_id) {
Some(id) => id,
None => return false,
};
*song = handler.play_returning(first.source);
if let Some(handler) = handler(guild_id, &mut manager) {
if playlist.is_empty() {
return false;
} else {
let first = playlist.remove(0);
super::check_msg(channel_id.say(format!(
"Playing song: {}",
super::youtube::convert_file_name(first.name)
)));
*song = handler.play_returning(first.source);
super::check_msg(channel_id.say(format!(
"Playing song: {}",
super::youtube::convert_file_name(first.name)
)));
return true;
}
}
return false;
}
}
@ -214,7 +235,10 @@ impl serenity::framework::standard::Command for Pause {
_: serenity::framework::standard::Args,
) -> ::std::result::Result<(), serenity::framework::standard::CommandError> {
if let Some(song) = self.media.current_song.borrow_mut().deref_mut() {
//song.pause();
let song_clone = song.clone();
let mut audio_lock = song_clone.lock();
audio_lock.pause();
}
Ok(())