Rename MessageFilter.Filter(...) to MessageFilter.IsMatch(...)

pull/710/head
Tyrrrz 3 years ago
parent 6b8170ab89
commit 301bca0633

@ -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

@ -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}'.")
};
}

@ -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)
)
);
}

@ -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);

@ -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(),

@ -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)

@ -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

@ -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);
}
}

@ -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;
}
}
Loading…
Cancel
Save