fix: no longer consider empty custom filters

This commit is contained in:
Anna 2021-04-25 15:19:42 -04:00
parent b0e49b8458
commit 815ba1c1ad
4 changed files with 11 additions and 11 deletions

View File

@ -16,7 +16,7 @@ namespace NoSoliciting {
msg = NoSolUtil.Normalise(msg);
return config.ChatSubstrings.Any(needle => msg.ContainsIgnoreCase(needle))
return config.ValidChatSubstrings.Any(needle => msg.ContainsIgnoreCase(needle))
|| config.CompiledChatRegexes.Any(needle => needle.IsMatch(msg));
}
}

View File

@ -16,7 +16,7 @@ namespace NoSoliciting {
msg = NoSolUtil.Normalise(msg);
return config.PFSubstrings.Any(needle => msg.ContainsIgnoreCase(needle))
return config.ValidPfSubstrings.Any(needle => msg.ContainsIgnoreCase(needle))
|| config.CompiledPFRegexes.Any(needle => needle.IsMatch(msg));
}
}

View File

@ -351,9 +351,7 @@ namespace NoSoliciting.Interface {
for (var i = 0; i < substrings.Count; i++) {
var input = substrings[i];
if (ImGui.InputText($"##{name}-substring-{i}", ref input, 1_000)) {
if (input.Length != 0) {
substrings[i] = input;
}
substrings[i] = input;
}
ImGui.SameLine();
@ -382,15 +380,12 @@ namespace NoSoliciting.Interface {
for (var i = 0; i < regexes.Count; i++) {
var input = regexes[i];
if (ImGui.InputText($"##{name}-regex-{i}", ref input, 1_000)) {
var valid = true;
try {
_ = new Regex(input);
} catch (ArgumentException) {
valid = false;
}
if (valid && input.Length != 0) {
// update if valid
regexes[i] = input;
} catch (ArgumentException) {
// ignore
}
}

View File

@ -99,6 +99,9 @@ namespace NoSoliciting {
public bool ConsiderPrivatePfs { get; set; }
public IEnumerable<string> ValidChatSubstrings => this.ChatSubstrings.Where(needle => !string.IsNullOrWhiteSpace(needle));
public IEnumerable<string> ValidPfSubstrings => this.PFSubstrings.Where(needle => !string.IsNullOrWhiteSpace(needle));
public void Initialise(DalamudPluginInterface pi) {
this.Interface = pi;
this.CompileRegexes();
@ -110,9 +113,11 @@ namespace NoSoliciting {
public void CompileRegexes() {
this.CompiledChatRegexes = this.ChatRegexes
.Where(reg => !string.IsNullOrWhiteSpace(reg))
.Select(reg => new Regex(reg, RegexOptions.Compiled))
.ToList();
this.CompiledPFRegexes = this.PFRegexes
.Where(reg => !string.IsNullOrWhiteSpace(reg))
.Select(reg => new Regex(reg, RegexOptions.Compiled))
.ToList();
}