Skip to content

Commit

Permalink
[Feature] Audit log integration type (#2814)
Browse files Browse the repository at this point in the history
* why do I do this instead of preparing for an exam

* oh yeah nullable ofc

* oh yeah
  • Loading branch information
Misha-133 authored Dec 25, 2023
1 parent 079a98f commit d382e5c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/API/Common/AuditLogOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ internal class AuditLogOptions

[JsonProperty("status")]
public string Status { get; set; }

[JsonProperty("integration_type")]
public string IntegrationType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -30,4 +31,9 @@ internal static KickAuditLogData Create(BaseDiscordClient discord, EntryModel en
/// 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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,7 +29,7 @@ internal static MemberRoleAuditLogData Create(BaseDiscordClient discord, EntryMo
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>
Expand All @@ -47,4 +48,9 @@ internal static MemberRoleAuditLogData Create(BaseDiscordClient discord, EntryMo
/// 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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -26,7 +27,7 @@ internal static SocketKickAuditLogData Create(DiscordSocketClient discord, Entry
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>
Expand All @@ -40,4 +41,9 @@ internal static SocketKickAuditLogData Create(DiscordSocketClient discord, Entry
/// 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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,7 +37,7 @@ internal static SocketMemberRoleAuditLogData Create(DiscordSocketClient discord,
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>
Expand All @@ -55,4 +56,9 @@ internal static SocketMemberRoleAuditLogData Create(DiscordSocketClient discord,
/// 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; }
}

0 comments on commit d382e5c

Please sign in to comment.