From 8fb2c71814fad9bcab1888fb8d66d693cc98a4b1 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 27 May 2018 16:37:17 -0400 Subject: [PATCH 1/4] Add new member objects to events --- src/Discord.Net.Rest/API/Common/Message.cs | 8 +++++++- src/Discord.Net.Rest/API/Common/VoiceState.cs | 5 ++++- .../API/Gateway/TypingStartEvent.cs | 6 +++++- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 10 ++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Discord.Net.Rest/API/Common/Message.cs b/src/Discord.Net.Rest/API/Common/Message.cs index 9a7629b96..229249ccf 100644 --- a/src/Discord.Net.Rest/API/Common/Message.cs +++ b/src/Discord.Net.Rest/API/Common/Message.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS1591 +#pragma warning disable CS1591 using Newtonsoft.Json; using System; @@ -12,10 +12,16 @@ namespace Discord.API public MessageType Type { get; set; } [JsonProperty("channel_id")] public ulong ChannelId { get; set; } + // ALWAYS sent on WebSocket messages + [JsonProperty("guild_id")] + public Optional GuildId { get; set; } [JsonProperty("webhook_id")] public Optional WebhookId { get; set; } [JsonProperty("author")] public Optional Author { get; set; } + // ALWAYS sent on WebSocket messages + [JsonProperty("member")] + public Optional Member { get; set; } [JsonProperty("content")] public Optional Content { get; set; } [JsonProperty("timestamp")] diff --git a/src/Discord.Net.Rest/API/Common/VoiceState.cs b/src/Discord.Net.Rest/API/Common/VoiceState.cs index 563a5f95b..b1f937b09 100644 --- a/src/Discord.Net.Rest/API/Common/VoiceState.cs +++ b/src/Discord.Net.Rest/API/Common/VoiceState.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS1591 +#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API @@ -11,6 +11,9 @@ namespace Discord.API public ulong? ChannelId { get; set; } [JsonProperty("user_id")] public ulong UserId { get; set; } + // ALWAYS sent over WebSocket, never on REST + [JsonProperty("member")] + public Optional Member { get; set; } [JsonProperty("session_id")] public string SessionId { get; set; } [JsonProperty("deaf")] diff --git a/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs index 3cce512bd..5ceae4b7a 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS1591 +#pragma warning disable CS1591 using Newtonsoft.Json; namespace Discord.API.Gateway @@ -9,6 +9,10 @@ namespace Discord.API.Gateway public ulong UserId { get; set; } [JsonProperty("channel_id")] public ulong ChannelId { get; set; } + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } + [JsonProperty("member")] + public GuildMember Member { get; set; } [JsonProperty("timestamp")] public int Timestamp { get; set; } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 01322a3cc..d66252835 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1091,7 +1091,7 @@ namespace Discord.WebSocket if (author == null) { if (guild != null) - author = guild.AddOrUpdateUser(data.Author.Value); //User has no guild-specific data + author = guild.AddOrUpdateUser(data.Member.Value); //per g250k, we can create an entire member now else if (channel is SocketGroupChannel) author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value); else @@ -1361,6 +1361,11 @@ namespace Discord.WebSocket } var user = (channel as SocketChannel).GetUser(data.UserId); + if (user == null) + { + if (guild != null) + user = guild.AddOrUpdateUser(data.Member); + } if (user != null) await TimedInvokeAsync(_userIsTypingEvent, nameof(UserIsTyping), user, channel).ConfigureAwait(false); } @@ -1427,7 +1432,8 @@ namespace Discord.WebSocket user = guild.GetUser(data.UserId); if (user == null) { - await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false); + user = guild.AddOrUpdateUser(data.Member.Value); //per g250k, this is always sent + //await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false); return; } } From c0c565fd7ee03fa569027fff7f17db90d9376b4f Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 27 May 2018 16:45:54 -0400 Subject: [PATCH 2/4] retain fallback case for if user is still null --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index d66252835..2dccd9321 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1429,11 +1429,10 @@ namespace Discord.WebSocket after = SocketVoiceState.Create(null, data); } - user = guild.GetUser(data.UserId); + user = guild.GetUser(data.UserId) ?? guild.AddOrUpdateUser(data.Member.Value); //per g250k, this is always sent if (user == null) { - user = guild.AddOrUpdateUser(data.Member.Value); //per g250k, this is always sent - //await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false); + await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false); return; } } From adf4da19fc116759c4246c978143987712fa2116 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 27 May 2018 17:56:14 -0400 Subject: [PATCH 3/4] fix: Properly rethrow exceptions in SocketGuild audio client --- src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 14263f0af..9a9f46baa 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -549,10 +549,10 @@ namespace Discord.WebSocket await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); } - catch (Exception) + catch (Exception e) { await DisconnectAudioInternalAsync().ConfigureAwait(false); - throw; + throw e; } finally { @@ -566,10 +566,10 @@ namespace Discord.WebSocket throw new TimeoutException(); return await promise.Task.ConfigureAwait(false); } - catch (Exception) + catch (Exception e) { await DisconnectAudioAsync().ConfigureAwait(false); - throw; + throw e; } } From 237ad0f8675023478ec8ad41c7b6b6fd19ceed2d Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 27 May 2018 18:00:51 -0400 Subject: [PATCH 4/4] Revert "fix: Properly rethrow exceptions in SocketGuild audio client" This reverts commit adf4da19fc116759c4246c978143987712fa2116. Someone hasn't written c# in a while --- src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 9a9f46baa..14263f0af 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -549,10 +549,10 @@ namespace Discord.WebSocket await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); } - catch (Exception e) + catch (Exception) { await DisconnectAudioInternalAsync().ConfigureAwait(false); - throw e; + throw; } finally { @@ -566,10 +566,10 @@ namespace Discord.WebSocket throw new TimeoutException(); return await promise.Task.ConfigureAwait(false); } - catch (Exception e) + catch (Exception) { await DisconnectAudioAsync().ConfigureAwait(false); - throw e; + throw; } }