Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions NetCord/Gateway/EventArgs/GuildJoinRequestDeleteEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NetCord.Gateway;

public class GuildJoinRequestDeleteEventArgs(JsonModels.EventArgs.JsonGuildJoinRequestDeleteEventArgs jsonModel) : IJsonModel<JsonModels.EventArgs.JsonGuildJoinRequestDeleteEventArgs>
{
JsonModels.EventArgs.JsonGuildJoinRequestDeleteEventArgs IJsonModel<JsonModels.EventArgs.JsonGuildJoinRequestDeleteEventArgs>.JsonModel => jsonModel;

public ulong JoinRequestId => jsonModel.JoinRequestId;

public ulong UserId => jsonModel.UserId;

public ulong GuildId => jsonModel.GuildId;
}
14 changes: 14 additions & 0 deletions NetCord/Gateway/EventArgs/GuildJoinRequestUpdateEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using NetCord.Rest;

namespace NetCord.Gateway;

public class GuildJoinRequestUpdateEventArgs(JsonModels.EventArgs.JsonGuildJoinRequestUpdateEventArgs jsonModel, RestClient client) : IJsonModel<JsonModels.EventArgs.JsonGuildJoinRequestUpdateEventArgs>
{
JsonModels.EventArgs.JsonGuildJoinRequestUpdateEventArgs IJsonModel<JsonModels.EventArgs.JsonGuildJoinRequestUpdateEventArgs>.JsonModel => jsonModel;

public GuildJoinRequestStatus Status => jsonModel.Status;

public GuildJoinRequest Request { get; } = new(jsonModel.Request, client);

public ulong GuildId => jsonModel.GuildId;
}
12 changes: 12 additions & 0 deletions NetCord/Gateway/GatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public partial class GatewayClient : WebSocketClient, IEntity
public event Func<Entitlement, ValueTask>? EntitlementCreate;
public event Func<Entitlement, ValueTask>? EntitlementUpdate;
public event Func<Entitlement, ValueTask>? EntitlementDelete;
public event Func<GuildJoinRequestUpdateEventArgs, ValueTask>? GuildJoinRequestUpdate;
public event Func<GuildJoinRequestDeleteEventArgs, ValueTask>? GuildJoinRequestDelete;
public event Func<UnknownEventEventArgs, ValueTask>? UnknownEvent;

