Allow the contains filter to also search on embed content

Closes #670
pull/710/head
Tyrrrz 3 years ago
parent e849c9516c
commit 6b8170ab89

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System.Linq;
using System.Text.RegularExpressions;
using DiscordChatExporter.Core.Discord.Data;
namespace DiscordChatExporter.Core.Exporting.Filtering
@ -9,10 +10,25 @@ namespace DiscordChatExporter.Core.Exporting.Filtering
public ContainsMessageFilter(string text) => _text = text;
public override bool Filter(Message message) => Regex.IsMatch(
message.Content,
"\\b" + _text + "\\b",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant
);
private bool Filter(string? content) =>
!string.IsNullOrWhiteSpace(content) &&
Regex.IsMatch(
content,
"\\b" + Regex.Escape(_text) + "\\b",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant
);
public override bool Filter(Message message) =>
Filter(message.Content) ||
message.Embeds.Any(e =>
Filter(e.Title) ||
Filter(e.Author?.Name) ||
Filter(e.Description) ||
Filter(e.Footer?.Text) ||
e.Fields.Any(f =>
Filter(f.Name) ||
Filter(f.Value)
)
);
}
}
Loading…
Cancel
Save