Skip to content

Commit

Permalink
update deps and add loop command
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed May 8, 2023
1 parent e0804df commit 21ebb4f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
18 changes: 14 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ branch = "serenity-next"

[dependencies.songbird]
git = "https://github.com/serenity-rs/songbird.git"
rev = "da3706c3380dfa28da458dab9af8a2f525201b90"
rev = "20da9e1cac0cca9c7f6ca1169a582064290dee8f"
features = [ "builtin-queue" ]

[dependencies.serenity]
Expand Down
50 changes: 49 additions & 1 deletion src/track.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use serenity::prelude::TypeMapKey;
use tracing::warn;

use crate::vc::enter_vc;
use crate::{CommandResult, Context};

crate::commands!(pause, resume);
crate::commands!(pause, resume, r#loop);

#[poise::command(slash_command, category = "Controls")]
/// Pause the current track
Expand Down Expand Up @@ -35,3 +36,50 @@ async fn resume(ctx: Context<'_>) -> CommandResult {
})
.await
}

pub enum LoopState {
Disabled,
Enabled,
}

impl TypeMapKey for LoopState {
type Value = LoopState;
}

#[poise::command(slash_command, category = "Controls")]
/// Toggle loop mode for the current track
async fn r#loop(ctx: Context<'_>) -> CommandResult {
enter_vc(ctx, false, |handler, c| async move {
let lock = handler.lock().await;
let current = lock.queue().current();
drop(lock);
let Some(current) = current else {
c.say("No track is currently playing").await?;
return Ok(());
};

let map = current.typemap().write().await;

let new_state = match map.get() {
Some(LoopState::Disabled) => LoopState::Enabled,
Some(LoopState::Enabled) => LoopState::Disabled,
None => LoopState::Enabled,
};

map.insert(new_state);

drop(map);

match new_state {
LoopState::Disabled => {
current.disable_loop()?;
c.say("Looping disabled").await?;
}
LoopState::Enabled => {
current.enable_loop()?;
c.say("Looping enabled").await?;
}
}

}).await
}

0 comments on commit 21ebb4f

Please sign in to comment.