feat: add "advanced mode" with custom filters
This commit is contained in:
parent
5dca5fbd1f
commit
dc249b2cbb
|
@ -55,6 +55,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Numerics" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
@ -63,7 +64,6 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CharUtil.cs" />
|
|
||||||
<Compile Include="GlobalSuppressions.cs" />
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="PFPacket.cs" />
|
<Compile Include="PFPacket.cs" />
|
||||||
<Compile Include="Plugin.cs" />
|
<Compile Include="Plugin.cs" />
|
||||||
|
@ -73,6 +73,7 @@
|
||||||
<Compile Include="RMTDetection.Chat.cs" />
|
<Compile Include="RMTDetection.Chat.cs" />
|
||||||
<Compile Include="RMTDetection.cs" />
|
<Compile Include="RMTDetection.cs" />
|
||||||
<Compile Include="RMTDetection.PartyFinder.cs" />
|
<Compile Include="RMTDetection.PartyFinder.cs" />
|
||||||
|
<Compile Include="RMTUtil.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="NoSoliciting.json" />
|
<None Include="NoSoliciting.json" />
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace NoSoliciting {
|
namespace NoSoliciting {
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
@ -14,6 +15,16 @@ namespace NoSoliciting {
|
||||||
public bool FilterChat { get; set; } = true;
|
public bool FilterChat { get; set; } = true;
|
||||||
public bool FilterPartyFinder { get; set; } = true;
|
public bool FilterPartyFinder { get; set; } = true;
|
||||||
|
|
||||||
|
public bool AdvancedMode { get; set; } = false;
|
||||||
|
|
||||||
|
public bool CustomChatFilter { get; set; } = false;
|
||||||
|
public List<string> ChatSubstrings { get; } = new List<string>();
|
||||||
|
public List<string> ChatRegexes { get; } = new List<string>();
|
||||||
|
|
||||||
|
public bool CustomPFFilter { get; set; } = false;
|
||||||
|
public List<string> PFSubstrings { get; } = new List<string>();
|
||||||
|
public List<string> PFRegexes { get; } = new List<string>();
|
||||||
|
|
||||||
public void Initialise(DalamudPluginInterface pi) {
|
public void Initialise(DalamudPluginInterface pi) {
|
||||||
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
|
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace NoSoliciting {
|
namespace NoSoliciting {
|
||||||
public class PluginUI {
|
public class PluginUI {
|
||||||
|
@ -24,6 +27,27 @@ namespace NoSoliciting {
|
||||||
|
|
||||||
public void DrawSettings() {
|
public void DrawSettings() {
|
||||||
if (ImGui.Begin($"{this.plugin.Name} settings", ref this._showSettings)) {
|
if (ImGui.Begin($"{this.plugin.Name} settings", ref this._showSettings)) {
|
||||||
|
if (this.plugin.Config.AdvancedMode) {
|
||||||
|
this.DrawAdvancedSettings();
|
||||||
|
} else {
|
||||||
|
this.DrawBasicSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.Separator();
|
||||||
|
|
||||||
|
bool advanced = this.plugin.Config.AdvancedMode;
|
||||||
|
if (ImGui.Checkbox("Advanced mode", ref advanced)) {
|
||||||
|
this.plugin.Config.AdvancedMode = advanced;
|
||||||
|
this.plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.End();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBasicSettings() {
|
||||||
|
ImGui.SetWindowSize(new Vector2(225, 125));
|
||||||
|
|
||||||
bool filterChat = this.plugin.Config.FilterChat;
|
bool filterChat = this.plugin.Config.FilterChat;
|
||||||
if (ImGui.Checkbox("Filter RMT from chat", ref filterChat)) {
|
if (ImGui.Checkbox("Filter RMT from chat", ref filterChat)) {
|
||||||
this.plugin.Config.FilterChat = filterChat;
|
this.plugin.Config.FilterChat = filterChat;
|
||||||
|
@ -35,8 +59,119 @@ namespace NoSoliciting {
|
||||||
this.plugin.Config.FilterPartyFinder = filterPartyFinder;
|
this.plugin.Config.FilterPartyFinder = filterPartyFinder;
|
||||||
this.plugin.Config.Save();
|
this.plugin.Config.Save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.End();
|
private void DrawAdvancedSettings() {
|
||||||
|
ImGui.SetWindowSize(new Vector2(600, 400));
|
||||||
|
|
||||||
|
if (ImGui.BeginTabBar("##nosoliciting-tabs")) {
|
||||||
|
if (ImGui.BeginTabItem("Chat")) {
|
||||||
|
bool filterChat = this.plugin.Config.FilterChat;
|
||||||
|
if (ImGui.Checkbox("Enable built-in RMT filter", ref filterChat)) {
|
||||||
|
this.plugin.Config.FilterChat = filterChat;
|
||||||
|
this.plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool customChat = this.plugin.Config.CustomChatFilter;
|
||||||
|
if (ImGui.Checkbox("Enable custom chat filters", ref customChat)) {
|
||||||
|
this.plugin.Config.CustomChatFilter = customChat;
|
||||||
|
this.plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.plugin.Config.CustomChatFilter) {
|
||||||
|
List<string> substrings = this.plugin.Config.ChatSubstrings;
|
||||||
|
List<string> regexes = this.plugin.Config.ChatRegexes;
|
||||||
|
this.DrawCustom("chat", ref substrings, ref regexes);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndTabItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.BeginTabItem("Party Finder")) {
|
||||||
|
bool filterPartyFinder = this.plugin.Config.FilterPartyFinder;
|
||||||
|
if (ImGui.Checkbox("Enable built-in Party Finder RMT filter", ref filterPartyFinder)) {
|
||||||
|
this.plugin.Config.FilterPartyFinder = filterPartyFinder;
|
||||||
|
this.plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool customPF = this.plugin.Config.CustomPFFilter;
|
||||||
|
if (ImGui.Checkbox("Enable custom Party Finder filters", ref customPF)) {
|
||||||
|
this.plugin.Config.CustomPFFilter = customPF;
|
||||||
|
this.plugin.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.plugin.Config.CustomPFFilter) {
|
||||||
|
List<string> substrings = this.plugin.Config.PFSubstrings;
|
||||||
|
List<string> regexes = this.plugin.Config.PFRegexes;
|
||||||
|
this.DrawCustom("pf", ref substrings, ref regexes);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndTabItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndTabBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawCustom(string name, ref List<string> substrings, ref List<string> regexes) {
|
||||||
|
ImGui.Columns(2);
|
||||||
|
|
||||||
|
ImGui.Text("Substrings to filter");
|
||||||
|
if (ImGui.BeginChild($"##{name}-substrings", new Vector2(0, 175))) {
|
||||||
|
for (int i = 0; i < substrings.Count; i++) {
|
||||||
|
string input = substrings[i];
|
||||||
|
if (ImGui.InputText($"##{name}-substring-{i}", ref input, 100)) {
|
||||||
|
if (input.Length != 0) {
|
||||||
|
substrings[i] = input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (ImGui.Button($"Remove##{name}-substring-{i}-remove")) {
|
||||||
|
substrings.RemoveAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.Button($"Add##{name}-substring-add")) {
|
||||||
|
substrings.Add("");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.NextColumn();
|
||||||
|
|
||||||
|
ImGui.Text("Regular expressions to filter");
|
||||||
|
if (ImGui.BeginChild($"##{name}-regexes", new Vector2(0, 175))) {
|
||||||
|
for (int i = 0; i < regexes.Count; i++) {
|
||||||
|
string input = regexes[i];
|
||||||
|
if (ImGui.InputText($"##{name}-regex-{i}", ref input, 100)) {
|
||||||
|
bool valid = true;
|
||||||
|
try {
|
||||||
|
_ = new Regex(input);
|
||||||
|
} catch (ArgumentException) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
if (valid && input.Length != 0) {
|
||||||
|
regexes[i] = input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (ImGui.Button($"Remove##{name}-regex-{i}-remove")) {
|
||||||
|
regexes.RemoveAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.Button($"Add##{name}-regex-add")) {
|
||||||
|
regexes.Add("");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.Columns(1);
|
||||||
|
|
||||||
|
if (ImGui.Button($"Save filters##{name}-save")) {
|
||||||
|
this.plugin.Config.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace NoSoliciting {
|
namespace NoSoliciting {
|
||||||
|
@ -34,13 +35,30 @@ namespace NoSoliciting {
|
||||||
"使用する5%オ",
|
"使用する5%オ",
|
||||||
"offers Fantasia",
|
"offers Fantasia",
|
||||||
};
|
};
|
||||||
private static readonly Regex rmtRegex = new Regex(@"Off Code( *)", RegexOptions.Compiled);
|
private static readonly Regex[] rmtRegexes = {
|
||||||
|
new Regex(@"Off Code( *)", RegexOptions.Compiled),
|
||||||
|
};
|
||||||
|
|
||||||
public static bool IsRMT(string msg) {
|
public static bool IsRMT(string msg) {
|
||||||
msg = RMTUtil.Normalise(msg);
|
msg = RMTUtil.Normalise(msg);
|
||||||
|
|
||||||
return rmtSubstrings.Any(needle => msg.Contains(needle))
|
return rmtSubstrings.Any(needle => msg.Contains(needle))
|
||||||
|| rmtRegex.IsMatch(msg);
|
|| rmtRegexes.Any(needle => needle.IsMatch(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool MatchesCustomFilters(string msg, PluginConfiguration config) {
|
||||||
|
if (config == null) {
|
||||||
|
throw new ArgumentNullException(nameof(config), "PluginConfiguration cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.AdvancedMode || !config.CustomChatFilter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = RMTUtil.Normalise(msg);
|
||||||
|
|
||||||
|
return config.ChatSubstrings.Any(needle => msg.Contains(needle))
|
||||||
|
|| config.ChatRegexes.Any(needle => Regex.IsMatch(msg, needle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,21 @@ namespace NoSoliciting {
|
||||||
|
|
||||||
return containsSell && containsDiscordTag && containsContent;
|
return containsSell && containsDiscordTag && containsContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool MatchesCustomFilters(string msg, PluginConfiguration config) {
|
||||||
|
if (config == null) {
|
||||||
|
throw new ArgumentNullException(nameof(config), "PluginConfiguration cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.AdvancedMode || !config.CustomPFFilter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = RMTUtil.Normalise(msg);
|
||||||
|
|
||||||
|
return config.PFSubstrings.Any(needle => msg.Contains(needle))
|
||||||
|
|| config.PFRegexes.Any(needle => Regex.IsMatch(msg, needle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,10 @@ namespace NoSoliciting {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string desc = listing.Description();
|
||||||
|
|
||||||
// only look at listings that are RMT
|
// only look at listings that are RMT
|
||||||
if (!PartyFinder.IsRMT(listing.Description())) {
|
if (!PartyFinder.IsRMT(desc) && !PartyFinder.MatchesCustomFilters(desc, this.plugin.Config)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +78,12 @@ namespace NoSoliciting {
|
||||||
|
|
||||||
string text = message.TextValue;
|
string text = message.TextValue;
|
||||||
|
|
||||||
if (Chat.IsRMT(text)) {
|
if (!Chat.IsRMT(text) && !Chat.MatchesCustomFilters(text, this.plugin.Config)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PluginLog.Log($"Handled RMT message: {text}");
|
PluginLog.Log($"Handled RMT message: {text}");
|
||||||
isHandled = true;
|
isHandled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user