Fix array access
This commit is contained in:
parent
46f2a76cf1
commit
dc41eb26f8
1 changed files with 36 additions and 12 deletions
|
@ -15,7 +15,7 @@ macro_rules! check_option {
|
||||||
($v:expr) => {
|
($v:expr) => {
|
||||||
match $v {
|
match $v {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => return (),
|
None => return,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,18 @@ impl MediaData {
|
||||||
let audio = song_lock.lock();
|
let audio = song_lock.lock();
|
||||||
|
|
||||||
if audio.finished {
|
if audio.finished {
|
||||||
Self::next_song(
|
if !Self::next_song(
|
||||||
song,
|
song,
|
||||||
media_clone.playlist.borrow_mut().deref_mut(),
|
media_clone.playlist.borrow_mut().deref_mut(),
|
||||||
channel_id,
|
channel_id,
|
||||||
&manager_clone,
|
&manager_clone,
|
||||||
)
|
) {
|
||||||
|
manager_clone
|
||||||
|
.lock()
|
||||||
|
.remove(check_option!(guild_id(channel_id)));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -94,6 +100,8 @@ impl MediaData {
|
||||||
"Playing song: {}",
|
"Playing song: {}",
|
||||||
super::youtube::convert_file_name(first.name)
|
super::youtube::convert_file_name(first.name)
|
||||||
)));
|
)));
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,10 +117,18 @@ impl MediaData {
|
||||||
manager_lock: &Arc<
|
manager_lock: &Arc<
|
||||||
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
|
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
|
||||||
>,
|
>,
|
||||||
) {
|
) -> bool {
|
||||||
let mut manager = manager_lock.lock();
|
let mut manager = manager_lock.lock();
|
||||||
|
|
||||||
if let Some(handler) = handler(check_option!(guild_id(channel_id)), &mut manager) {
|
let guild_id = match guild_id(channel_id) {
|
||||||
|
Some(id) => id,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(handler) = handler(guild_id, &mut manager) {
|
||||||
|
if playlist.is_empty() {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
let first = playlist.remove(0);
|
let first = playlist.remove(0);
|
||||||
|
|
||||||
*song = handler.play_returning(first.source);
|
*song = handler.play_returning(first.source);
|
||||||
|
@ -121,8 +137,13 @@ impl MediaData {
|
||||||
"Playing song: {}",
|
"Playing song: {}",
|
||||||
super::youtube::convert_file_name(first.name)
|
super::youtube::convert_file_name(first.name)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MediaData {
|
impl Default for MediaData {
|
||||||
|
@ -214,7 +235,10 @@ impl serenity::framework::standard::Command for Pause {
|
||||||
_: serenity::framework::standard::Args,
|
_: serenity::framework::standard::Args,
|
||||||
) -> ::std::result::Result<(), serenity::framework::standard::CommandError> {
|
) -> ::std::result::Result<(), serenity::framework::standard::CommandError> {
|
||||||
if let Some(song) = self.media.current_song.borrow_mut().deref_mut() {
|
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(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue