Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

baalajimaestro
Copy link

@baalajimaestro baalajimaestro commented Dec 8, 2022

Fixes #31

  • Added a bunch of upgrades as well

Tested to be working just fine

Required breaking change:

DISCORD_USER_ID is now DISCORD_ADMINS which is a list

For supplying via env vars, DISCORD_ADMINS = '["user1","user2"]'

Signed-off-by: baalajimaestro <[email protected]>
Signed-off-by: baalajimaestro <[email protected]>
Signed-off-by: baalajimaestro <[email protected]>
Signed-off-by: baalajimaestro <[email protected]>
Signed-off-by: baalajimaestro <[email protected]>
Signed-off-by: baalajimaestro <[email protected]>
Copy link
Contributor

@sibartel sibartel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. Some feedback from my side.

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@sibartel sibartel Dec 8, 2022

Choose a reason for hiding this comment

The 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.

// 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();
Copy link
Contributor

Choose a reason for hiding this comment

The 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 is_some check of line 142 as a condition to the if in 130 and only assign if a valid channel was found.
The var channel_id should then be an Option<id::ChannelId> initialized to None.

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.

// 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need one channel_id later on. Just use an Option<id::ChannelId> and move the is_some() check into the loop in line 71.

Copy link
Contributor

@sibartel sibartel Dec 8, 2022

Choose a reason for hiding this comment

The 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 i in channel_ids {
if i.is_some() {
// Enable casting
player.lock().await.enable_connect().await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break here to prevent multiple connect attempts.

@@ -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"]'
Copy link
Contributor

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 not DISCORD_USERS?

@baalajimaestro
Copy link
Author

Thanks for the quick review, will resolve the requested changes

@Sheeley7
Copy link

Sheeley7 commented Jun 8, 2024

Did any feature like this ever get merged into the main branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the bot follow multiple users
3 participants