From 45ab636d7eca19e8779a838db53bfcec90e59d22 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 25 Dec 2020 20:24:43 -0500 Subject: [PATCH] refactor: update for testing --- .../CursedWorkaround.cs | 4 +++ NoSoliciting.CursedWorkaround/Models.cs | 9 +++++-- .../DefinitionsTests/Chat.RMT.cs | 1 + NoSoliciting/ILRepack.targets | 20 -------------- NoSoliciting/Message.cs | 18 +++++++++++++ NoSoliciting/Ml/MlFilter.cs | 4 +++ NoSoliciting/NoSoliciting.csproj | 1 - NoSoliciting/Plugin.cs | 6 +++++ NoSoliciting/PluginUi.cs | 27 ++++++++----------- 9 files changed, 51 insertions(+), 39 deletions(-) delete mode 100644 NoSoliciting/ILRepack.targets diff --git a/NoSoliciting.CursedWorkaround/CursedWorkaround.cs b/NoSoliciting.CursedWorkaround/CursedWorkaround.cs index cc5914c..87e2d60 100644 --- a/NoSoliciting.CursedWorkaround/CursedWorkaround.cs +++ b/NoSoliciting.CursedWorkaround/CursedWorkaround.cs @@ -11,6 +11,10 @@ namespace NoSoliciting.CursedWorkaround { private DataViewSchema Schema { get; set; } = null!; private PredictionEngine PredictionEngine { get; set; } = null!; + public override object? InitializeLifetimeService() { + return null; + } + public void Initialise(byte[] data) { this.Context = new MLContext(); using var stream = new MemoryStream(data); diff --git a/NoSoliciting.CursedWorkaround/Models.cs b/NoSoliciting.CursedWorkaround/Models.cs index 310e772..d7029a5 100644 --- a/NoSoliciting.CursedWorkaround/Models.cs +++ b/NoSoliciting.CursedWorkaround/Models.cs @@ -8,6 +8,7 @@ namespace NoSoliciting.CursedWorkaround { private static readonly Regex WardRegex = new Regex(@"w.{0,2}\d", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex PlotRegex = new Regex(@"p.{0,2}\d", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly string[] PlotWords = { "plot", "apartment", @@ -17,12 +18,14 @@ namespace NoSoliciting.CursedWorkaround { private static readonly Regex NumbersRegex = new Regex(@"\d{1,2}.{0,2}\d{1,2}", RegexOptions.Compiled); private static readonly string[] TradeWords = { - "B>", - "S>", + "B> ", + "S> ", "buy", "sell", }; + private static readonly Regex SketchUrlRegex = new Regex(@"\.com-\w+\.\w+", RegexOptions.IgnoreCase | RegexOptions.Compiled); + public string? Category { get; } public uint Channel { get; } @@ -41,6 +44,8 @@ namespace NoSoliciting.CursedWorkaround { public bool ContainsTradeWords => TradeWords.Any(word => this.Message.ContainsIgnoreCase(word)); + public bool ContainsSketchUrl => SketchUrlRegex.IsMatch(this.Message); + public MessageData(uint channel, string message) { this.Channel = channel; this.Message = message; diff --git a/NoSoliciting.Tests/DefinitionsTests/Chat.RMT.cs b/NoSoliciting.Tests/DefinitionsTests/Chat.RMT.cs index 5c45c8f..30d279a 100644 --- a/NoSoliciting.Tests/DefinitionsTests/Chat.RMT.cs +++ b/NoSoliciting.Tests/DefinitionsTests/Chat.RMT.cs @@ -18,6 +18,7 @@ namespace NoSoliciting.Tests.DefinitionsTests.Chat { new TestMessage(ChatType.Shout, "【 PVP●K.℃ O M 、● = BAN 】,5分納品!ジル&480-500HQセット&希望の園エデン (野蛮)全部強奪!安い&安全保障【コード:714、5%OFF】!!!-pdonb"), new TestMessage(ChatType.Say, "Buy Cheap gils on www,G/a/m/e/r/E/a/s/y.c0m, 8% code,FFXIV2020, 15 mins deliveryvnm15"), new TestMessage(ChatType.TellIncoming, "You're Invited To Our Clan's Final Giveaway Of 850M Gil Starting In 45Mins! Visit Our Discord For The Location Of The Giveaway: https://discord.gg/VtqY9tFyUb"), + new TestMessage(ChatType.TellIncoming, "Quitting FFXIV, You're Invited To The Final Giveaway Of 850M Gil! Please Read The Rules And Location Of The Giveaway On The FFXIV Forum Post: https://www.squarenix.com-iy.ru/ffxiv/threads/6842918"), }); //public static object[][] DataNegatives => DefUtils.DataFromMessages(new TestMessage[] { diff --git a/NoSoliciting/ILRepack.targets b/NoSoliciting/ILRepack.targets deleted file mode 100644 index c4c5013..0000000 --- a/NoSoliciting/ILRepack.targets +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - diff --git a/NoSoliciting/Message.cs b/NoSoliciting/Message.cs index b468996..37510e3 100644 --- a/NoSoliciting/Message.cs +++ b/NoSoliciting/Message.cs @@ -6,6 +6,8 @@ using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; using System.Linq; +using Dalamud.Data; +using Lumina.Excel.GeneratedSheets; namespace NoSoliciting { public class Message { @@ -162,6 +164,22 @@ namespace NoSoliciting { _ => (byte) type, }; + public static string Name(this ChatType type, DataManager data) { + switch (type) { + case ChatType.None: + return "Party Finder"; + case ChatType.TellIncoming: + return "Tell (Incoming)"; + case ChatType.TellOutgoing: + return "Tell (Outgoing)"; + case ChatType.CrossParty: + return "Party (Cross-world)"; + } + + var lf = data.GetExcelSheet().FirstOrDefault(lf => lf.LogKind == type.LogKind()); + return lf?.Name?.ToString() ?? type.ToString(); + } + public static ChatType FromCode(ushort code) { return (ChatType) (code & Clear7); } diff --git a/NoSoliciting/Ml/MlFilter.cs b/NoSoliciting/Ml/MlFilter.cs index 5ec90a6..5259dd5 100644 --- a/NoSoliciting/Ml/MlFilter.cs +++ b/NoSoliciting/Ml/MlFilter.cs @@ -15,7 +15,11 @@ namespace NoSoliciting.Ml { private const string ManifestName = "manifest.yaml"; private const string ModelName = "model.zip"; + #if DEBUG + private const string Url = "https://annaclemens.io/assets/nosol/ml/manifest.yaml"; + #else private const string Url = "http://localhost:8000/manifest.yaml"; + #endif public uint Version { get; } private IClassifier Classifier { get; } diff --git a/NoSoliciting/NoSoliciting.csproj b/NoSoliciting/NoSoliciting.csproj index cf8b03e..976136e 100644 --- a/NoSoliciting/NoSoliciting.csproj +++ b/NoSoliciting/NoSoliciting.csproj @@ -37,7 +37,6 @@ - diff --git a/NoSoliciting/Plugin.cs b/NoSoliciting/Plugin.cs index 39baeeb..2bc4c28 100644 --- a/NoSoliciting/Plugin.cs +++ b/NoSoliciting/Plugin.cs @@ -47,6 +47,7 @@ namespace NoSoliciting { ConfigurationFile = $"{LibraryName}.dll.config", ApplicationBase = Path.GetDirectoryName(this.AssemblyLocation), }); + this.InnerDomain.InitializeLifetimeService(); this.Classifier = (IClassifier) this.InnerDomain.CreateInstanceAndUnwrap(LibraryName, $"{LibraryName}.CursedWorkaround"); string path = Environment.GetEnvironmentVariable("PATH")!; @@ -110,6 +111,11 @@ namespace NoSoliciting { } private void OnCommand(string command, string args) { + if (args == "report") { + this.Ui.OpenReporting(); + return; + } + this.Ui.OpenSettings(null, null); } diff --git a/NoSoliciting/PluginUi.cs b/NoSoliciting/PluginUi.cs index d7ab088..194cefa 100644 --- a/NoSoliciting/PluginUi.cs +++ b/NoSoliciting/PluginUi.cs @@ -17,7 +17,6 @@ using NoSoliciting.Ml; namespace NoSoliciting { public class PluginUi { private Plugin Plugin { get; } - private bool _resizeWindow; private ReportStatus LastReportStatus { get; set; } = ReportStatus.None; private bool _showSettings; @@ -42,6 +41,10 @@ namespace NoSoliciting { this.ShowSettings = true; } + public void OpenReporting() { + this.ShowReporting = true; + } + public void Draw() { if (this.ShowSettings) { this.DrawSettings(); @@ -53,13 +56,6 @@ namespace NoSoliciting { } private void DrawSettings() { - if (this._resizeWindow) { - this._resizeWindow = false; - ImGui.SetNextWindowSize(new Vector2(this.Plugin.Config.AdvancedMode ? 650 : 0, 0)); - } else { - ImGui.SetNextWindowSize(new Vector2(0, 0), ImGuiCond.FirstUseEver); - } - if (!ImGui.Begin($"{this.Plugin.Name} settings", ref this._showSettings)) { return; } @@ -260,6 +256,11 @@ namespace NoSoliciting { return; } + ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(255f, 204f, 0f, 1f)); + ImGui.TextUnformatted("Do not change advanced settings unless you know what you are doing."); + ImGui.TextUnformatted("The machine learning model was trained with certain channels in mind."); + ImGui.PopStyleColor(); + foreach (var category in (MessageCategory[]) Enum.GetValues(typeof(MessageCategory))) { if (category == MessageCategory.Normal) { continue; @@ -276,13 +277,7 @@ namespace NoSoliciting { var types = this.Plugin.Config.MlFilters[category]; void DrawTypes(ChatType type) { - string name; - if (type == ChatType.None) { - name = "Party Finder"; - } else { - var lf = this.Plugin.Interface.Data.GetExcelSheet().FirstOrDefault(lf => lf.LogKind == type.LogKind()); - name = lf?.Name?.ToString() ?? type.ToString(); - } + var name = type.Name(this.Plugin.Interface.Data); var check = types.Contains(type); if (!ImGui.Checkbox(name, ref check)) { @@ -451,7 +446,7 @@ namespace NoSoliciting { .Select(payload => payload.Text) .FirstOrDefault() ?? ""; - if (AddColumn(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.ChatType.ToString(), message.FilterReason ?? "", sender, message.Content.TextValue)) { + if (AddColumn(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.ChatType.Name(this.Plugin.Interface.Data), message.FilterReason ?? "", sender, message.Content.TextValue)) { ImGui.OpenPopup($"###modal-message-{message.Id}"); }