/// <summary>
Expand Down Expand Up @@ -717,6 +719,16 @@ await InvokeEventAsync(
await InvokeEventAsync(EntitlementDelete, () => new(data.ToObject(Serialization.Default.JsonEntitlement))).ConfigureAwait(false);
}
break;
case "GUILD_JOIN_REQUEST_UPDATE":
{
await InvokeEventAsync(GuildJoinRequestUpdate, () => new(data.ToObject(Serialization.Default.JsonGuildJoinRequestUpdateEventArgs), Rest)).ConfigureAwait(false);
}
break;
case "GUILD_JOIN_REQUEST_DELETE":
{
await InvokeEventAsync(GuildJoinRequestDelete, () => new(data.ToObject(Serialization.Default.JsonGuildJoinRequestDeleteEventArgs))).ConfigureAwait(false);
}
break;
default:
{
await InvokeEventAsync(UnknownEvent, () => new(name, data)).ConfigureAwait(false);
Expand Down
20 changes: 20 additions & 0 deletions NetCord/Gateway/GuildJoinRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NetCord.Rest;

namespace NetCord.Gateway;
Comment thread
KubaZ2 marked this conversation as resolved.

public class GuildJoinRequest(JsonModels.JsonGuildJoinRequest jsonModel, RestClient client) : Entity, IJsonModel<JsonModels.JsonGuildJoinRequest>
{
JsonModels.JsonGuildJoinRequest IJsonModel<JsonModels.JsonGuildJoinRequest>.JsonModel => jsonModel;

public override ulong Id => jsonModel.Id;
public GuildJoinRequestStatus ApplicationStatus => jsonModel.ApplicationStatus;
//public DateTimeOffset CreatedAt => jsonModel.CreatedAt;
public ulong GuildId => jsonModel.GuildId;
public DateTimeOffset LastSeenAt => jsonModel.LastSeenAt;
public string? RejectionReason => jsonModel.RejectionReason;
public ulong UserId => jsonModel.UserId;
public User User { get; } = new(jsonModel.User, client);
public IReadOnlyList<GuildJoinRequestFormResponse> FormResponses { get; } = jsonModel.FormResponses.Select(e => new GuildJoinRequestFormResponse(e)).ToArray();
public User ActionedByUser { get; } = new(jsonModel.ActionedByUser, client);
public ulong ActionedAt => jsonModel.ActionedAt;
}
12 changes: 12 additions & 0 deletions NetCord/Gateway/GuildJoinRequestFormResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NetCord.Gateway;

public class GuildJoinRequestFormResponse(JsonModels.JsonGuildJoinRequestFormResponse jsonModel) : IJsonModel<JsonModels.JsonGuildJoinRequestFormResponse>
{
JsonModels.JsonGuildJoinRequestFormResponse IJsonModel<JsonModels.JsonGuildJoinRequestFormResponse>.JsonModel => jsonModel;

public GuildJoinRequestFormResponseFieldType FieldType => jsonModel.FieldType;
public string Label => jsonModel.Label;
public bool Required => jsonModel.Required;
public bool IsResponse => jsonModel.Response;
public IReadOnlyList<string> Values => jsonModel.Values;
}
20 changes: 20 additions & 0 deletions NetCord/Gateway/GuildJoinRequestFormResponseFieldType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;

namespace NetCord.Gateway;

[JsonConverter(typeof(JsonConverters.StringEnumConverterWithErrorHandling<GuildJoinRequestFormResponseFieldType>))]
public enum GuildJoinRequestFormResponseFieldType
{
[JsonPropertyName("TERMS")]
Terms,
[JsonPropertyName("TEXT_INPUT")]
TextInput,
[JsonPropertyName("PARAGRAPH")]
Paragraph,
[JsonPropertyName("MULTIPLE_CHOICE")]
MultipleChoice,
[JsonPropertyName("VERIFICATION")]
Verification,
[JsonPropertyName("FILE_UPLOAD")]
FileUpload,
}
16 changes: 16 additions & 0 deletions NetCord/Gateway/GuildJoinRequestStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace NetCord.Gateway;
Comment thread
KubaZ2 marked this conversation as resolved.

[JsonConverter(typeof(JsonConverters.StringEnumConverterWithErrorHandling<GuildJoinRequestStatus>))]
public enum GuildJoinRequestStatus
{
[JsonPropertyName("STARTED")]
Started,
[JsonPropertyName("PENDING")]
Pending,
[JsonPropertyName("REJECTED")]
Rejected,
[JsonPropertyName("APPROVED")]
Approved,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;

namespace NetCord.Gateway.JsonModels.EventArgs;

public class JsonGuildJoinRequestDeleteEventArgs
{
[JsonPropertyName("id")]
public ulong JoinRequestId { get; set; }

[JsonPropertyName("user_id")]
public ulong UserId { get; set; }

[JsonPropertyName("guild_id")]
public ulong GuildId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;

namespace NetCord.Gateway.JsonModels.EventArgs;

public class JsonGuildJoinRequestUpdateEventArgs
{
[JsonPropertyName("status")]
public GuildJoinRequestStatus Status { get; set; }

[JsonPropertyName("request")]
public JsonGuildJoinRequest Request { get; set; }

[JsonPropertyName("guild_id")]
public ulong GuildId { get; set; }
}
38 changes: 38 additions & 0 deletions NetCord/Gateway/JsonModels/JsonGuildJoinRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Text.Json.Serialization;

using NetCord.JsonModels;

namespace NetCord.Gateway.JsonModels;
Comment thread
KubaZ2 marked this conversation as resolved.

public class JsonGuildJoinRequest : JsonEntity
{
[JsonPropertyName("application_status")]
public GuildJoinRequestStatus ApplicationStatus { get; set; }

//[JsonPropertyName("created_at")]
//public DateTimeOffset CreatedAt { get; set; }

[JsonPropertyName("guild_id")]
public ulong GuildId { get; set; }

[JsonPropertyName("last_seen")]
public DateTimeOffset LastSeenAt { get; set; }

[JsonPropertyName("rejection_reason")]
public string? RejectionReason { get; set; }

[JsonPropertyName("user_id")]
public ulong UserId { get; set; }

[JsonPropertyName("user")]
public JsonUser User { get; set; }

[JsonPropertyName("form_responses")]
public IReadOnlyList<JsonGuildJoinRequestFormResponse> FormResponses { get; set; }

[JsonPropertyName("actioned_by_user")]
public JsonUser ActionedByUser { get; set; }

[JsonPropertyName("actioned_at")]
public ulong ActionedAt { get; set; }
}
24 changes: 24 additions & 0 deletions NetCord/Gateway/JsonModels/JsonGuildJoinRequestFormResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Text.Json.Serialization;

namespace NetCord.Gateway.JsonModels;

public partial class JsonGuildJoinRequestFormResponse
{
[JsonPropertyName("field_type")]
public GuildJoinRequestFormResponseFieldType FieldType { get; set; }

[JsonPropertyName("label")]
public string Label { get; set; }

[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonPropertyName("required")]
public bool Required { get; set; }

[JsonPropertyName("response")]
public bool Response { get; set; }

[JsonPropertyName("values")]
public IReadOnlyList<string> Values { get; set; }
}
30 changes: 30 additions & 0 deletions NetCord/Gateway/ShardedGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ private void HookEvents(GatewayClient client)
HookEvent(client, _entitlementCreateLock, ref _entitlementCreate, a => _entitlementCreate!(client, a), (c, e) => c.EntitlementCreate += e);
HookEvent(client, _entitlementUpdateLock, ref _entitlementUpdate, a => _entitlementUpdate!(client, a), (c, e) => c.EntitlementUpdate += e);
HookEvent(client, _entitlementDeleteLock, ref _entitlementDelete, a => _entitlementDelete!(client, a), (c, e) => c.EntitlementDelete += e);
HookEvent(client, _guildJoinRequestUpdateLock, ref _guildJoinRequestUpdate, a => _guildJoinRequestUpdate!(client, a), (c, e) => c.GuildJoinRequestUpdate += e);
HookEvent(client, _guildJoinRequestDeleteLock, ref _guildJoinRequestDelete, a => _guildJoinRequestDelete!(client, a), (c, e) => c.GuildJoinRequestDelete += e);
HookEvent(client, _unknownEventLock, ref _unknownEvent, a => _unknownEvent!(client, a), (c, e) => c.UnknownEvent += e);
}

Expand Down Expand Up @@ -1309,6 +1311,34 @@ public event Func<GatewayClient, Entitlement, ValueTask>? EntitlementDelete
}
}

