From 301bca063301db25fca27737552f7a2d5ee59aa5 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 1 Sep 2021 18:18:20 +0300 Subject: [PATCH] Rename MessageFilter.Filter(...) to MessageFilter.IsMatch(...) --- .../Exporting/ChannelExporter.cs | 2 +- .../Filtering/BinaryExpressionMessageFilter.cs | 6 +++--- .../Filtering/ContainsMessageFilter.cs | 18 +++++++++--------- .../Exporting/Filtering/FromMessageFilter.cs | 2 +- .../Exporting/Filtering/HasMessageFilter.cs | 2 +- .../Filtering/MentionsMessageFilter.cs | 2 +- .../Exporting/Filtering/MessageFilter.cs | 2 +- .../Filtering/NegatedMessageFilter.cs | 2 +- .../Exporting/Filtering/NullMessageFilter.cs | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/DiscordChatExporter.Core/Exporting/ChannelExporter.cs b/DiscordChatExporter.Core/Exporting/ChannelExporter.cs index 7a8f262..1d04d39 100644 --- a/DiscordChatExporter.Core/Exporting/ChannelExporter.cs +++ b/DiscordChatExporter.Core/Exporting/ChannelExporter.cs @@ -40,7 +40,7 @@ namespace DiscordChatExporter.Core.Exporting await foreach (var message in _discord.GetMessagesAsync(request.Channel.Id, request.After, request.Before, progress)) { // Skips any messages that fail to pass the supplied filter - if (!request.MessageFilter.Filter(message)) + if (!request.MessageFilter.IsMatch(message)) continue; // Resolve members for referenced users diff --git a/DiscordChatExporter.Core/Exporting/Filtering/BinaryExpressionMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/BinaryExpressionMessageFilter.cs index 6a187cd..013bd0e 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/BinaryExpressionMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/BinaryExpressionMessageFilter.cs @@ -16,10 +16,10 @@ namespace DiscordChatExporter.Core.Exporting.Filtering _kind = kind; } - public override bool Filter(Message message) => _kind switch + public override bool IsMatch(Message message) => _kind switch { - BinaryExpressionKind.Or => _first.Filter(message) || _second.Filter(message), - BinaryExpressionKind.And => _first.Filter(message) && _second.Filter(message), + BinaryExpressionKind.Or => _first.IsMatch(message) || _second.IsMatch(message), + BinaryExpressionKind.And => _first.IsMatch(message) && _second.IsMatch(message), _ => throw new InvalidOperationException($"Unknown binary expression kind '{_kind}'.") }; } diff --git a/DiscordChatExporter.Core/Exporting/Filtering/ContainsMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/ContainsMessageFilter.cs index 007b9a0..2e0999d 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/ContainsMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/ContainsMessageFilter.cs @@ -10,7 +10,7 @@ namespace DiscordChatExporter.Core.Exporting.Filtering public ContainsMessageFilter(string text) => _text = text; - private bool Filter(string? content) => + private bool IsMatch(string? content) => !string.IsNullOrWhiteSpace(content) && Regex.IsMatch( content, @@ -18,16 +18,16 @@ namespace DiscordChatExporter.Core.Exporting.Filtering RegexOptions.IgnoreCase | RegexOptions.CultureInvariant ); - public override bool Filter(Message message) => - Filter(message.Content) || + public override bool IsMatch(Message message) => + IsMatch(message.Content) || message.Embeds.Any(e => - Filter(e.Title) || - Filter(e.Author?.Name) || - Filter(e.Description) || - Filter(e.Footer?.Text) || + IsMatch(e.Title) || + IsMatch(e.Author?.Name) || + IsMatch(e.Description) || + IsMatch(e.Footer?.Text) || e.Fields.Any(f => - Filter(f.Name) || - Filter(f.Value) + IsMatch(f.Name) || + IsMatch(f.Value) ) ); } diff --git a/DiscordChatExporter.Core/Exporting/Filtering/FromMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/FromMessageFilter.cs index f6da2c7..a328fc5 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/FromMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/FromMessageFilter.cs @@ -9,7 +9,7 @@ namespace DiscordChatExporter.Core.Exporting.Filtering public FromMessageFilter(string value) => _value = value; - public override bool Filter(Message message) => + public override bool IsMatch(Message message) => string.Equals(_value, message.Author.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(_value, message.Author.FullName, StringComparison.OrdinalIgnoreCase) || string.Equals(_value, message.Author.Id.ToString(), StringComparison.OrdinalIgnoreCase); diff --git a/DiscordChatExporter.Core/Exporting/Filtering/HasMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/HasMessageFilter.cs index 4ef94f5..2188522 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/HasMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/HasMessageFilter.cs @@ -11,7 +11,7 @@ namespace DiscordChatExporter.Core.Exporting.Filtering public HasMessageFilter(MessageContentMatchKind kind) => _kind = kind; - public override bool Filter(Message message) => _kind switch + public override bool IsMatch(Message message) => _kind switch { MessageContentMatchKind.Link => Regex.IsMatch(message.Content, "https?://\\S*[^\\.,:;\"\'\\s]"), MessageContentMatchKind.Embed => message.Embeds.Any(), diff --git a/DiscordChatExporter.Core/Exporting/Filtering/MentionsMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/MentionsMessageFilter.cs index f96bc88..2cfe77d 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/MentionsMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/MentionsMessageFilter.cs @@ -10,7 +10,7 @@ namespace DiscordChatExporter.Core.Exporting.Filtering public MentionsMessageFilter(string value) => _value = value; - public override bool Filter(Message message) => message.MentionedUsers.Any(user => + public override bool IsMatch(Message message) => message.MentionedUsers.Any(user => string.Equals(_value, user.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(_value, user.FullName, StringComparison.OrdinalIgnoreCase) || string.Equals(_value, user.Id.ToString(), StringComparison.OrdinalIgnoreCase) diff --git a/DiscordChatExporter.Core/Exporting/Filtering/MessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/MessageFilter.cs index a7bbb09..45fb75d 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/MessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/MessageFilter.cs @@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Exporting.Filtering { public abstract partial class MessageFilter { - public abstract bool Filter(Message message); + public abstract bool IsMatch(Message message); } public partial class MessageFilter diff --git a/DiscordChatExporter.Core/Exporting/Filtering/NegatedMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/NegatedMessageFilter.cs index 2c144d0..2d9b8ad 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/NegatedMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/NegatedMessageFilter.cs @@ -8,6 +8,6 @@ namespace DiscordChatExporter.Core.Exporting.Filtering public NegatedMessageFilter(MessageFilter filter) => _filter = filter; - public override bool Filter(Message message) => !_filter.Filter(message); + public override bool IsMatch(Message message) => !_filter.IsMatch(message); } } \ No newline at end of file diff --git a/DiscordChatExporter.Core/Exporting/Filtering/NullMessageFilter.cs b/DiscordChatExporter.Core/Exporting/Filtering/NullMessageFilter.cs index d68b6b6..be81ab6 100644 --- a/DiscordChatExporter.Core/Exporting/Filtering/NullMessageFilter.cs +++ b/DiscordChatExporter.Core/Exporting/Filtering/NullMessageFilter.cs @@ -4,6 +4,6 @@ namespace DiscordChatExporter.Core.Exporting.Filtering { internal class NullMessageFilter : MessageFilter { - public override bool Filter(Message message) => true; + public override bool IsMatch(Message message) => true; } } \ No newline at end of file