Skip to content

Commit

Permalink
[Feature] Audit Log Created gateway event support (#2627)
Browse files Browse the repository at this point in the history
* add event to socket client

* make `AuditLog` param optional

* Some WIP audit log changes

* api models

* moar models

* complete models

* modelsss

* forgot to push

* oh lol forgot this too

* api & rest guild method

* revert VS being VS & formatting to file scoped namespace

* socket entities

* some work eh

* moar stuff

- switched to d.net's attribute for audit log deserialization

* working socket guild updated event + reworked rest GuildInfo creation

* a bit of refactoring + new models

* +channel created

* channel updated & channel deleted

* refactor rest channel updated log + some nullable fixes

* rest channel created + deleted logs

* user banned socket log

* kick + unban

* moar log modelsssss

* fixes & 4 more log types

* overwrite logs

* role logs

* invite logs

* webhook logs

* switch to `ISocketAuditLogData` for socket log data

* emote logs

* move stuff around

* move more stuff around

* audit logs cache

* scheduled event logs

* thread logs

* command permission update audit log

* fetch scheduled event data from log

* integration audit logs

* sticker audit log data

* stage instance audit logs

* auto mod rule audit logs

* fix

* forgot couple props

* command perm updated data from options

* final automod ones

* debugging goes away :(

* merge cringe

* ...

* yup

* fix xml doc

* onboarding audit logs

* changes

---------

Co-authored-by: cat <lumitydev@gmail.com>
  • Loading branch information
Misha-133 and CottageDwellingCat committed Apr 14, 2023
1 parent 3a8f76c commit dff6a57
Show file tree
Hide file tree
Showing 181 changed files with 8,890 additions and 2,703 deletions.
46 changes: 45 additions & 1 deletion src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,50 @@ public enum ActionType
/// <summary>
/// A thread was deleted.
/// </summary>
ThreadDelete = 112
ThreadDelete = 112,
/// <summary>
/// Permissions were updated for a command.
/// </summary>
ApplicationCommandPermissionUpdate = 121,

/// <summary>
/// Auto Moderation rule was created.
/// </summary>
AutoModerationRuleCreate = 140,
/// <summary>
/// Auto Moderation rule was updated.
/// </summary>
AutoModerationRuleUpdate = 141,
/// <summary>
/// Auto Moderation rule was deleted.
/// </summary>
AutoModerationRuleDelete = 142,
/// <summary>
/// Message was blocked by Auto Moderation.
/// </summary>
AutoModerationBlockMessage = 143,
/// <summary>
/// Message was flagged by Auto Moderation.
/// </summary>
AutoModerationFlagToChannel = 144,
/// <summary>
/// Member was timed out by Auto Moderation.
/// </summary>
AutoModerationUserCommunicationDisabled = 145,

/// <summary>
/// Guild Onboarding Question was created.
/// </summary>
OnboardingQuestionCreated = 163,

/// <summary>
/// Guild Onboarding Question was updated.
/// </summary>
OnboardingQuestionUpdated = 164,

/// <summary>
/// Guild Onboarding was updated.
/// </summary>
OnboardingUpdated = 167
}
}
6 changes: 6 additions & 0 deletions src/Discord.Net.Core/Entities/AuditLogs/IAuditLogInfoModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Discord;

public interface IAuditLogInfoModel
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ public enum ThreadArchiveDuration

/// <summary>
/// Three days (4320 minutes).
/// <remarks>
/// This option is explicitly available to nitro users.
/// </remarks>
/// </summary>
ThreeDays = 4320,

