diff --git a/Backend/Remora.Discord.API.Abstractions/API/Gateway/Events/AuditLog/IAuditLogEntryCreate.cs b/Backend/Remora.Discord.API.Abstractions/API/Gateway/Events/AuditLog/IAuditLogEntryCreate.cs new file mode 100644 index 0000000000..5a77311887 --- /dev/null +++ b/Backend/Remora.Discord.API.Abstractions/API/Gateway/Events/AuditLog/IAuditLogEntryCreate.cs @@ -0,0 +1,34 @@ +// +// IAuditLogEntryCreate.cs +// +// Author: +// Jarl Gullberg +// +// Copyright (c) Jarl Gullberg +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using JetBrains.Annotations; +using Remora.Discord.API.Abstractions.Objects; + +namespace Remora.Discord.API.Abstractions.Gateway.Events; + +/// +/// Represents the creation of an audit log entry. +/// +[PublicAPI] +public interface IAuditLogEntryCreate : IGatewayEvent, IAuditLogEntry +{ +} diff --git a/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj b/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj index 4f20026be9..8a89ffd95f 100644 --- a/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj +++ b/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj @@ -5,7 +5,7 @@ Interface definitions of Discord's API Add UriString markers - Change attachment->image in documentation + Change attachment->image in documentation BREAKING: Re-type IMessageComponentData.cs#Values to an optional list of strings diff --git a/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj.DotSettings b/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj.DotSettings index 897a40942e..2f46ed7149 100644 --- a/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj.DotSettings +++ b/Backend/Remora.Discord.API.Abstractions/Remora.Discord.API.Abstractions.csproj.DotSettings @@ -2,6 +2,7 @@ True False True + True True True True diff --git a/Backend/Remora.Discord.API/API/Gateway/Events/AuditLog/AuditLogEntryCreate.cs b/Backend/Remora.Discord.API/API/Gateway/Events/AuditLog/AuditLogEntryCreate.cs new file mode 100644 index 0000000000..0cbb1c122f --- /dev/null +++ b/Backend/Remora.Discord.API/API/Gateway/Events/AuditLog/AuditLogEntryCreate.cs @@ -0,0 +1,42 @@ +// +// AuditLogEntryCreate.cs +// +// Author: +// Jarl Gullberg +// +// Copyright (c) Jarl Gullberg +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using System.Collections.Generic; +using JetBrains.Annotations; +using Remora.Discord.API.Abstractions.Gateway.Events; +using Remora.Discord.API.Abstractions.Objects; +using Remora.Rest.Core; + +namespace Remora.Discord.API.Gateway.Events; + +/// +[PublicAPI] +public record AuditLogEntryCreate +( + string? TargetID, + Optional> Changes, + Snowflake? UserID, + Snowflake ID, + AuditLogEvent ActionType, + Optional Options = default, + Optional Reason = default +) : IAuditLogEntryCreate; diff --git a/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs b/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs index d795d6eaa6..0db0b26af6 100644 --- a/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs @@ -207,6 +207,9 @@ private static JsonSerializerOptions AddGatewayEventConverters(this JsonSerializ options.AddDataObjectConverter() .WithPropertyName(r => r.IsEnabled, "enabled"); + // Audit logs + options.AddDataObjectConverter(); + // Channels options.AddDataObjectConverter() .WithPropertyName(c => c.IsNsfw, "nsfw") diff --git a/Tests/Remora.Discord.API.Tests/API/Gateway/Events/AuditLog/AuditLogEntryCreateTests.cs b/Tests/Remora.Discord.API.Tests/API/Gateway/Events/AuditLog/AuditLogEntryCreateTests.cs new file mode 100644 index 0000000000..916af02c9a --- /dev/null +++ b/Tests/Remora.Discord.API.Tests/API/Gateway/Events/AuditLog/AuditLogEntryCreateTests.cs @@ -0,0 +1,41 @@ +// +// AuditLogEntryCreateTests.cs +// +// Author: +// Jarl Gullberg +// +// Copyright (c) Jarl Gullberg +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using Remora.Discord.API.Abstractions.Gateway.Events; +using Remora.Discord.API.Tests.TestBases; + +namespace Remora.Discord.API.Tests.Gateway.Events; + +/// +/// Tests the IAuditLogEntryCreate event. +/// +public class AuditLogEntryCreateTests : GatewayEventTestBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The test fixture. + public AuditLogEntryCreateTests(JsonBackedTypeTestFixture fixture) + : base(fixture) + { + } +} diff --git a/Tests/Remora.Discord.API.Tests/Remora.Discord.API.Tests.csproj.DotSettings b/Tests/Remora.Discord.API.Tests/Remora.Discord.API.Tests.csproj.DotSettings index a7aaf66904..b2e8a172af 100644 --- a/Tests/Remora.Discord.API.Tests/Remora.Discord.API.Tests.csproj.DotSettings +++ b/Tests/Remora.Discord.API.Tests/Remora.Discord.API.Tests.csproj.DotSettings @@ -1,6 +1,7 @@  True True + True True True True diff --git a/Tests/Remora.Discord.Tests/Samples/Gateway/Events/AUDIT_LOG_ENTRY_CREATE/AUDIT_LOG_ENTRY_CREATE.json b/Tests/Remora.Discord.Tests/Samples/Gateway/Events/AUDIT_LOG_ENTRY_CREATE/AUDIT_LOG_ENTRY_CREATE.json new file mode 100644 index 0000000000..d11a8b23cf --- /dev/null +++ b/Tests/Remora.Discord.Tests/Samples/Gateway/Events/AUDIT_LOG_ENTRY_CREATE/AUDIT_LOG_ENTRY_CREATE.json @@ -0,0 +1,18 @@ +{ + "t": "AUDIT_LOG_ENTRY_CREATE", + "s": 3, + "op": 0, + "d": { + "target_id": "999999999999999999", + "changes": [ + { + "key": "name" + } + ], + "user_id": "999999999999999999", + "id": "999999999999999999", + "action_type": 21, + "options": { }, + "reason": "none" + } +} diff --git a/Tests/Remora.Discord.Tests/Samples/Gateway/Events/AUDIT_LOG_ENTRY_CREATE/AUDIT_LOG_ENTRY_CREATE.optionals.json b/Tests/Remora.Discord.Tests/Samples/Gateway/Events/AUDIT_LOG_ENTRY_CREATE/AUDIT_LOG_ENTRY_CREATE.optionals.json new file mode 100644 index 0000000000..185a63b835 --- /dev/null +++ b/Tests/Remora.Discord.Tests/Samples/Gateway/Events/AUDIT_LOG_ENTRY_CREATE/AUDIT_LOG_ENTRY_CREATE.optionals.json @@ -0,0 +1,11 @@ +{ + "t": "AUDIT_LOG_ENTRY_CREATE", + "s": 3, + "op": 0, + "d": { + "target_id": "999999999999999999", + "user_id": "999999999999999999", + "id": "999999999999999999", + "action_type": 21 + } +}