Add skip command
This commit is contained in:
parent
2cd55ca5b9
commit
b739039f7f
2 changed files with 67 additions and 1 deletions
|
@ -131,7 +131,8 @@ fn main() {
|
|||
),
|
||||
)
|
||||
.cmd("stop", Stop::new(media_data.clone()))
|
||||
.cmd("list", List::new(media_data.clone())),
|
||||
.cmd("list", List::new(media_data.clone()))
|
||||
.cmd("skip", Skip::new(media_data.clone())),
|
||||
);
|
||||
|
||||
let _ = client
|
||||
|
|
|
@ -481,3 +481,68 @@ impl serenity::framework::standard::Command for Stop {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Skip {
|
||||
media: Arc<MediaData>,
|
||||
}
|
||||
|
||||
impl Skip {
|
||||
pub fn new(media_data: Arc<MediaData>) -> Skip {
|
||||
Skip { media: media_data }
|
||||
}
|
||||
}
|
||||
|
||||
impl serenity::framework::standard::Command for Skip {
|
||||
#[allow(unreachable_code, unused_mut)]
|
||||
fn execute(
|
||||
&self,
|
||||
ctx: &mut serenity::client::Context,
|
||||
msg: &serenity::model::channel::Message,
|
||||
_: serenity::framework::standard::Args,
|
||||
) -> ::std::result::Result<(), serenity::framework::standard::CommandError> {
|
||||
let mut manager_lock = ctx
|
||||
.data
|
||||
.lock()
|
||||
.get::<super::VoiceManager>()
|
||||
.cloned()
|
||||
.unwrap();
|
||||
|
||||
let mut manager = manager_lock.lock();
|
||||
|
||||
let guild_id = match guild_id(msg.channel_id) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
println!("error getting guild id");
|
||||
|
||||
super::check_msg(msg.channel_id.say("error getting guild id"));
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(handler) = handler(guild_id, &mut manager) {
|
||||
let playlist_mutex = self.media.playlist_mut();
|
||||
let mut playlist = playlist_mutex.borrow_mut();
|
||||
|
||||
let song_mutex = self.media.song_mut();
|
||||
let mut song = song_mutex.borrow_mut();
|
||||
|
||||
if playlist.is_empty() {
|
||||
super::check_msg(
|
||||
msg.channel_id
|
||||
.say("playlist is empty, no next song available"),
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
} else {
|
||||
let first = playlist.remove(0);
|
||||
|
||||
*song = Some(handler.play_returning(first.source));
|
||||
|
||||
super::check_msg(msg.channel_id.say(format!("Playing song: {}", first.name)));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue