Skip to content

Commit

Permalink
Implement Invite Types (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherZane authored May 19, 2024
1 parent 893cc7a commit cbb8b2c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Disqord.Core/Entities/Core/Invite/IInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Disqord;
/// </summary>
public interface IInvite : IPossiblyChannelEntity, IClientEntity, IJsonUpdatable<InviteJsonModel>
{
/// <summary>
/// Gets the type of this invite.
/// </summary>
InviteType Type { get; }

/// <summary>
/// Gets the code of this invite.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class TransientInvite : TransientClientEntity<InviteJsonModel>, IInvite
/// <inheritdoc/>
public Snowflake? ChannelId => Model.Channel?.Id;

/// <inheritdoc/>
public InviteType Type => Model.Type;

/// <inheritdoc/>
public string Code => Model.Code;

Expand Down Expand Up @@ -50,7 +53,7 @@ public TransientInvite(IClient client, InviteJsonModel model)

public static IInvite Create(IClient client, InviteJsonModel model)
{
return model.Guild.HasValue
return model.Type == InviteType.Guild
? new TransientGuildInvite(client, model)
: new TransientInvite(client, model);
}
Expand Down
22 changes: 22 additions & 0 deletions src/Disqord.Core/Enums/InviteType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Disqord;

/// <summary>
/// Represents the type of an invite.
/// </summary>
public enum InviteType
{
/// <summary>
/// An invitation to a guild.
/// </summary>
Guild = 0,

/// <summary>
/// An invitation to a group private channel.
/// </summary>
Group = 1,

/// <summary>
/// An invitation to add the inviter as a friend.
/// </summary>
Friend = 2
}
3 changes: 3 additions & 0 deletions src/Disqord.Core/Models/Invite/InviteJsonModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Disqord.Models;

public class InviteJsonModel : JsonModel
{
[JsonProperty("type")]
public InviteType Type;

[JsonProperty("code")]
public string Code = null!;

Expand Down

0 comments on commit cbb8b2c

Please sign in to comment.