/// <summary>
/// One week (10080 minutes).
/// <remarks>
/// This option is explicitly available to nitro users.
/// </remarks>
/// </summary>
OneWeek = 10080
}
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Discord
{
// when adding properties to guilds please check if they are returned in audit log events and add them to the
// 'GuildInfo.cs' file for socket and rest audit logs.
/// <summary>
/// Represents a generic guild/server.
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/AutoModRuleInfoAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

internal class AutoModRuleInfoAuditLogModel : IAuditLogInfoModel
{
[JsonField("name")]
public string Name { get; set; }

[JsonField("event_type")]
public AutoModEventType EventType { get; set; }

[JsonField("trigger_type")]
public AutoModTriggerType TriggerType { get; set; }

[JsonField("trigger_metadata")]
public TriggerMetadata TriggerMetadata { get; set; }

[JsonField("actions")]
public AutoModAction[] Actions { get; set; }

[JsonField("enabled")]
public bool Enabled { get; set; }

[JsonField("exempt_roles")]
public ulong[] ExemptRoles { get; set; }

[JsonField("exempt_channels")]
public ulong[] ExemptChannels { get; set; }
}
57 changes: 57 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/ChannelInfoAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

internal class ChannelInfoAuditLogModel : IAuditLogInfoModel
{
[JsonField("name")]
public string Name { get; set; }

[JsonField("type")]
public ChannelType? Type { get; set; }

[JsonField("permission_overwrites")]
public Overwrite[] Overwrites { get; set; }

[JsonField("flags")]
public ChannelFlags? Flags { get; set; }

[JsonField("default_thread_rate_limit_per_user")]
public int? DefaultThreadRateLimitPerUser { get; set; }

[JsonField("default_auto_archive_duration")]
public ThreadArchiveDuration? DefaultArchiveDuration { get; set; }

[JsonField("rate_limit_per_user")]
public int? RateLimitPerUser { get; set; }

[JsonField("auto_archive_duration")]
public ThreadArchiveDuration? AutoArchiveDuration { get; set; }

[JsonField("nsfw")]
public bool? IsNsfw { get; set; }

[JsonField("topic")]
public string Topic { get; set; }

// Forum channels
[JsonField("available_tags")]
public ForumTag[] AvailableTags { get; set; }

[JsonField("default_reaction_emoji")]
public ForumReactionEmoji DefaultEmoji { get; set; }

// Voice channels

[JsonField("user_limit")]
public int? UserLimit { get; set; }

[JsonField("rtc_region")]
public string Region { get; set; }

[JsonField("video_quality_mode")]
public VideoQualityMode? VideoQualityMode { get; set; }

[JsonField("bitrate")]
public int? Bitrate { get; set; }
}
82 changes: 82 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/GuildInfoAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

public class GuildInfoAuditLogModel : IAuditLogInfoModel
{
[JsonField("name")]
public string Name { get; set; }

[JsonField("afk_timeout")]
public int? AfkTimeout { get; set; }

[JsonField("widget_enabled")]
public bool? IsEmbeddable { get; set; }

[JsonField("default_message_notifications")]
public DefaultMessageNotifications? DefaultMessageNotifications { get; set; }

[JsonField("mfa_level")]
public MfaLevel? MfaLevel { get; set; }

[JsonField("verification_level")]
public VerificationLevel? VerificationLevel { get; set; }

[JsonField("explicit_content_filter")]
public ExplicitContentFilterLevel? ExplicitContentFilterLevel { get; set; }

[JsonField("icon_hash")]
public string IconHash { get; set; }

[JsonField("discovery_splash")]
public string DiscoverySplash { get; set; }

[JsonField("splash")]
public string Splash { get; set; }

[JsonField("afk_channel_id")]
public ulong? AfkChannelId { get; set; }

[JsonField("widget_channel_id")]
public ulong? EmbeddedChannelId { get; set; }

[JsonField("system_channel_id")]
public ulong? SystemChannelId { get; set; }

[JsonField("rules_channel_id")]
public ulong? RulesChannelId { get; set; }

[JsonField("public_updates_channel_id")]
public ulong? PublicUpdatesChannelId { get; set; }

[JsonField("owner_id")]
public ulong? OwnerId { get; set; }

[JsonField("application_id")]
public ulong? ApplicationId { get; set; }

[JsonField("region")]
public string RegionId { get; set; }

[JsonField("banner")]
public string Banner { get; set; }

[JsonField("vanity_url_code")]
public string VanityUrl { get; set; }

[JsonField("system_channel_flags")]
public SystemChannelMessageDeny? SystemChannelFlags { get; set; }

[JsonField("description")]
public string Description { get; set; }

[JsonField("preferred_locale")]
public string PreferredLocale { get; set; }

[JsonField("nsfw_level")]
public NsfwLevel? NsfwLevel { get; set; }

[JsonField("premium_progress_bar_enabled")]
public bool? ProgressBarEnabled { get; set; }

}
33 changes: 33 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/IntegrationInfoAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

internal class IntegrationInfoAuditLogModel : IAuditLogInfoModel
{
[JsonField("name")]
public string Name { get; set; }

[JsonField("type")]
public string Type { get; set; }

[JsonField("enabled")]
public bool? Enabled { get; set; }

[JsonField("syncing")]
public bool? Syncing { get; set; }

[JsonField("role_id")]
public ulong? RoleId { get; set; }

[JsonField("enable_emoticons")]
public bool? EnableEmojis { get; set; }

[JsonField("expire_behavior")]
public IntegrationExpireBehavior? ExpireBehavior { get; set; }

[JsonField("expire_grace_period")]
public int? ExpireGracePeriod { get; set; }

[JsonField("scopes")]
public string[] Scopes { get; set; }
}
27 changes: 27 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/InviteInfoAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

internal class InviteInfoAuditLogModel : IAuditLogInfoModel
{
[JsonField("code")]
public string Code { get; set; }

[JsonField("channel_id")]
public ulong? ChannelId { get; set; }

[JsonField("inviter_id")]
public ulong? InviterId { get; set; }

[JsonField("uses")]
public int? Uses { get; set; }

[JsonField("max_uses")]
public int? MaxUses { get; set; }

[JsonField("max_age")]
public int? MaxAge { get; set; }

[JsonField("temporary")]
public bool? Temporary { get; set; }
}
19 changes: 19 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/MemberInfoAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Discord.Rest;
using System;

namespace Discord.API.AuditLogs;

internal class MemberInfoAuditLogModel : IAuditLogInfoModel
{
[JsonField("nick")]
public string Nickname { get; set; }

[JsonField("mute")]
public bool? IsMuted { get; set; }

[JsonField("deaf")]
public bool? IsDeafened { get; set; }

[JsonField("communication_disabled_until")]
public DateTimeOffset? TimeOutUntil { get; set; }
}
15 changes: 15 additions & 0 deletions src/Discord.Net.Rest/API/AuditLogs/OnboardingAuditLogModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

internal class OnboardingAuditLogModel : IAuditLogInfoModel
{
[JsonField("default_channel_ids")]
public ulong[] DefaultChannelIds { get; set; }

[JsonField("prompts")]
public GuildOnboardingPrompt[] Prompts { get; set; }

[JsonField("enabled")]
public bool? Enabled { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Discord.Rest;

namespace Discord.API.AuditLogs;

internal class OnboardingPromptAuditLogModel : IAuditLogInfoModel
{
[JsonField("id")]
public ulong? Id { get; set; }

[JsonField("title")]
public string Title { get; set; }

[JsonField("options")]
public GuildOnboardingPromptOption[] Options { get; set; }

[JsonField("single_select")]
public bool? IsSingleSelect { get; set; }

[JsonField("required")]
public bool? IsRequired { get; set; }

[JsonField("in_onboarding")]
public bool? IsInOnboarding { get; set; }

[JsonField("type")]
public GuildOnboardingPromptType? Type { get; set; }
}

0 comments on commit dff6a57

Please sign in to comment.