Browse Source

Add two new fields to the gateway event

pull/1491/head
Paulo 5 years ago
parent
commit
c21d0979f5
4 changed files with 34 additions and 4 deletions
  1. +8
    -0
      src/Discord.Net.Core/Entities/Invites/TargetUserType.cs
  2. +4
    -0
      src/Discord.Net.WebSocket/API/Gateway/InviteCreateEvent.cs
  3. +9
    -1
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  4. +13
    -3
      src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs

+ 8
- 0
src/Discord.Net.Core/Entities/Invites/TargetUserType.cs View File

@@ -0,0 +1,8 @@
namespace Discord
{
public enum TargetUserType
{
/// <summary> The invite is for a Go Live stream. </summary>
Stream = 1
}
}

+ 4
- 0
src/Discord.Net.WebSocket/API/Gateway/InviteCreateEvent.cs View File

@@ -19,6 +19,10 @@ namespace Discord.API.Gateway
public int MaxAge { get; set; } public int MaxAge { get; set; }
[JsonProperty("max_uses")] [JsonProperty("max_uses")]
public int MaxUses { get; set; } public int MaxUses { get; set; }
[JsonProperty("target_user")]
public Optional<User> TargetUser { get; set; }
[JsonProperty("target_user_type")]
public Optional<TargetUserType> TargetUserType { get; set; }
[JsonProperty("temporary")] [JsonProperty("temporary")]
public bool Temporary { get; set; } public bool Temporary { get; set; }
[JsonProperty("uses")] [JsonProperty("uses")]


+ 9
- 1
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -1658,7 +1658,15 @@ namespace Discord.WebSocket
inviter = guild.AddOrUpdateUser(data.Inviter.Value); inviter = guild.AddOrUpdateUser(data.Inviter.Value);
} }


var invite = SocketInvite.Create(this, guild, channel, inviter, data);
SocketUser target = null;
if (data.TargetUser.IsSpecified)
{
target = guild.GetUser(data.TargetUser.Value.Id);
if (target == null)
target = SocketUnknownUser.Create(this, State, data.TargetUser.Value);
}

var invite = SocketInvite.Create(this, guild, channel, inviter, target, data);


await TimedInvokeAsync(_inviteCreatedEvent, nameof(InviteCreated), invite).ConfigureAwait(false); await TimedInvokeAsync(_inviteCreatedEvent, nameof(InviteCreated), invite).ConfigureAwait(false);
} }


+ 13
- 3
src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs View File

@@ -80,22 +80,31 @@ namespace Discord.WebSocket
/// Gets when this invite was created. /// Gets when this invite was created.
/// </summary> /// </summary>
public DateTimeOffset CreatedAt => DateTimeUtils.FromTicks(_createdAtTicks); public DateTimeOffset CreatedAt => DateTimeUtils.FromTicks(_createdAtTicks);
/// <summary>
/// Gets the user targeted by this invite if available.
/// </summary>
public SocketUser TargetUser { get; private set; }
/// <summary>
/// Gets the type of the user targeted by this invite if available.
/// </summary>
public TargetUserType? TargetUserType { get; private set; }


/// <inheritdoc /> /// <inheritdoc />
public string Code => Id; public string Code => Id;
/// <inheritdoc /> /// <inheritdoc />
public string Url => $"{DiscordConfig.InviteUrl}{Code}"; public string Url => $"{DiscordConfig.InviteUrl}{Code}";


internal SocketInvite(DiscordSocketClient discord, SocketGuild guild, SocketGuildChannel channel, SocketGuildUser inviter, string id)
internal SocketInvite(DiscordSocketClient discord, SocketGuild guild, SocketGuildChannel channel, SocketGuildUser inviter, SocketUser target, string id)
: base(discord, id) : base(discord, id)
{ {
Guild = guild; Guild = guild;
Channel = channel; Channel = channel;
Inviter = inviter; Inviter = inviter;
TargetUser = target;
} }
internal static SocketInvite Create(DiscordSocketClient discord, SocketGuild guild, SocketGuildChannel channel, SocketGuildUser inviter, Model model)
internal static SocketInvite Create(DiscordSocketClient discord, SocketGuild guild, SocketGuildChannel channel, SocketGuildUser inviter, SocketUser target, Model model)
{ {
var entity = new SocketInvite(discord, guild, channel, inviter, model.Code);
var entity = new SocketInvite(discord, guild, channel, inviter, target, model.Code);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }
@@ -108,6 +117,7 @@ namespace Discord.WebSocket
MaxUses = model.MaxUses; MaxUses = model.MaxUses;
Uses = model.Uses; Uses = model.Uses;
_createdAtTicks = model.CreatedAt.UtcTicks; _createdAtTicks = model.CreatedAt.UtcTicks;
TargetUserType = model.TargetUserType.IsSpecified ? model.TargetUserType.Value : default(TargetUserType?);
} }


/// <inheritdoc /> /// <inheritdoc />


Loading…
Cancel
Save