feat: begin removing support for defs

Remove the global section, which filtered Free Company ads and RP
ads. Prevent reporting of messages that were filtered by
definitions. Make the ML mode default and mark definitions mode as
obsolete.
This commit is contained in:
Anna 2021-02-24 20:20:04 -05:00
parent 83e6b20333
commit 8c8b3f1b39
4 changed files with 34 additions and 45 deletions

View File

@ -27,7 +27,6 @@ namespace NoSoliciting {
public Dictionary<string, Definition> Chat { get; private set; }
public Dictionary<string, Definition> PartyFinder { get; private set; }
public Dictionary<string, Definition> Global { get; private set; }
public static async Task<Definitions> UpdateAndCache(Plugin plugin) {
#if DEBUG
@ -127,24 +126,6 @@ namespace NoSoliciting {
}
}
foreach (var entry in this.Global) {
var chat = entry.Value.Clone();
chat.Initialise($"chat.global.{entry.Key}");
this.Chat[$"global.{entry.Key}"] = chat;
var pf = entry.Value.Clone();
pf.Initialise($"party_finder.global.{entry.Key}");
this.PartyFinder[$"global.{entry.Key}"] = pf;
if (!plugin.Config.FilterStatus.TryGetValue(chat.Id, out _)) {
plugin.Config.FilterStatus[chat.Id] = chat.Default;
}
if (!plugin.Config.FilterStatus.TryGetValue(pf.Id, out _)) {
plugin.Config.FilterStatus[pf.Id] = pf.Default;
}
}
plugin.Config.Save();
}
}
@ -215,19 +196,6 @@ namespace NoSoliciting {
// matches only if likelihood is greater than or equal the threshold
return likelihood >= this.LikelihoodThreshold;
}
public Definition Clone() {
return new() {
RequiredMatchers = this.RequiredMatchers,
LikelyMatchers = this.LikelyMatchers,
LikelihoodThreshold = this.LikelihoodThreshold,
IgnoreCase = this.IgnoreCase,
Normalise = this.Normalise,
Channels = this.Channels,
Option = this.Option,
Default = this.Default,
};
}
}
public class Matcher {

View File

@ -26,14 +26,16 @@ namespace NoSoliciting.Ml {
#endif
public uint Version { get; }
public Uri ReportUrl { get; }
private Process Process { get; }
private IIpcClient<IClassifier> Classifier { get; }
private MlFilter(uint version, Process process, IIpcClient<IClassifier> classifier) {
private MlFilter(uint version, Uri reportUrl, Process process, IIpcClient<IClassifier> classifier) {
this.Process = process;
this.Classifier = classifier;
this.Version = version;
this.ReportUrl = reportUrl;
}
public MessageCategory ClassifyMessage(ushort channel, string message) {
@ -86,7 +88,12 @@ namespace NoSoliciting.Ml {
var process = StartClassifier(exePath, pidPath);
var client = await CreateClassifierClient(data);
return new MlFilter(manifest.Item1.Version, process!, client);
return new MlFilter(
manifest.Item1.Version,
manifest.Item1.ReportUrl,
process!,
client
);
}
private static async Task<IIpcClient<IClassifier>> CreateClassifierClient(byte[] data) {

View File

@ -52,7 +52,7 @@ namespace NoSoliciting {
public bool FilterHugeItemLevelPFs { get; set; }
public bool UseMachineLearning { get; set; }
public bool UseMachineLearning { get; set; } = true;
public HashSet<MessageCategory> BasicMlFilters { get; set; } = new() {
MessageCategory.RmtGil,

View File

@ -72,12 +72,12 @@ namespace NoSoliciting {
}
var modes = new[] {
"Definition matchers (default)",
"Machine learning (experimental)",
"Machine learning (default)",
"Definition matchers (obsolete)",
};
var modeIndex = this.Plugin.Config.UseMachineLearning ? 1 : 0;
var modeIndex = this.Plugin.Config.UseMachineLearning ? 0 : 1;
if (ImGui.Combo("Filter mode", ref modeIndex, modes, modes.Length)) {
this.Plugin.Config.UseMachineLearning = modeIndex == 1;
this.Plugin.Config.UseMachineLearning = modeIndex == 0;
this.Plugin.Config.Save();
if (this.Plugin.Config.UseMachineLearning) {
@ -568,15 +568,21 @@ namespace NoSoliciting {
ImGui.PushTextWrapPos();
ImGui.Text("Reporting this message will let the developer know that you think this message was incorrectly classified.");
if (!message.Ml) {
ImGui.TextUnformatted("You cannot report messages filtered by definitions. Please switch to machine learning mode.");
ImGui.Text(message.FilterReason != null
goto EndPopup;
}
ImGui.TextUnformatted("Reporting this message will let the developer know that you think this message was incorrectly classified.");
ImGui.TextUnformatted(message.FilterReason != null
? "Specifically, this message WAS filtered but shouldn't have been."
: "Specifically, this message WAS NOT filtered but should have been.");
ImGui.Separator();
ImGui.Text(message.Content.TextValue);
ImGui.TextUnformatted(message.Content.TextValue);
ImGui.Separator();
@ -587,7 +593,9 @@ namespace NoSoliciting {
ImGui.Separator();
if (message.FilterReason == "custom") {
ImGui.TextColored(new Vector4(1f, 0f, 0f, 1f), "You cannot report messages filtered because of a custom filter.");
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
ImGui.TextUnformatted("You cannot report messages filtered because of a custom filter.");
ImGui.PopStyleColor();
} else {
if (ImGui.Button("Report")) {
Task.Run(async () => {
@ -595,13 +603,18 @@ namespace NoSoliciting {
try {
using var client = new WebClient();
this.LastReportStatus = ReportStatus.InProgress;
resp = await client.UploadStringTaskAsync(this.Plugin.Definitions!.ReportUrl, message.ToJson()).ConfigureAwait(true);
var reportUrl = this.Plugin.MlFilter?.ReportUrl;
if (reportUrl != null) {
resp = await client.UploadStringTaskAsync(reportUrl, message.ToJson()).ConfigureAwait(true);
}
} catch (Exception) {
// ignored
}
this.LastReportStatus = resp == "{\"message\":\"ok\"}" ? ReportStatus.Successful : ReportStatus.Failure;
PluginLog.Log($"Report sent. Response: {resp}");
PluginLog.Log(resp == null
? "Report not sent. ML model not set."
: $"Report sent. Response: {resp}");
});
ImGui.CloseCurrentPopup();
}
@ -615,6 +628,7 @@ namespace NoSoliciting {
ImGui.SameLine();
EndPopup:
if (ImGui.Button("Cancel")) {
ImGui.CloseCurrentPopup();
}