Skip to content

Commit

Permalink
feat: Implement MemberVoiceStateBehavior.RequireDifferent
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Feb 11, 2024
1 parent 0078e2c commit 8608c23
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Lavalink4NET/Clients/MemberVoiceStateBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public enum MemberVoiceStateBehavior : byte
/// Regardless of the player's connection state, the user must be in the same voice channel as the player.
/// </summary>
RequireSame,

/// <summary>
/// Regardless of the player's connection state, the user must be in a different voice channel than the player.
/// </summary>
RequireDifferent,
}
11 changes: 9 additions & 2 deletions src/Lavalink4NET/Players/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ static async ValueTask<PlayerResult<TPlayer>> CheckPreconditionsAsync(

if (player is not null)
{
if (voiceStateBehavior is MemberVoiceStateBehavior.AlwaysRequired or MemberVoiceStateBehavior.RequireSame &&
memberVoiceChannel is null)
if (voiceStateBehavior is not MemberVoiceStateBehavior.Ignore && memberVoiceChannel is null)
{
return PlayerResult<TPlayer>.UserNotInVoiceChannel;
}
Expand All @@ -277,6 +276,14 @@ await DiscordClient
.ConfigureAwait(false);
}
}
else
{
// Player is in same voice chanenl as bot
if (voiceStateBehavior is MemberVoiceStateBehavior.RequireDifferent)
{
return PlayerResult<TPlayer>.UserInSameVoiceChannel;
}
}

return await CheckPreconditionsAsync(player, preconditions, cancellationToken).ConfigureAwait(false);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Lavalink4NET/Players/PlayerResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static PlayerResult<TPlayer> Success(TPlayer player)

public static PlayerResult<TPlayer> VoiceChannelMismatch => new(null, PlayerRetrieveStatus.VoiceChannelMismatch, null);

public static PlayerResult<TPlayer> UserInSameVoiceChannel => new(null, PlayerRetrieveStatus.UserInSameVoiceChannel, null);

public static PlayerResult<TPlayer> BotNotConnected => new(null, PlayerRetrieveStatus.BotNotConnected, null);

public static PlayerResult<TPlayer> PreconditionFailed(TPlayer player, IPlayerPrecondition precondition)
Expand Down
1 change: 1 addition & 0 deletions src/Lavalink4NET/Players/PlayerRetrieveStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum PlayerRetrieveStatus : byte
Success,
UserNotInVoiceChannel,
VoiceChannelMismatch,
UserInSameVoiceChannel,
BotNotConnected,
PreconditionFailed,
}

0 comments on commit 8608c23

Please sign in to comment.