Audit Logs implementation (#1055)
* Copy audit logs impl from old branch and clean up I suck at using git, so I'm gonna use brute force. * Remove unnecessary TODOs Category channels do not provide any new information, and the other I forgot to remove beforehand * Add invite update data, clean up after feedback * Remove TODOs, add WebhookType enum for future use WebhookType is a future-use type, as currently audit logs are the only thing which may return it.
This commit is contained in:
committed by
Christopher F
parent
97c893107b
commit
39dffe8585
@@ -4,10 +4,10 @@ namespace Discord
|
||||
{
|
||||
public class DiscordConfig
|
||||
{
|
||||
public const int APIVersion = 6;
|
||||
public const int APIVersion = 6;
|
||||
public static string Version { get; } =
|
||||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ??
|
||||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetName().Version.ToString(3) ??
|
||||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetName().Version.ToString(3) ??
|
||||
"Unknown";
|
||||
|
||||
public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})";
|
||||
@@ -20,10 +20,11 @@ namespace Discord
|
||||
public const int MaxMessagesPerBatch = 100;
|
||||
public const int MaxUsersPerBatch = 1000;
|
||||
public const int MaxGuildsPerBatch = 100;
|
||||
public const int MaxAuditLogEntriesPerBatch = 100;
|
||||
|
||||
/// <summary> Gets or sets how a request should act in the case of an error, by default. </summary>
|
||||
public RetryMode DefaultRetryMode { get; set; } = RetryMode.AlwaysRetry;
|
||||
|
||||
|
||||
/// <summary> Gets or sets the minimum log level severity that will be sent to the Log event. </summary>
|
||||
public LogSeverity LogLevel { get; set; } = LogSeverity.Info;
|
||||
|
||||
|
||||
50
src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs
Normal file
50
src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
/// The action type within a <see cref="IAuditLogEntry"/>
|
||||
/// </summary>
|
||||
public enum ActionType
|
||||
{
|
||||
GuildUpdated = 1,
|
||||
|
||||
ChannelCreated = 10,
|
||||
ChannelUpdated = 11,
|
||||
ChannelDeleted = 12,
|
||||
|
||||
OverwriteCreated = 13,
|
||||
OverwriteUpdated = 14,
|
||||
OverwriteDeleted = 15,
|
||||
|
||||
Kick = 20,
|
||||
Prune = 21,
|
||||
Ban = 22,
|
||||
Unban = 23,
|
||||
|
||||
MemberUpdated = 24,
|
||||
MemberRoleUpdated = 25,
|
||||
|
||||
RoleCreated = 30,
|
||||
RoleUpdated = 31,
|
||||
RoleDeleted = 32,
|
||||
|
||||
InviteCreated = 40,
|
||||
InviteUpdated = 41,
|
||||
InviteDeleted = 42,
|
||||
|
||||
WebhookCreated = 50,
|
||||
WebhookUpdated = 51,
|
||||
WebhookDeleted = 52,
|
||||
|
||||
EmojiCreated = 60,
|
||||
EmojiUpdated = 61,
|
||||
EmojiDeleted = 62,
|
||||
|
||||
MessageDeleted = 72
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Core/Entities/AuditLogs/IAuditLogData.cs
Normal file
14
src/Discord.Net.Core/Entities/AuditLogs/IAuditLogData.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents data applied to an <see cref="IAuditLogEntry"/>
|
||||
/// </summary>
|
||||
public interface IAuditLogData
|
||||
{ }
|
||||
}
|
||||
34
src/Discord.Net.Core/Entities/AuditLogs/IAuditLogEntry.cs
Normal file
34
src/Discord.Net.Core/Entities/AuditLogs/IAuditLogEntry.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an entry in an audit log
|
||||
/// </summary>
|
||||
public interface IAuditLogEntry : IEntity<ulong>
|
||||
{
|
||||
/// <summary>
|
||||
/// The action which occured to create this entry
|
||||
/// </summary>
|
||||
ActionType Action { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The data for this entry. May be <see cref="null"/> if no data was available.
|
||||
/// </summary>
|
||||
IAuditLogData Data { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user responsible for causing the changes
|
||||
/// </summary>
|
||||
IUser User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The reason behind the change. May be <see cref="null"/> if no reason was provided.
|
||||
/// </summary>
|
||||
string Reason { get; }
|
||||
}
|
||||
}
|
||||
@@ -139,6 +139,10 @@ namespace Discord
|
||||
/// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary>
|
||||
Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null);
|
||||
|
||||
/// <summary> Gets the specified number of audit log entries for this guild. </summary>
|
||||
Task<IReadOnlyCollection<IAuditLogEntry>> GetAuditLogAsync(int limit = DiscordConfig.MaxAuditLogEntriesPerBatch,
|
||||
CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
|
||||
|
||||
/// <summary> Gets the webhook in this guild with the provided id, or null if not found. </summary>
|
||||
Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null);
|
||||
/// <summary> Gets a collection of all webhooks for this guild. </summary>
|
||||
|
||||
14
src/Discord.Net.Core/Entities/Webhooks/WebhookType.cs
Normal file
14
src/Discord.Net.Core/Entities/Webhooks/WebhookType.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the type of a webhook.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This type is currently unused, and is only returned in audit log responses.
|
||||
/// </remarks>
|
||||
public enum WebhookType
|
||||
{
|
||||
/// <summary> An incoming webhook </summary>
|
||||
Incoming = 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user