From 42abb662eb9ceebcc63fcb96857e2b5c10c4a19c Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 10:47:15 +0530 Subject: [PATCH 1/7] Bump up librespot Signed-off-by: baalajimaestro --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d9caac8..30fe177 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Max Isom "] edition = "2018" [dependencies] -librespot = {version = "0.4.1", default-features = false} +librespot = {version = "0.4.2", default-features = false} songbird = "0.3.0" tracing = "0.1" tracing-subscriber = "0.2" From eb85cdedea13c4fc79b4bfa882418873abcca2ec Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 10:48:33 +0530 Subject: [PATCH 2/7] Bump up serenity Signed-off-by: baalajimaestro --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 30fe177..65fce30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ figment = { version = "0.10", features = ["toml", "env"] } rubato = "0.12.0" [dependencies.serenity] -version = "0.11.2" +version = "0.11.5" features = ["client"] [profile.dev] From b8a2eb9999821e6350c03bf9c4ed16f7efb5fedc Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 10:52:58 +0530 Subject: [PATCH 3/7] Migrate to rust 2021 Signed-off-by: baalajimaestro --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 65fce30..571381b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "aoede" version = "0.6.0" authors = ["Max Isom "] -edition = "2018" +edition = "2021" [dependencies] librespot = {version = "0.4.2", default-features = false} From ef80706a412f684eb2d5d6b1deebcc27cce06eba Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 10:55:51 +0530 Subject: [PATCH 4/7] Bump up tokio Signed-off-by: baalajimaestro --- Cargo.lock | 68 +++++++++++++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 2 +- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15b6cc4..4d5164d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1288,7 +1288,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1440,7 +1440,7 @@ dependencies = [ "redox_syscall", "smallvec", "thread-id", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -2332,9 +2332,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" dependencies = [ "autocfg", "bytes", @@ -2342,13 +2342,12 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "winapi", + "windows-sys 0.42.0", ] [[package]] @@ -2874,6 +2873,27 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.32.0" @@ -2886,6 +2906,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.32.0" @@ -2898,6 +2924,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.32.0" @@ -2910,6 +2942,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.32.0" @@ -2922,6 +2960,18 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.32.0" @@ -2934,6 +2984,12 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index 571381b..5e2b10d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ songbird = "0.3.0" tracing = "0.1" tracing-subscriber = "0.2" tracing-futures = "0.2" -tokio = { version = "1.20.1", features = ["default"] } +tokio = { version = "1.23.0", features = ["default"] } byteorder = "1.4.3" serde = "1.0" figment = { version = "0.10", features = ["toml", "env"] } From 5815f3ee6f6d5c3542413669b0a952bf2ae02241 Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 15:07:56 +0530 Subject: [PATCH 5/7] Handle multiple bot admins Signed-off-by: baalajimaestro --- Cargo.toml | 2 +- config.sample.toml | 2 +- src/lib/config.rs | 4 ++-- src/main.rs | 57 ++++++++++++++++++++++++++++++---------------- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5e2b10d..a3f7c6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ rubato = "0.12.0" [dependencies.serenity] version = "0.11.5" -features = ["client"] +features = ["client", "utils"] [profile.dev] split-debuginfo = "unpacked" diff --git a/config.sample.toml b/config.sample.toml index 11a626d..c1fd394 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -1,4 +1,4 @@ DISCORD_TOKEN="the discord bot token" SPOTIFY_USERNAME="your spotify email" SPOTIFY_PASSWORD="your spotify password" -DISCORD_USER_ID="your discord id here" +DISCORD_ADMINS=["list of ids who can control the bot"] diff --git a/src/lib/config.rs b/src/lib/config.rs index 81de751..41272b7 100644 --- a/src/lib/config.rs +++ b/src/lib/config.rs @@ -12,8 +12,8 @@ pub struct Config { pub spotify_username: String, #[serde(alias = "SPOTIFY_PASSWORD")] pub spotify_password: String, - #[serde(alias = "DISCORD_USER_ID")] - pub discord_user_id: u64, + #[serde(alias = "DISCORD_ADMINS")] + pub discord_admins: Vec, } impl Config { diff --git a/src/main.rs b/src/main.rs index 0d3685a..acfa093 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,15 +63,22 @@ impl EventHandler for Handler { .guild(guild_id) .expect("Could not find guild in cache."); - let channel_id = guild - .voice_states - .get(&config.discord_user_id.into()) - .and_then(|voice_state| voice_state.channel_id); - drop(guild); + // Check if any of the admins are in the VC + let user_list = guild.voice_states; + + let mut channel_ids: Vec> = Vec::new(); + + for (key, value) in user_list { + if config.discord_admins.contains(&key.to_string()) { + channel_ids.push(value.channel_id); + } + } - if channel_id.is_some() { - // Enable casting - player.lock().await.enable_connect().await; + for i in channel_ids { + if i.is_some() { + // Enable casting + player.lock().await.enable_connect().await; + } } let c = ctx.clone(); @@ -114,17 +121,29 @@ impl EventHandler for Handler { .guild(guild_id) .expect("Could not find guild in cache."); - let channel_id = match guild - .voice_states - .get(&config.discord_user_id.into()) - .and_then(|voice_state| voice_state.channel_id) - { - Some(channel_id) => channel_id, - None => { - println!("Could not find user in VC."); - continue; + // Check if any of the admins are in the VC + let user_list = guild.voice_states; + + let mut channel_ids: Vec> = Vec::new(); + + for (key, value) in user_list { + if config.discord_admins.contains(&key.to_string()) { + channel_ids.push(value.channel_id); } - }; + } + + if channel_ids.len() == 0 { + println!("Admin not in VC!"); + continue; + } + + let mut channel_id = id::ChannelId(0); + for i in channel_ids { + if i.is_some() { + // Choose the first channel we encounter which is non-null + channel_id = i.unwrap(); + } + } let _handler = manager.join(guild_id, channel_id).await; @@ -195,7 +214,7 @@ impl EventHandler for Handler { let config = data.get::().unwrap(); - if new.user_id.to_string() != config.discord_user_id.to_string() { + if ! config.discord_admins.contains(&new.user_id.to_string()) { return; } From 36e946ed32f322f3359e03ad42381676972a4dc4 Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 15:09:58 +0530 Subject: [PATCH 6/7] Make appropriate documentation changes Signed-off-by: baalajimaestro --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 23dfd64..c0f669e 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ services: - DISCORD_TOKEN= - SPOTIFY_USERNAME= - SPOTIFY_PASSWORD= - - DISCORD_USER_ID= # Discord user ID of the user you want Aoede to follow + - DISCORD_ADMINS= # List (wrapped in single quotes) of users u want the bot to keep track of, eg value: '["100","200"]' ``` ### Docker: @@ -52,7 +52,7 @@ services: DISCORD_TOKEN= SPOTIFY_USERNAME= SPOTIFY_PASSWORD= -DISCORD_USER_ID= +DISCORD_ADMINS= ``` ```bash From fc8f199e8bdb525a471cc54d1c1cad8d7891d87f Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Thu, 8 Dec 2022 15:37:33 +0530 Subject: [PATCH 7/7] Run cargo fmt Signed-off-by: baalajimaestro --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index acfa093..63ba472 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ impl EventHandler for Handler { let user_list = guild.voice_states; let mut channel_ids: Vec> = Vec::new(); - + for (key, value) in user_list { if config.discord_admins.contains(&key.to_string()) { channel_ids.push(value.channel_id); @@ -123,9 +123,9 @@ impl EventHandler for Handler { // Check if any of the admins are in the VC let user_list = guild.voice_states; - + let mut channel_ids: Vec> = Vec::new(); - + for (key, value) in user_list { if config.discord_admins.contains(&key.to_string()) { channel_ids.push(value.channel_id); @@ -136,7 +136,7 @@ impl EventHandler for Handler { println!("Admin not in VC!"); continue; } - + let mut channel_id = id::ChannelId(0); for i in channel_ids { if i.is_some() { @@ -214,7 +214,7 @@ impl EventHandler for Handler { let config = data.get::().unwrap(); - if ! config.discord_admins.contains(&new.user_id.to_string()) { + if !config.discord_admins.contains(&new.user_id.to_string()) { return; }