From d382e5cd489a7a2b6a37ee3c3d5c9425e3227a10 Mon Sep 17 00:00:00 2001 From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> Date: Tue, 26 Dec 2023 01:34:25 +0300 Subject: [PATCH] [Feature] Audit log integration type (#2814) * why do I do this instead of preparing for an exam * oh yeah nullable ofc * oh yeah --- src/Discord.Net.Rest/API/Common/AuditLogOptions.cs | 3 +++ .../Entities/AuditLogs/DataTypes/KickAuditLogData.cs | 10 ++++++++-- .../AuditLogs/DataTypes/MemberRoleAuditLogData.cs | 10 ++++++++-- .../AuditLogs/DataTypes/SocketKickAuditLogData.cs | 10 ++++++++-- .../DataTypes/SocketMemberRoleAuditLogData.cs | 10 ++++++++-- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/Discord.Net.Rest/API/Common/AuditLogOptions.cs b/src/Discord.Net.Rest/API/Common/AuditLogOptions.cs index ea6339f2..41292ca0 100644 --- a/src/Discord.Net.Rest/API/Common/AuditLogOptions.cs +++ b/src/Discord.Net.Rest/API/Common/AuditLogOptions.cs @@ -39,4 +39,7 @@ internal class AuditLogOptions [JsonProperty("status")] public string Status { get; set; } + + [JsonProperty("integration_type")] + public string IntegrationType { get; set; } } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/KickAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/KickAuditLogData.cs index 99b385d8..610983c1 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/KickAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/KickAuditLogData.cs @@ -9,15 +9,16 @@ namespace Discord.Rest; /// public class KickAuditLogData : IAuditLogData { - private KickAuditLogData(RestUser user) + private KickAuditLogData(RestUser user, string integrationType) { Target = user; + IntegrationType = integrationType; } internal static KickAuditLogData Create(BaseDiscordClient discord, EntryModel entry, Model log = null) { var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); - return new KickAuditLogData((userInfo != null) ? RestUser.Create(discord, userInfo) : null); + return new KickAuditLogData((userInfo != null) ? RestUser.Create(discord, userInfo) : null, entry.Options?.IntegrationType); } /// @@ -30,4 +31,9 @@ public class KickAuditLogData : IAuditLogData /// A user object representing the kicked user. /// public IUser Target { get; } + + /// + /// Gets the type of integration which performed the action. if the action was performed by a user. + /// + public string IntegrationType { get; } } diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs index 7bc59f51..eb91ff2c 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/MemberRoleAuditLogData.cs @@ -10,10 +10,11 @@ namespace Discord.Rest; /// public class MemberRoleAuditLogData : IAuditLogData { - private MemberRoleAuditLogData(IReadOnlyCollection roles, IUser target) + private MemberRoleAuditLogData(IReadOnlyCollection roles, IUser target, string integrationType) { Roles = roles; Target = target; + IntegrationType = integrationType; } internal static MemberRoleAuditLogData Create(BaseDiscordClient discord, EntryModel entry, Model log = null) @@ -28,7 +29,7 @@ public class MemberRoleAuditLogData : IAuditLogData var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); RestUser user = (userInfo != null) ? RestUser.Create(discord, userInfo) : null; - return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user); + return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user, entry.Options?.IntegrationType); } /// @@ -47,4 +48,9 @@ public class MemberRoleAuditLogData : IAuditLogData /// A user object representing the user that the role changes were performed on. /// public IUser Target { get; } + + /// + /// Gets the type of integration which performed the action. if the action was performed by a user. + /// + public string IntegrationType { get; } } diff --git a/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketKickAuditLogData.cs b/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketKickAuditLogData.cs index df3f800d..09263ea8 100644 --- a/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketKickAuditLogData.cs +++ b/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketKickAuditLogData.cs @@ -9,9 +9,10 @@ namespace Discord.WebSocket; /// public class SocketKickAuditLogData : ISocketAuditLogData { - private SocketKickAuditLogData(Cacheable user) + private SocketKickAuditLogData(Cacheable user, string integrationType) { Target = user; + IntegrationType = integrationType; } internal static SocketKickAuditLogData Create(DiscordSocketClient discord, EntryModel entry) @@ -26,7 +27,7 @@ public class SocketKickAuditLogData : ISocketAuditLogData var user = await discord.ApiClient.GetUserAsync(entry.TargetId!.Value); return user is not null ? RestUser.Create(discord, user) : null; }); - return new SocketKickAuditLogData(cacheableUser); + return new SocketKickAuditLogData(cacheableUser, entry.Options?.IntegrationType); } /// @@ -40,4 +41,9 @@ public class SocketKickAuditLogData : ISocketAuditLogData /// A cacheable user object representing the kicked user. /// public Cacheable Target { get; } + + /// + /// Gets the type of integration which performed the action. if the action was performed by a user. + /// + public string IntegrationType { get; } } diff --git a/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketMemberRoleAuditLogData.cs b/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketMemberRoleAuditLogData.cs index ad6c715f..84b64a9c 100644 --- a/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketMemberRoleAuditLogData.cs +++ b/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketMemberRoleAuditLogData.cs @@ -10,10 +10,11 @@ namespace Discord.WebSocket; /// public class SocketMemberRoleAuditLogData : ISocketAuditLogData { - private SocketMemberRoleAuditLogData(IReadOnlyCollection roles, Cacheable target) + private SocketMemberRoleAuditLogData(IReadOnlyCollection roles, Cacheable target, string integrationType) { Roles = roles; Target = target; + IntegrationType = integrationType; } internal static SocketMemberRoleAuditLogData Create(DiscordSocketClient discord, EntryModel entry) @@ -36,7 +37,7 @@ public class SocketMemberRoleAuditLogData : ISocketAuditLogData return user is not null ? RestUser.Create(discord, user) : null; }); - return new SocketMemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), cacheableUser); + return new SocketMemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), cacheableUser, entry.Options?.IntegrationType); } /// @@ -55,4 +56,9 @@ public class SocketMemberRoleAuditLogData : ISocketAuditLogData /// A cacheable user object representing the user that the role changes were performed on. /// public Cacheable Target { get; } + + /// + /// Gets the type of integration which performed the action. if the action was performed by a user. + /// + public string IntegrationType { get; } }