Skip to content

Commit

Permalink
Allow the contains filter to also search on embed content
Browse files Browse the repository at this point in the history
Closes #670
  • Loading branch information
Tyrrrz committed Aug 31, 2021
1 parent e849c95 commit 6b8170a
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,10 +10,25 @@ internal class ContainsMessageFilter : MessageFilter

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

0 comments on commit 6b8170a

Please sign in to comment.