Skip to content

Commit

Permalink
refactor: Revert allowing zombie players
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Aug 16, 2023
1 parent b68cf3d commit 802062d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public async ValueTask<PlayerActivityStatus> CheckAsync(InactivityTrackingContex
{
var includeBots = !_options.ExcludeBots.GetValueOrDefault(true);

if (context.Player.VoiceChannelId is null)
{
return PlayerActivityStatus.Inactive;
}

var usersInChannel = await context.Client
.GetChannelUsersAsync(context.Player.GuildId, context.Player.VoiceChannelId.Value, includeBots, cancellationToken)
.GetChannelUsersAsync(context.Player.GuildId, context.Player.VoiceChannelId, includeBots, cancellationToken)
.ConfigureAwait(false);

return usersInChannel.Length >= _options.Threshold.GetValueOrDefault(1)
Expand Down
2 changes: 1 addition & 1 deletion src/Lavalink4NET/Players/ILavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface ILavalinkPlayer : IAsyncDisposable

PlayerState State { get; }

ulong? VoiceChannelId { get; }
ulong VoiceChannelId { get; }

PlayerConnectionState ConnectionState { get; }

Expand Down
13 changes: 8 additions & 5 deletions src/Lavalink4NET/Players/LavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public TrackPosition? Position
_ => PlayerState.Playing,
};

public ulong? VoiceChannelId { get; private set; }
public ulong VoiceChannelId { get; private set; }

public float Volume { get; private set; }

Expand All @@ -102,13 +102,16 @@ public TrackPosition? Position

async ValueTask ILavalinkPlayerListener.NotifyChannelUpdateAsync(ulong? voiceChannelId, CancellationToken cancellationToken)
{
EnsureNotDestroyed();

if (voiceChannelId is null)
{
_logger.PlayerDisconnected(_label);
await using var _ = this.ConfigureAwait(false);
return;
}
else if (!_connectedOnce || VoiceChannelId is null)

EnsureNotDestroyed();

if (!_connectedOnce)
{
_connectedOnce = true;
_logger.PlayerConnected(_label, voiceChannelId);
Expand All @@ -118,7 +121,7 @@ async ValueTask ILavalinkPlayerListener.NotifyChannelUpdateAsync(ulong? voiceCha
_logger.PlayerMoved(_label, voiceChannelId);
}

VoiceChannelId = voiceChannelId;
VoiceChannelId = voiceChannelId.Value;

try
{
Expand Down
1 change: 0 additions & 1 deletion src/Lavalink4NET/Players/Vote/UserVoteResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public enum UserVoteResult : byte
{
Submitted,
Skipped,
NotConnected,
AlreadySubmitted,
UserNotInChannel,
}
17 changes: 2 additions & 15 deletions src/Lavalink4NET/Players/Vote/VoteLavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,8 @@ public async ValueTask<VoteSkipInformation> GetVotesAsync(CancellationToken canc
{
cancellationToken.ThrowIfCancellationRequested();

if (VoiceChannelId is null)
{
return new VoteSkipInformation(
Votes: ImmutableArray<UserVote>.Empty,
TotalUsers: 0,
Percentage: 0.0F);
}

var channelUsers = await _discordClient
.GetChannelUsersAsync(GuildId, VoiceChannelId.Value, includeBots: false, cancellationToken)
.GetChannelUsersAsync(GuildId, VoiceChannelId, includeBots: false, cancellationToken)
.ConfigureAwait(false);

return await ComputeAsync(channelUsers, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -98,13 +90,8 @@ public virtual async ValueTask<UserVoteResult> VoteAsync(ulong userId, UserVoteO
{
cancellationToken.ThrowIfCancellationRequested();

if (VoiceChannelId is null)
{
return UserVoteResult.NotConnected;
}

var channelUsers = await _discordClient
.GetChannelUsersAsync(GuildId, VoiceChannelId.Value, includeBots: false, cancellationToken)
.GetChannelUsersAsync(GuildId, VoiceChannelId, includeBots: false, cancellationToken)
.ConfigureAwait(false);

if (_requireUserToBeInVoiceChannel && !channelUsers.Contains(userId))
Expand Down

0 comments on commit 802062d

Please sign in to comment.