Add new member objects to events

This commit is contained in:
Christopher F
2018-05-27 16:37:17 -04:00
parent a06e21261c
commit 8fb2c71814
4 changed files with 24 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
@@ -12,10 +12,16 @@ namespace Discord.API
public MessageType Type { get; set; } public MessageType Type { get; set; }
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
public ulong ChannelId { get; set; } public ulong ChannelId { get; set; }
// ALWAYS sent on WebSocket messages
[JsonProperty("guild_id")]
public Optional<ulong> GuildId { get; set; }
[JsonProperty("webhook_id")] [JsonProperty("webhook_id")]
public Optional<ulong> WebhookId { get; set; } public Optional<ulong> WebhookId { get; set; }
[JsonProperty("author")] [JsonProperty("author")]
public Optional<User> Author { get; set; } public Optional<User> Author { get; set; }
// ALWAYS sent on WebSocket messages
[JsonProperty("member")]
public Optional<GuildMember> Member { get; set; }
[JsonProperty("content")] [JsonProperty("content")]
public Optional<string> Content { get; set; } public Optional<string> Content { get; set; }
[JsonProperty("timestamp")] [JsonProperty("timestamp")]

View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Discord.API namespace Discord.API
@@ -11,6 +11,9 @@ namespace Discord.API
public ulong? ChannelId { get; set; } public ulong? ChannelId { get; set; }
[JsonProperty("user_id")] [JsonProperty("user_id")]
public ulong UserId { get; set; } public ulong UserId { get; set; }
// ALWAYS sent over WebSocket, never on REST
[JsonProperty("member")]
public Optional<GuildMember> Member { get; set; }
[JsonProperty("session_id")] [JsonProperty("session_id")]
public string SessionId { get; set; } public string SessionId { get; set; }
[JsonProperty("deaf")] [JsonProperty("deaf")]

View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Discord.API.Gateway namespace Discord.API.Gateway
@@ -9,6 +9,10 @@ namespace Discord.API.Gateway
public ulong UserId { get; set; } public ulong UserId { get; set; }
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
public ulong ChannelId { get; set; } public ulong ChannelId { get; set; }
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
[JsonProperty("member")]
public GuildMember Member { get; set; }
[JsonProperty("timestamp")] [JsonProperty("timestamp")]
public int Timestamp { get; set; } public int Timestamp { get; set; }
} }

View File

@@ -1091,7 +1091,7 @@ namespace Discord.WebSocket
if (author == null) if (author == null)
{ {
if (guild != 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) else if (channel is SocketGroupChannel)
author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value); author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value);
else else
@@ -1361,6 +1361,11 @@ namespace Discord.WebSocket
} }
var user = (channel as SocketChannel).GetUser(data.UserId); var user = (channel as SocketChannel).GetUser(data.UserId);
if (user == null)
{
if (guild != null)
user = guild.AddOrUpdateUser(data.Member);
}
if (user != null) if (user != null)
await TimedInvokeAsync(_userIsTypingEvent, nameof(UserIsTyping), user, channel).ConfigureAwait(false); await TimedInvokeAsync(_userIsTypingEvent, nameof(UserIsTyping), user, channel).ConfigureAwait(false);
} }
@@ -1427,7 +1432,8 @@ namespace Discord.WebSocket
user = guild.GetUser(data.UserId); user = guild.GetUser(data.UserId);
if (user == null) 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; return;
} }
} }