@@ -9,9 +9,13 @@ namespace Discord.API.Client.GatewaySocket | |||||
object IWebSocketMessage.Payload => this; | object IWebSocketMessage.Payload => this; | ||||
bool IWebSocketMessage.IsPrivate => false; | bool IWebSocketMessage.IsPrivate => false; | ||||
[JsonProperty("idle_since")] | |||||
[JsonProperty("afk")] | |||||
public bool? Afk { get; set; } | |||||
[JsonProperty("since")] | |||||
public long? IdleSince { get; set; } | public long? IdleSince { get; set; } | ||||
[JsonProperty("game")] | [JsonProperty("game")] | ||||
public Game Game { get; set; } | public Game Game { get; set; } | ||||
[JsonProperty("status")] | |||||
public string Status { get; set; } | |||||
} | } | ||||
} | } |
@@ -324,8 +324,8 @@ namespace Discord | |||||
public void SetStatus(UserStatus status) | public void SetStatus(UserStatus status) | ||||
{ | { | ||||
if (status == null) throw new ArgumentNullException(nameof(status)); | if (status == null) throw new ArgumentNullException(nameof(status)); | ||||
if (status != UserStatus.Online && status != UserStatus.Idle) | |||||
throw new ArgumentException($"Invalid status, must be {UserStatus.Online} or {UserStatus.Idle}", nameof(status)); | |||||
if (status != UserStatus.Online && status != UserStatus.Idle && status != UserStatus.DoNotDisturb) | |||||
throw new ArgumentException($"Invalid status, must be {UserStatus.Online}, {UserStatus.Idle} or {UserStatus.DoNotDisturb}", nameof(status)); | |||||
Status = status; | Status = status; | ||||
SendStatus(); | SendStatus(); | ||||
@@ -360,7 +360,7 @@ namespace Discord | |||||
} | } | ||||
var socket = GatewaySocket; | var socket = GatewaySocket; | ||||
if (socket != null) | if (socket != null) | ||||
socket.SendUpdateStatus(Status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, CurrentGame); | |||||
socket.SendUpdateStatus(Status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, CurrentGame, Status == UserStatus.Idle, Status); | |||||
} | } | ||||
#region Channels | #region Channels | ||||
@@ -8,6 +8,8 @@ | |||||
public static UserStatus Idle { get; } = new UserStatus("idle"); | public static UserStatus Idle { get; } = new UserStatus("idle"); | ||||
/// <summary> User is offline. </summary> | /// <summary> User is offline. </summary> | ||||
public static UserStatus Offline { get; } = new UserStatus("offline"); | public static UserStatus Offline { get; } = new UserStatus("offline"); | ||||
/// <summary> User is busy. </summary> | |||||
public static UserStatus DoNotDisturb { get; } = new UserStatus("dnd"); | |||||
private UserStatus(string value) | private UserStatus(string value) | ||||
: base(value) { } | : base(value) { } | ||||
@@ -24,6 +26,8 @@ | |||||
return Idle; | return Idle; | ||||
case "offline": | case "offline": | ||||
return Offline; | return Offline; | ||||
case "dnd": | |||||
return DoNotDisturb; | |||||
default: | default: | ||||
return new UserStatus(value); | return new UserStatus(value); | ||||
} | } | ||||
@@ -170,11 +170,13 @@ namespace Discord.Net.WebSockets | |||||
=> QueueMessage(new ResumeCommand { SessionId = SessionId, Sequence = _lastSequence }); | => QueueMessage(new ResumeCommand { SessionId = SessionId, Sequence = _lastSequence }); | ||||
public override void SendHeartbeat() | public override void SendHeartbeat() | ||||
=> QueueMessage(new HeartbeatCommand()); | => QueueMessage(new HeartbeatCommand()); | ||||
public void SendUpdateStatus(long? idleSince, Game? game) | |||||
public void SendUpdateStatus(long? idleSince, Game? game, bool? afk, UserStatus status) | |||||
=> QueueMessage(new UpdateStatusCommand | => QueueMessage(new UpdateStatusCommand | ||||
{ | { | ||||
IdleSince = idleSince, | IdleSince = idleSince, | ||||
Game = game != null ? new APIGame { Name = game.Value.Name, Type = game.Value.Type, Url = game.Value.Url } : null | |||||
Game = game != null ? new APIGame { Name = game.Value.Name, Type = game.Value.Type, Url = game.Value.Url } : null, | |||||
Afk = afk, | |||||
Status = status.Value | |||||
}); | }); | ||||
public void SendUpdateVoice(ulong? serverId, ulong? channelId, bool isSelfMuted, bool isSelfDeafened) | public void SendUpdateVoice(ulong? serverId, ulong? channelId, bool isSelfMuted, bool isSelfDeafened) | ||||
=> QueueMessage(new UpdateVoiceCommand { GuildId = serverId, ChannelId = channelId, IsSelfMuted = isSelfMuted, IsSelfDeafened = isSelfDeafened }); | => QueueMessage(new UpdateVoiceCommand { GuildId = serverId, ChannelId = channelId, IsSelfMuted = isSelfMuted, IsSelfDeafened = isSelfDeafened }); | ||||