Skip to content

Commit

Permalink
Implement support for AUDIT_LOG_ENTRY_CREATE.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Jan 18, 2023
1 parent ddf62de commit 5b80a61
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// IAuditLogEntryCreate.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// 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 <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents the creation of an audit log entry.
/// </summary>
[PublicAPI]
public interface IAuditLogEntryCreate : IGatewayEvent, IAuditLogEntry
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>Interface definitions of Discord's API</Description>
<PackageReleaseNotes>
Add UriString markers
Change attachment->image in documentation
Change attachment-&gt;image in documentation
BREAKING: Re-type IMessageComponentData.cs#Values to an optional list of strings
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway/@EntryIndexedValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Capplicationcommands/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cauditlog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cautomoderation/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cchannels/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cconnectingresuming/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// AuditLogEntryCreate.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// 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 <http://www.gnu.org/licenses/>.
//

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;

/// <inheritdoc />
[PublicAPI]
public record AuditLogEntryCreate
(
string? TargetID,
Optional<IReadOnlyList<IAuditLogChange>> Changes,
Snowflake? UserID,
Snowflake ID,
AuditLogEvent ActionType,
Optional<IOptionalAuditEntryInfo> Options = default,
Optional<string> Reason = default
) : IAuditLogEntryCreate;
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ private static JsonSerializerOptions AddGatewayEventConverters(this JsonSerializ
options.AddDataObjectConverter<IAutoModerationRuleDelete, AutoModerationRuleDelete>()
.WithPropertyName(r => r.IsEnabled, "enabled");

// Audit logs
options.AddDataObjectConverter<IAuditLogEntryCreate, AuditLogEntryCreate>();

// Channels
options.AddDataObjectConverter<IChannelCreate, ChannelCreate>()
.WithPropertyName(c => c.IsNsfw, "nsfw")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// AuditLogEntryCreateTests.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// 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 <http://www.gnu.org/licenses/>.
//

using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Tests.TestBases;

namespace Remora.Discord.API.Tests.Gateway.Events;

/// <summary>
/// Tests the IAuditLogEntryCreate event.
/// </summary>
public class AuditLogEntryCreateTests : GatewayEventTestBase<IAuditLogEntryCreate>
{
/// <summary>
/// Initializes a new instance of the <see cref="AuditLogEntryCreateTests"/> class.
/// </summary>
/// <param name="fixture">The test fixture.</param>
public AuditLogEntryCreateTests(JsonBackedTypeTestFixture fixture)
: base(fixture)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Capplicationcommands/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cauditlog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cautomoderation/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cchannels/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=api_005Cgateway_005Cevents_005Cconnectingresuming/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 5b80a61

Please sign in to comment.