diff --git a/Cargo.lock b/Cargo.lock index 01c68a8..50079af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -892,7 +892,7 @@ dependencies = [ [[package]] name = "lyra" -version = "0.2.0" +version = "0.3.0" dependencies = [ "dotenv", "openssl", diff --git a/Cargo.toml b/Cargo.toml index 3e7b1c0..04a48d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lyra" -version = "0.2.0" +version = "0.3.0" edition = "2021" [dependencies] diff --git a/src/commands/music/loop.rs b/src/commands/music/loop.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/commands/music/loopcurrent.rs b/src/commands/music/loopcurrent.rs new file mode 100644 index 0000000..e347f09 --- /dev/null +++ b/src/commands/music/loopcurrent.rs @@ -0,0 +1,83 @@ +use serenity::framework::standard::macros::command; +use serenity::framework::standard::{Args, CommandResult}; +use serenity::model::prelude::*; +use serenity::prelude::*; +use songbird::tracks::LoopState; + +use crate::commands::misc::check_msg; + +#[command] +#[aliases(loop)] +#[only_in(guilds)] +async fn loopcurrent(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { + let guild_id = msg.guild_id.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Client placed at init") + .clone(); + + + if let Some(handler_lock) = manager.get(guild_id) { + let handler = handler_lock.lock().await; + let queue = handler.queue(); + + let track = queue.current().unwrap().get_info().await; + let is_looped = track.unwrap().loops; + + + let count = match args.single::() { + Ok(count) => count, + Err(_) => 100, + }; + + match is_looped { + LoopState::Infinite => { + let _ = queue.current().unwrap().disable_loop(); + + check_msg( + msg.channel_id + .say( + &ctx.http, + format!("Song unlooped."), + ) + .await, + ); + } + LoopState::Finite(_) => { + if count < 100 { + let _ = queue.current().unwrap().loop_for(count); + check_msg( + msg.channel_id + .say( + &ctx.http, + format!("Song looped forever (a very long time)."), + ) + .await, + ) + } + else { + let _ = queue.current().unwrap().enable_loop(); + + check_msg( + msg.channel_id + .say( + &ctx.http, + format!("Song looped {} times.", count), + ) + .await, + ) + } + + } + } + } else { + check_msg( + msg.channel_id + .say(&ctx.http, "Not in a voice channel to play in") + .await, + ); + } + + Ok(()) +} diff --git a/src/commands/music/mod.rs b/src/commands/music/mod.rs index 31d9376..342a8fb 100644 --- a/src/commands/music/mod.rs +++ b/src/commands/music/mod.rs @@ -7,3 +7,6 @@ pub mod play; pub mod queue; pub mod skip; pub mod stop; +pub mod loopcurrent; +pub mod pause; +pub mod resume; diff --git a/src/commands/music/pause.rs b/src/commands/music/pause.rs index e69de29..02f0c77 100644 --- a/src/commands/music/pause.rs +++ b/src/commands/music/pause.rs @@ -0,0 +1,40 @@ +use serenity::framework::standard::macros::command; +use serenity::framework::standard::CommandResult; +use serenity::model::prelude::*; +use serenity::prelude::*; + +use crate::commands::misc::check_msg; + +#[command] +#[only_in(guilds)] +async fn pause(ctx: &Context, msg: &Message) -> CommandResult { + let guild_id = msg.guild_id.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Client placed at init") + .clone(); + + if let Some(handler_lock) = manager.get(guild_id) { + let handler = handler_lock.lock().await; + let queue = handler.queue(); + let _ = queue.pause(); + + check_msg( + msg.channel_id + .say( + &ctx.http, + format!("Song paused."), + ) + .await, + ); + } else { + check_msg( + msg.channel_id + .say(&ctx.http, "Not in a voice channel to play in") + .await, + ); + } + + Ok(()) +} diff --git a/src/commands/music/play.rs b/src/commands/music/play.rs index a80b8de..b16ccf0 100644 --- a/src/commands/music/play.rs +++ b/src/commands/music/play.rs @@ -60,7 +60,7 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { if let Ok(handler_lock) = manager.join(guild_id, connect_to).await { let mut handler = handler_lock.lock().await; - if let Err(err) = handler.deafen(true).await {println!("Failed to deafen: {:?}", err)}; + // if let Err(err) = handler.deafen(true).await {println!("Failed to deafen: {:?}", err)}; handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier); let mut src = if is_search { @@ -73,7 +73,6 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let _ = handler.enqueue_input(src.clone().into()).await; let metadata = src.aux_metadata().await.unwrap(); - // let _ = handler.play_input(src.clone().into()); check_msg(msg.channel_id.say(&ctx.http, format!("Playing song: {}", metadata.title.unwrap())).await); } else { diff --git a/src/commands/music/resume.rs b/src/commands/music/resume.rs index e69de29..a569bf5 100644 --- a/src/commands/music/resume.rs +++ b/src/commands/music/resume.rs @@ -0,0 +1,40 @@ +use serenity::framework::standard::macros::command; +use serenity::framework::standard::CommandResult; +use serenity::model::prelude::*; +use serenity::prelude::*; + +use crate::commands::misc::check_msg; + +#[command] +#[only_in(guilds)] +async fn resume(ctx: &Context, msg: &Message) -> CommandResult { + let guild_id = msg.guild_id.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Client placed at init") + .clone(); + + if let Some(handler_lock) = manager.get(guild_id) { + let handler = handler_lock.lock().await; + let queue = handler.queue(); + let _ = queue.resume(); + + check_msg( + msg.channel_id + .say( + &ctx.http, + format!("Song resumed."), + ) + .await, + ); + } else { + check_msg( + msg.channel_id + .say(&ctx.http, "Not in a voice channel to play in") + .await, + ); + } + + Ok(()) +} diff --git a/src/commands/music/stop.rs b/src/commands/music/stop.rs index 0ccfb45..426737d 100644 --- a/src/commands/music/stop.rs +++ b/src/commands/music/stop.rs @@ -16,18 +16,10 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult { .clone(); if let Some(handler_lock) = manager.get(guild_id) { - let mut handler = handler_lock.lock().await; + let handler = handler_lock.lock().await; let queue = handler.queue(); queue.stop(); - if let Err(e) = handler.deafen(false).await { - check_msg( - msg.channel_id - .say(&ctx.http, format!("Failed: {:?}", e)) - .await, - ); - } - check_msg(msg.channel_id.say(&ctx.http, "Playback stopped!").await); } else { check_msg( diff --git a/src/main.rs b/src/main.rs index 9b2d995..0b12fb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,9 @@ use crate::commands::music::play::*; use crate::commands::music::queue::*; use crate::commands::music::skip::*; use crate::commands::music::stop::*; +use crate::commands::music::loopcurrent::*; +use crate::commands::music::pause::*; +use crate::commands::music::resume::*; // tools use crate::commands::tools::ping::*; @@ -59,7 +62,7 @@ async fn before(_: &Context, msg: &Message, command_name: &str) -> bool { #[group] #[commands( - join, deafen, leave, mute, play, ping, kashi, queue, stop, skip + join, deafen, leave, mute, play, ping, kashi, queue, stop, skip, loopcurrent, pause, resume )] struct General;