Skip to content

Commit

Permalink
feat: add ability to customize autoplay from a configuration file (#44)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Isom <codetheweb@users.noreply.github.com>
  • Loading branch information
SijyKijy and codetheweb committed Nov 3, 2023
1 parent 2fe136d commit e9104d6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -43,7 +43,8 @@ services:
- DISCORD_TOKEN=
- SPOTIFY_USERNAME=
- SPOTIFY_PASSWORD=
- DISCORD_USER_ID= # Discord user ID of the user you want Aoede to follow
- DISCORD_USER_ID= # Discord user ID of the user you want Aoede to follow
- SPOTIFY_BOT_AUTOPLAY= # Autoplay similar songs when your music ends (true/false)
```

### Docker:
Expand All @@ -53,6 +54,7 @@ DISCORD_TOKEN=
SPOTIFY_USERNAME=
SPOTIFY_PASSWORD=
DISCORD_USER_ID=
SPOTIFY_BOT_AUTOPLAY=
```

```bash
Expand Down
1 change: 1 addition & 0 deletions config.sample.toml
Expand Up @@ -2,3 +2,4 @@ DISCORD_TOKEN="the discord bot token"
SPOTIFY_USERNAME="your spotify email"
SPOTIFY_PASSWORD="your spotify password"
DISCORD_USER_ID="your discord id here"
SPOTIFY_BOT_AUTOPLAY=true
2 changes: 2 additions & 0 deletions src/lib/config.rs
Expand Up @@ -14,6 +14,8 @@ pub struct Config {
pub spotify_password: String,
#[serde(alias = "DISCORD_USER_ID")]
pub discord_user_id: u64,
#[serde(alias = "SPOTIFY_BOT_AUTOPLAY")]
pub spotify_bot_autoplay: bool,
}

impl Config {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/player.rs
Expand Up @@ -37,6 +37,7 @@ pub struct SpotifyPlayer {
pub spirc: Option<Box<Spirc>>,
pub event_channel: Option<Arc<tokio::sync::Mutex<PlayerEventChannel>>>,
mixer: Box<SoftMixer>,
pub bot_autoplay: bool,
}

pub struct EmittedSink {
Expand Down Expand Up @@ -206,6 +207,7 @@ impl SpotifyPlayer {
password: String,
quality: Bitrate,
cache_dir: Option<String>,
bot_autoplay: bool,
) -> SpotifyPlayer {
let credentials = Credentials::with_password(username, password);

Expand Down Expand Up @@ -256,6 +258,7 @@ impl SpotifyPlayer {
spirc: None,
event_channel: Some(Arc::new(tokio::sync::Mutex::new(rx))),
mixer,
bot_autoplay,
}
}

Expand All @@ -265,7 +268,7 @@ impl SpotifyPlayer {
device_type: DeviceType::AudioDongle,
initial_volume: None,
has_volume_ctrl: true,
autoplay: true,
autoplay: self.bot_autoplay,
};

let cloned_sink = self.emitted_sink.clone();
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Expand Up @@ -288,6 +288,7 @@ async fn main() {
config.spotify_password.clone(),
Bitrate::Bitrate320,
cache_dir,
config.spotify_bot_autoplay,
)
.await,
));
Expand Down

0 comments on commit e9104d6

Please sign in to comment.