Skip to content

Commit

Permalink
Add self_video to VoiceState (#2137)
Browse files Browse the repository at this point in the history
* Add self_video to VoiceState

* Update selfVideo flag
  • Loading branch information
EpicOfficer committed Mar 2, 2022
1 parent 3e52fab commit 8bcd3da
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Discord.Net.Core/Entities/Users/IVoiceState.cs
Expand Up @@ -65,6 +65,13 @@ public interface IVoiceState
/// </returns>
bool IsStreaming { get; }
/// <summary>
/// Gets a value that indicates if the user is videoing in a voice channel.
/// </summary>
/// <returns>
/// <c>true</c> if the user has their camera turned on; otherwise <c>false</c>.
/// </returns>
bool IsVideoing { get; }
/// <summary>
/// Gets the time on which the user requested to speak.
/// </summary>
DateTimeOffset? RequestToSpeakTimestamp { get; }
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/API/Common/VoiceState.cs
Expand Up @@ -28,6 +28,8 @@ internal class VoiceState
public bool Suppress { get; set; }
[JsonProperty("self_stream")]
public bool SelfStream { get; set; }
[JsonProperty("self_video")]
public bool SelfVideo { get; set; }
[JsonProperty("request_to_speak_timestamp")]
public Optional<DateTimeOffset?> RequestToSpeakTimestamp { get; set; }
}
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs
Expand Up @@ -41,6 +41,8 @@ internal new static RestGroupUser Create(BaseDiscordClient discord, Model model)
/// <inheritdoc />
bool IVoiceState.IsStreaming => false;
/// <inheritdoc />
bool IVoiceState.IsVideoing => false;
/// <inheritdoc />
DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null;
#endregion
}
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
Expand Up @@ -223,6 +223,8 @@ IGuild IGuildUser.Guild
/// <inheritdoc />
bool IVoiceState.IsStreaming => false;
/// <inheritdoc />
bool IVoiceState.IsVideoing => false;
/// <inheritdoc />
DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null;
#endregion
}
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
Expand Up @@ -131,6 +131,8 @@ IGuild IGuildUser.Guild
/// <inheritdoc />
bool IVoiceState.IsStreaming => false;
/// <inheritdoc />
bool IVoiceState.IsVideoing => false;
/// <inheritdoc />
DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null;
#endregion
}
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs
Expand Up @@ -70,6 +70,8 @@ internal static SocketGroupUser Create(SocketGroupChannel channel, ClientState s
/// <inheritdoc />
bool IVoiceState.IsStreaming => false;
/// <inheritdoc />
bool IVoiceState.IsVideoing => false;
/// <inheritdoc />
DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null;
#endregion
}
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
Expand Up @@ -65,6 +65,8 @@ public class SocketGuildUser : SocketUser, IGuildUser
/// <inheritdoc />
public bool IsStreaming => VoiceState?.IsStreaming ?? false;
/// <inheritdoc />
public bool IsVideoing => VoiceState?.IsVideoing ?? false;
/// <inheritdoc />
public DateTimeOffset? RequestToSpeakTimestamp => VoiceState?.RequestToSpeakTimestamp ?? null;
/// <inheritdoc />
public bool? IsPending { get; private set; }
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
Expand Up @@ -122,6 +122,10 @@ public string VoiceSessionId
public bool IsStreaming
=> GuildUser.IsStreaming;

/// <inheritdoc/>
public bool IsVideoing
=> GuildUser.IsVideoing;

/// <inheritdoc/>
public DateTimeOffset? RequestToSpeakTimestamp
=> GuildUser.RequestToSpeakTimestamp;
Expand Down
11 changes: 8 additions & 3 deletions src/Discord.Net.WebSocket/Entities/Users/SocketVoiceState.cs
Expand Up @@ -13,7 +13,7 @@ public struct SocketVoiceState : IVoiceState
/// <summary>
/// Initializes a default <see cref="SocketVoiceState"/> with everything set to <c>null</c> or <c>false</c>.
/// </summary>
public static readonly SocketVoiceState Default = new SocketVoiceState(null, null, null, false, false, false, false, false, false);
public static readonly SocketVoiceState Default = new SocketVoiceState(null, null, null, false, false, false, false, false, false, false);

[Flags]
private enum Flags : byte
Expand All @@ -25,6 +25,7 @@ private enum Flags : byte
SelfMuted = 0x08,
SelfDeafened = 0x10,
SelfStream = 0x20,
SelfVideo = 0x40,
}

private readonly Flags _voiceStates;
Expand All @@ -50,9 +51,11 @@ private enum Flags : byte
public bool IsSelfDeafened => (_voiceStates & Flags.SelfDeafened) != 0;
/// <inheritdoc />
public bool IsStreaming => (_voiceStates & Flags.SelfStream) != 0;
/// <inheritdoc />
public bool IsVideoing => (_voiceStates & Flags.SelfVideo) != 0;


internal SocketVoiceState(SocketVoiceChannel voiceChannel, DateTimeOffset? requestToSpeak, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isMuted, bool isDeafened, bool isSuppressed, bool isStream)
internal SocketVoiceState(SocketVoiceChannel voiceChannel, DateTimeOffset? requestToSpeak, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isMuted, bool isDeafened, bool isSuppressed, bool isStream, bool isVideo)
{
VoiceChannel = voiceChannel;
VoiceSessionId = sessionId;
Expand All @@ -71,11 +74,13 @@ internal SocketVoiceState(SocketVoiceChannel voiceChannel, DateTimeOffset? reque
voiceStates |= Flags.Suppressed;
if (isStream)
voiceStates |= Flags.SelfStream;
if (isVideo)
voiceStates |= Flags.SelfVideo;
_voiceStates = voiceStates;
}
internal static SocketVoiceState Create(SocketVoiceChannel voiceChannel, Model model)
{
return new SocketVoiceState(voiceChannel, model.RequestToSpeakTimestamp.IsSpecified ? model.RequestToSpeakTimestamp.Value : null, model.SessionId, model.SelfMute, model.SelfDeaf, model.Mute, model.Deaf, model.Suppress, model.SelfStream);
return new SocketVoiceState(voiceChannel, model.RequestToSpeakTimestamp.IsSpecified ? model.RequestToSpeakTimestamp.Value : null, model.SessionId, model.SelfMute, model.SelfDeaf, model.Mute, model.Deaf, model.Suppress, model.SelfStream, model.SelfVideo);
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs
Expand Up @@ -164,6 +164,8 @@ internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, M
/// <inheritdoc />
bool IVoiceState.IsStreaming => false;
/// <inheritdoc />
bool IVoiceState.IsVideoing => false;
/// <inheritdoc />
DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null;
#endregion
}
Expand Down

0 comments on commit 8bcd3da

Please sign in to comment.