-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the bot follow multiple users #32
base: main
Are you sure you want to change the base?
Changes from 6 commits
42abb66
eb85cde
b8a2eb9
ef80706
5815f3e
36e946e
fc8f199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,23 @@ | |
name = "aoede" | ||
version = "0.6.0" | ||
authors = ["Max Isom <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[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" | ||
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"] } | ||
rubato = "0.12.0" | ||
|
||
[dependencies.serenity] | ||
version = "0.11.2" | ||
features = ["client"] | ||
version = "0.11.5" | ||
features = ["client", "utils"] | ||
|
||
[profile.dev] | ||
split-debuginfo = "unpacked" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Option<id::ChannelId>> = Vec::new(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only need one channel_id later on. Just use an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to store it at all, just connect directly if a valid channel is found (and then break). |
||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Break here to prevent multiple connect attempts. |
||
} | ||
} | ||
|
||
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<Option<id::ChannelId>> = Vec::new(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you use here an vector if in fact you only need one single channel_id later on? Add the Then you can check if it is still None after your loop, if that's the case log that the 'admin' was not found. If it is some, join the channel. |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your comment doesn't match your code. You are taking the last channel which is some. Later loop iterations are overwriting your channel_id. An early break would make sense here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comments above / below, this extra loop should not be necessary at all. |
||
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::<ConfigKey>().unwrap(); | ||
|
||
if new.user_id.to_string() != config.discord_user_id.to_string() { | ||
if ! config.discord_admins.contains(&new.user_id.to_string()) { | ||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I don't like the name
DISCORD_ADMINS
. Someone could think that he must list the discord server admins / owners here. Why notDISCORD_USERS
?