Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Invite Types #114

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading