@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
namespace Discord.API.Gateway | namespace Discord.API.Gateway | ||||
{ | { | ||||
internal enum GatewayOpCode : byte | internal enum GatewayOpCode : byte | ||||
@@ -10,7 +10,7 @@ namespace Discord.API.Gateway | |||||
/// <summary> C→S - Used to associate a connection with a token and specify configuration. </summary> | /// <summary> C→S - Used to associate a connection with a token and specify configuration. </summary> | ||||
Identify = 2, | Identify = 2, | ||||
/// <summary> C→S - Used to update client's status and current game id. </summary> | /// <summary> C→S - Used to update client's status and current game id. </summary> | ||||
StatusUpdate = 3, | |||||
PresenceUpdate = 3, | |||||
/// <summary> C→S - Used to join a particular voice channel. </summary> | /// <summary> C→S - Used to join a particular voice channel. </summary> | ||||
VoiceStateUpdate = 4, | VoiceStateUpdate = 4, | ||||
/// <summary> C→S - Used to ensure the guild's voice server is alive. </summary> | /// <summary> C→S - Used to ensure the guild's voice server is alive. </summary> | ||||
@@ -16,7 +16,7 @@ namespace Discord.API.Gateway | |||||
[JsonProperty("shard")] | [JsonProperty("shard")] | ||||
public Optional<int[]> ShardingParams { get; set; } | public Optional<int[]> ShardingParams { get; set; } | ||||
[JsonProperty("presence")] | [JsonProperty("presence")] | ||||
public Optional<StatusUpdateParams> Presence { get; set; } | |||||
public Optional<PresenceUpdateParams> Presence { get; set; } | |||||
[JsonProperty("intents")] | [JsonProperty("intents")] | ||||
public Optional<int> Intents { get; set; } | public Optional<int> Intents { get; set; } | ||||
} | } | ||||
@@ -4,15 +4,16 @@ using Newtonsoft.Json; | |||||
namespace Discord.API.Gateway | namespace Discord.API.Gateway | ||||
{ | { | ||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | ||||
internal class StatusUpdateParams | |||||
internal class PresenceUpdateParams | |||||
{ | { | ||||
[JsonProperty("status")] | [JsonProperty("status")] | ||||
public UserStatus Status { get; set; } | public UserStatus Status { get; set; } | ||||
[JsonProperty("since"), Int53] | |||||
[JsonProperty("since", NullValueHandling = NullValueHandling.Include), Int53] | |||||
public long? IdleSince { get; set; } | public long? IdleSince { get; set; } | ||||
[JsonProperty("afk")] | [JsonProperty("afk")] | ||||
public bool IsAFK { get; set; } | public bool IsAFK { get; set; } | ||||
[JsonProperty("game")] | |||||
public Game Game { get; set; } | |||||
[JsonProperty("activities")] | |||||
public object[] Activities { get; set; } // TODO, change to interface later | |||||
} | } | ||||
} | } |
@@ -185,6 +185,11 @@ namespace Discord | |||||
_readyPromise.TrySetException(ex); | _readyPromise.TrySetException(ex); | ||||
_connectionPromise.TrySetException(ex); | _connectionPromise.TrySetException(ex); | ||||
_connectionCancelToken?.Cancel(); | _connectionCancelToken?.Cancel(); | ||||
_ = Task.Run(async () => | |||||
{ | |||||
await _logger.ErrorAsync($"Failed to start the connection: {ex}", ex); | |||||
}); | |||||
} | } | ||||
public void CriticalError(Exception ex) | public void CriticalError(Exception ex) | ||||
{ | { | ||||
@@ -18,7 +18,7 @@ | |||||
<DocumentationFile>..\Discord.Net.WebSocket\Discord.Net.WebSocket.xml</DocumentationFile> | <DocumentationFile>..\Discord.Net.WebSocket\Discord.Net.WebSocket.xml</DocumentationFile> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net461|AnyCPU'"> | <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net461|AnyCPU'"> | ||||
<DefineConstants>DEBUG;TRACE;DEBUG_LIMITS</DefineConstants> | |||||
<DefineConstants>TRACE</DefineConstants> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | <ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | ||||
@@ -13,7 +13,7 @@ | |||||
<member name="F:Discord.API.Gateway.GatewayOpCode.Identify"> | <member name="F:Discord.API.Gateway.GatewayOpCode.Identify"> | ||||
<summary> C→S - Used to associate a connection with a token and specify configuration. </summary> | <summary> C→S - Used to associate a connection with a token and specify configuration. </summary> | ||||
</member> | </member> | ||||
<member name="F:Discord.API.Gateway.GatewayOpCode.StatusUpdate"> | |||||
<member name="F:Discord.API.Gateway.GatewayOpCode.PresenceUpdate"> | |||||
<summary> C→S - Used to update client's status and current game id. </summary> | <summary> C→S - Used to update client's status and current game id. </summary> | ||||
</member> | </member> | ||||
<member name="F:Discord.API.Gateway.GatewayOpCode.VoiceStateUpdate"> | <member name="F:Discord.API.Gateway.GatewayOpCode.VoiceStateUpdate"> | ||||
@@ -213,6 +213,10 @@ namespace Discord.API | |||||
options.BucketId = GatewayBucket.Get(GatewayBucketType.Unbucketed).Id; | options.BucketId = GatewayBucket.Get(GatewayBucketType.Unbucketed).Id; | ||||
await RequestQueue.SendAsync(new WebSocketRequest(WebSocketClient, bytes, true, opCode == GatewayOpCode.Heartbeat, options)).ConfigureAwait(false); | await RequestQueue.SendAsync(new WebSocketRequest(WebSocketClient, bytes, true, opCode == GatewayOpCode.Heartbeat, options)).ConfigureAwait(false); | ||||
await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); | await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); | ||||
#if DEBUG | |||||
Console.WriteLine($"Sent {opCode}:\n{SerializeJson(payload)}"); | |||||
#endif | |||||
} | } | ||||
public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null) | public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null) | ||||
@@ -237,12 +241,12 @@ namespace Discord.API | |||||
if (presence.HasValue) | if (presence.HasValue) | ||||
{ | { | ||||
msg.Presence = new StatusUpdateParams | |||||
msg.Presence = new PresenceUpdateParams | |||||
{ | { | ||||
Status = presence.Value.Item1, | Status = presence.Value.Item1, | ||||
IsAFK = presence.Value.Item2, | IsAFK = presence.Value.Item2, | ||||
IdleSince = presence.Value.Item3, | IdleSince = presence.Value.Item3, | ||||
Game = presence.Value.Item4, | |||||
Activities = new object[] { presence.Value.Item4 } | |||||
}; | }; | ||||
} | } | ||||
@@ -264,18 +268,18 @@ namespace Discord.API | |||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false); | await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task SendStatusUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null) | |||||
public async Task SendPresenceUpdateAsync(UserStatus status, bool isAFK, long? since, GameModel game, RequestOptions options = null) | |||||
{ | { | ||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
var args = new StatusUpdateParams | |||||
var args = new PresenceUpdateParams | |||||
{ | { | ||||
Status = status, | Status = status, | ||||
IdleSince = since, | IdleSince = since, | ||||
IsAFK = isAFK, | IsAFK = isAFK, | ||||
Game = game | |||||
Activities = new object[] { game } | |||||
}; | }; | ||||
options.BucketId = GatewayBucket.Get(GatewayBucketType.PresenceUpdate).Id; | options.BucketId = GatewayBucket.Get(GatewayBucketType.PresenceUpdate).Id; | ||||
await SendGatewayAsync(GatewayOpCode.StatusUpdate, args, options: options).ConfigureAwait(false); | |||||
await SendGatewayAsync(GatewayOpCode.PresenceUpdate, args, options: options).ConfigureAwait(false); | |||||
} | } | ||||
public async Task SendRequestMembersAsync(IEnumerable<ulong> guildIds, RequestOptions options = null) | public async Task SendRequestMembersAsync(IEnumerable<ulong> guildIds, RequestOptions options = null) | ||||
{ | { | ||||
@@ -495,7 +495,7 @@ namespace Discord.WebSocket | |||||
var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null); | var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null); | ||||
await ApiClient.SendStatusUpdateAsync( | |||||
await ApiClient.SendPresenceUpdateAsync( | |||||
status: presence.Item1, | status: presence.Item1, | ||||
isAFK: presence.Item2, | isAFK: presence.Item2, | ||||
since: presence.Item3, | since: presence.Item3, | ||||
@@ -2,7 +2,7 @@ | |||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||||
<metadata> | <metadata> | ||||
<id>Discord.Net.Labs</id> | <id>Discord.Net.Labs</id> | ||||
<version>3.0.0-pre$suffix$</version> | |||||
<version>3.0.1-pre$suffix$</version> | |||||
<title>Discord.Net Labs</title> | <title>Discord.Net Labs</title> | ||||
<authors>Discord.Net Contributors</authors> | <authors>Discord.Net Contributors</authors> | ||||
<owners>quinchs</owners> | <owners>quinchs</owners> | ||||
@@ -14,25 +14,25 @@ | |||||
<iconUrl>https://avatars.githubusercontent.com/u/84047264</iconUrl> | <iconUrl>https://avatars.githubusercontent.com/u/84047264</iconUrl> | ||||
<dependencies> | <dependencies> | ||||
<group targetFramework="net461"> | <group targetFramework="net461"> | ||||
<dependency id="Discord.Net.Labs.Core" version="2.4.6$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Rest" version="2.4.6$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Core" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Rest" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.WebSocket" version="3.0.0-pre$suffix$" /> | <dependency id="Discord.Net.Labs.WebSocket" version="3.0.0-pre$suffix$" /> | ||||
<dependency id="Discord.Net.Labs.Commands" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Webhook" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" /> | |||||
</group> | </group> | ||||
<group targetFramework="netstandard2.0"> | <group targetFramework="netstandard2.0"> | ||||
<dependency id="Discord.Net.Labs.Core" version="2.4.6$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Rest" version="2.4.6$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Core" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Rest" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.WebSocket" version="3.0.0-pre$suffix$" /> | <dependency id="Discord.Net.Labs.WebSocket" version="3.0.0-pre$suffix$" /> | ||||
<dependency id="Discord.Net.Labs.Commands" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Webhook" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" /> | |||||
</group> | </group> | ||||
<group targetFramework="netstandard2.1"> | <group targetFramework="netstandard2.1"> | ||||
<dependency id="Discord.Net.Labs.Core" version="2.4.6$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Rest" version="2.4.6$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Core" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Rest" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.WebSocket" version="3.0.0-pre$suffix$" /> | <dependency id="Discord.Net.Labs.WebSocket" version="3.0.0-pre$suffix$" /> | ||||
<dependency id="Discord.Net.Labs.Commands" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Webhook" version="3.0.0-pre$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" /> | |||||
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" /> | |||||
</group> | </group> | ||||
</dependencies> | </dependencies> | ||||
</metadata> | </metadata> | ||||