Skip to content

Commit

Permalink
lint: clean up bulk delete PR
Browse files Browse the repository at this point in the history
  • Loading branch information
foxbot committed May 17, 2019
1 parent dec353e commit 03e6401
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public partial class DiscordSocketClient : BaseSocketClient, IDiscordClient
internal WebSocketProvider WebSocketProvider { get; private set; }
internal bool AlwaysDownloadUsers { get; private set; }
internal int? HandlerTimeout { get; private set; }
internal bool UseMessagesBulkDeletedOnly { get; private set; }
internal bool? ExclusiveBulkDelete { get; private set; }

internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient;
/// <inheritdoc />
Expand Down Expand Up @@ -129,7 +129,7 @@ private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClie
WebSocketProvider = config.WebSocketProvider;
AlwaysDownloadUsers = config.AlwaysDownloadUsers;
HandlerTimeout = config.HandlerTimeout;
UseMessagesBulkDeletedOnly = config.UseMessagesBulkDeletedOnly;
ExclusiveBulkDelete = config.ExclusiveBulkDelete;
State = new ClientState(0, 0);
Rest = new DiscordSocketRestClient(config, ApiClient);
_heartbeatTimes = new ConcurrentQueue<long>();
Expand Down Expand Up @@ -1357,6 +1357,14 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
{
await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_DELETE_BULK)").ConfigureAwait(false);

if (!ExclusiveBulkDelete.HasValue)
{
await _gatewayLogger.WarningAsync("A bulk delete event has been received, but the event handling behavior has not been set. " +
"To supress this message, set the ExclusiveBulkDelete configuration property. " +
"This message will appear only once.");
ExclusiveBulkDelete = false;
}

var data = (payload as JToken).ToObject<MessageDeleteBulkEvent>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
Expand All @@ -1375,7 +1383,7 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
var cacheable = new Cacheable<IMessage, ulong>(msg, id, isCached, async () => await channel.GetMessageAsync(id).ConfigureAwait(false));
cacheableList = cacheableList.Add(cacheable);

if (!UseMessagesBulkDeletedOnly)
if (!ExclusiveBulkDelete ?? false) // this shouldn't happen, but we'll play it safe anyways
await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false);
}

Expand Down
11 changes: 9 additions & 2 deletions src/Discord.Net.WebSocket/DiscordSocketConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ public class DiscordSocketConfig : DiscordRestConfig
public int? HandlerTimeout { get; set; } = 3000;

/// <summary>
/// Gets or sets whether or not <see cref="Discord.WebSocket.BaseSocketClient.MessageDeleted"/> is fired for each message on bulk delete.
/// Gets or sets the behavior for <see cref="BaseSocketClient.MessageDeleted"/> on bulk deletes.
///
/// If true, the <see cref="BaseSocketClient.MessageDeleted"/> event will not be raised for bulk deletes, and
/// only the <see cref="BaseSocketClient.MessagesBulkDeleted"/> will be raised.
///
/// If false, both events will be raised.
///
/// If unset, both events will be raised, but a warning will be logged when hooking into the bulk delete event.
/// </summary>
public bool UseMessagesBulkDeletedOnly { get; set; } = false;
public bool? ExclusiveBulkDelete { get; set; } = null;

/// <summary>
/// Initializes a default configuration.
Expand Down

0 comments on commit 03e6401

Please sign in to comment.