private readonly object _guildJoinRequestUpdateLock = new();
private Func<GatewayClient, GuildJoinRequestUpdateEventArgs, ValueTask>? _guildJoinRequestUpdate;
public event Func<GatewayClient, GuildJoinRequestUpdateEventArgs, ValueTask>? GuildJoinRequestUpdate
{
add
{
HookEvent(_guildJoinRequestUpdateLock, value, ref _guildJoinRequestUpdate, client => a => _guildJoinRequestUpdate!(client, a), (c, e) => c.GuildJoinRequestUpdate += e);
}
remove
{
UnhookEvent(_guildJoinRequestUpdateLock, value, ref _guildJoinRequestUpdate, (c, e) => c.GuildJoinRequestUpdate -= e);
}
}

private readonly object _guildJoinRequestDeleteLock = new();
private Func<GatewayClient, GuildJoinRequestDeleteEventArgs, ValueTask>? _guildJoinRequestDelete;
public event Func<GatewayClient, GuildJoinRequestDeleteEventArgs, ValueTask>? GuildJoinRequestDelete
{
add
{
HookEvent(_guildJoinRequestDeleteLock, value, ref _guildJoinRequestDelete, client => a => _guildJoinRequestDelete!(client, a), (c, e) => c.GuildJoinRequestDelete += e);
}
remove
{
UnhookEvent(_guildJoinRequestDeleteLock, value, ref _guildJoinRequestDelete, (c, e) => c.GuildJoinRequestDelete -= e);
}
}

private readonly object _unknownEventLock = new();
private Func<GatewayClient, UnknownEventEventArgs, ValueTask>? _unknownEvent;
public event Func<GatewayClient, UnknownEventEventArgs, ValueTask>? UnknownEvent
Expand Down
2 changes: 2 additions & 0 deletions NetCord/Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ namespace NetCord;
[JsonSerializable(typeof(GuildUsersSearchTimestamp))]
[JsonSerializable(typeof(JsonGuildUserSearchResult))]
[JsonSerializable(typeof(GuildUsersSearchPaginationProperties))]
[JsonSerializable(typeof(JsonGuildJoinRequestUpdateEventArgs))]
[JsonSerializable(typeof(JsonGuildJoinRequestDeleteEventArgs))]
internal partial class Serialization : JsonSerializerContext
{
}