[Feature] Audit Log Created gateway event support (#2627)
* 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>
This commit is contained in:
@@ -49,6 +49,8 @@ namespace Discord.WebSocket
|
||||
private ConcurrentDictionary<ulong, SocketAutoModRule> _automodRules;
|
||||
private ImmutableArray<GuildEmote> _emotes;
|
||||
|
||||
private readonly AuditLogCache _auditLogs;
|
||||
|
||||
private AudioClient _audioClient;
|
||||
private VoiceStateUpdateParams _voiceStateUpdateParams;
|
||||
#pragma warning restore IDISP002, IDISP006
|
||||
@@ -415,6 +417,7 @@ namespace Discord.WebSocket
|
||||
_audioLock = new SemaphoreSlim(1, 1);
|
||||
_emotes = ImmutableArray.Create<GuildEmote>();
|
||||
_automodRules = new ConcurrentDictionary<ulong, SocketAutoModRule>();
|
||||
_auditLogs = new AuditLogCache(client);
|
||||
}
|
||||
internal static SocketGuild Create(DiscordSocketClient discord, ClientState state, ExtendedModel model)
|
||||
{
|
||||
@@ -1403,9 +1406,36 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
|
||||
/// of the requested audit log entries.
|
||||
/// </returns>
|
||||
/// </returns>
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null, ulong? afterId = null)
|
||||
=> GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType, afterId: afterId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all cached audit log entries from this guild.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketAuditLogEntry> CachedAuditLogs => _auditLogs?.AuditLogs ?? ImmutableArray.Create<SocketAuditLogEntry>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets cached audit log entry with the provided id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns <see langword="null"/> if no entry with provided id was found in cache.
|
||||
/// </remarks>
|
||||
public SocketAuditLogEntry GetCachedAuditLog(ulong id)
|
||||
=> _auditLogs.Get(id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets audit log entries with the specified type from cache.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<SocketAuditLogEntry> GetCachedAuditLogs(int limit = DiscordConfig.MaxAuditLogEntriesPerBatch, ActionType? action = null,
|
||||
ulong? fromEntryId = null, Direction direction = Direction.Before)
|
||||
{
|
||||
return _auditLogs.GetMany(fromEntryId, direction, limit, action);
|
||||
}
|
||||
|
||||
internal void AddAuditLog(SocketAuditLogEntry entry)
|
||||
=> _auditLogs.Add(entry);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Webhooks
|
||||
|
||||
Reference in New Issue
Block a user