[Feature] Audit log integration type (#2814)

* why do I do this instead of preparing for an exam

* oh yeah nullable ofc

* oh yeah
This commit is contained in:
Mihail Gribkov
2023-12-26 01:34:25 +03:00
committed by GitHub
parent 079a98fbdd
commit d382e5cd48
5 changed files with 35 additions and 8 deletions

View File

@@ -39,4 +39,7 @@ internal class AuditLogOptions
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("integration_type")]
public string IntegrationType { get; set; }
}

View File

@@ -9,15 +9,16 @@ namespace Discord.Rest;
/// </summary>
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);
}
/// <summary>
@@ -30,4 +31,9 @@ public class KickAuditLogData : IAuditLogData
/// A user object representing the kicked user.
/// </returns>
public IUser Target { get; }
/// <summary>
/// Gets the type of integration which performed the action. <see langword="null"/> if the action was performed by a user.
/// </summary>
public string IntegrationType { get; }
}

View File

@@ -10,10 +10,11 @@ namespace Discord.Rest;
/// </summary>
public class MemberRoleAuditLogData : IAuditLogData
{
private MemberRoleAuditLogData(IReadOnlyCollection<MemberRoleEditInfo> roles, IUser target)
private MemberRoleAuditLogData(IReadOnlyCollection<MemberRoleEditInfo> 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);
}
/// <summary>
@@ -47,4 +48,9 @@ public class MemberRoleAuditLogData : IAuditLogData
/// A user object representing the user that the role changes were performed on.
/// </returns>
public IUser Target { get; }
/// <summary>
/// Gets the type of integration which performed the action. <see langword="null"/> if the action was performed by a user.
/// </summary>
public string IntegrationType { get; }
}

View File

@@ -9,9 +9,10 @@ namespace Discord.WebSocket;
/// </summary>
public class SocketKickAuditLogData : ISocketAuditLogData
{
private SocketKickAuditLogData(Cacheable<SocketUser, RestUser, IUser, ulong> user)
private SocketKickAuditLogData(Cacheable<SocketUser, RestUser, IUser, ulong> 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);
}
/// <summary>
@@ -40,4 +41,9 @@ public class SocketKickAuditLogData : ISocketAuditLogData
/// A cacheable user object representing the kicked user.
/// </returns>
public Cacheable<SocketUser, RestUser, IUser, ulong> Target { get; }
/// <summary>
/// Gets the type of integration which performed the action. <see langword="null"/> if the action was performed by a user.
/// </summary>
public string IntegrationType { get; }
}

View File

@@ -10,10 +10,11 @@ namespace Discord.WebSocket;
/// </summary>
public class SocketMemberRoleAuditLogData : ISocketAuditLogData
{
private SocketMemberRoleAuditLogData(IReadOnlyCollection<SocketMemberRoleEditInfo> roles, Cacheable<SocketUser, RestUser, IUser, ulong> target)
private SocketMemberRoleAuditLogData(IReadOnlyCollection<SocketMemberRoleEditInfo> roles, Cacheable<SocketUser, RestUser, IUser, ulong> 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);
}
/// <summary>
@@ -55,4 +56,9 @@ public class SocketMemberRoleAuditLogData : ISocketAuditLogData
/// A cacheable user object representing the user that the role changes were performed on.
/// </returns>
public Cacheable<SocketUser, RestUser, IUser, ulong> Target { get; }
/// <summary>
/// Gets the type of integration which performed the action. <see langword="null"/> if the action was performed by a user.
/// </summary>
public string IntegrationType { get; }
}