From 908f405b88f1ad9bbfcce23f2fb9ea71ac5989b4 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Mon, 22 Feb 2021 20:22:40 -0500 Subject: [PATCH] feat: add config for disabling providers --- ExpandedSearchInfo.sln | 0 ExpandedSearchInfo/Configs/BaseConfig.cs | 6 ++ ExpandedSearchInfo/Configs/CarrdConfig.cs | 4 + ExpandedSearchInfo/Configs/FListConfig.cs | 4 + ExpandedSearchInfo/Configs/PastebinConfig.cs | 4 + ExpandedSearchInfo/Configs/PlainTextConfig.cs | 4 + ExpandedSearchInfo/Configs/RefsheetConfig.cs | 4 + ExpandedSearchInfo/ExpandedSearchInfo.csproj | 8 +- ExpandedSearchInfo/ExpandedSearchInfo.yaml | 0 ExpandedSearchInfo/GameFunctions.cs | 2 +- ExpandedSearchInfo/Plugin.cs | 17 ++- ExpandedSearchInfo/PluginConfiguration.cs | 28 +++++ ExpandedSearchInfo/PluginUi.cs | 101 +++++++++++++++++- .../Providers/BaseHtmlProvider.cs | 9 ++ ExpandedSearchInfo/Providers/CarrdProvider.cs | 17 +++ ExpandedSearchInfo/Providers/FListProvider.cs | 22 +++- ExpandedSearchInfo/Providers/IProvider.cs | 9 ++ .../Providers/PastebinProvider.cs | 18 +++- .../Providers/PlainTextProvider.cs | 18 +++- .../Providers/RefsheetProvider.cs | 17 +++ ExpandedSearchInfo/SearchInfoRepository.cs | 13 +-- ExpandedSearchInfo/Sections/FListSection.cs | 5 +- .../Sections/ISearchInfoSection.cs | 2 + .../Sections/RefsheetSection.cs | 5 +- ExpandedSearchInfo/Sections/TextSection.cs | 9 +- ExpandedSearchInfo/Util.cs | 2 +- 26 files changed, 303 insertions(+), 25 deletions(-) mode change 100755 => 100644 ExpandedSearchInfo.sln create mode 100755 ExpandedSearchInfo/Configs/BaseConfig.cs create mode 100755 ExpandedSearchInfo/Configs/CarrdConfig.cs create mode 100755 ExpandedSearchInfo/Configs/FListConfig.cs create mode 100755 ExpandedSearchInfo/Configs/PastebinConfig.cs create mode 100755 ExpandedSearchInfo/Configs/PlainTextConfig.cs create mode 100755 ExpandedSearchInfo/Configs/RefsheetConfig.cs mode change 100755 => 100644 ExpandedSearchInfo/ExpandedSearchInfo.yaml mode change 100755 => 100644 ExpandedSearchInfo/GameFunctions.cs mode change 100755 => 100644 ExpandedSearchInfo/Plugin.cs create mode 100755 ExpandedSearchInfo/PluginConfiguration.cs mode change 100755 => 100644 ExpandedSearchInfo/PluginUi.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/BaseHtmlProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/CarrdProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/FListProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/IProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/PastebinProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/PlainTextProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/Providers/RefsheetProvider.cs mode change 100755 => 100644 ExpandedSearchInfo/SearchInfoRepository.cs mode change 100755 => 100644 ExpandedSearchInfo/Sections/FListSection.cs mode change 100755 => 100644 ExpandedSearchInfo/Sections/ISearchInfoSection.cs mode change 100755 => 100644 ExpandedSearchInfo/Sections/RefsheetSection.cs mode change 100755 => 100644 ExpandedSearchInfo/Sections/TextSection.cs mode change 100755 => 100644 ExpandedSearchInfo/Util.cs diff --git a/ExpandedSearchInfo.sln b/ExpandedSearchInfo.sln old mode 100755 new mode 100644 diff --git a/ExpandedSearchInfo/Configs/BaseConfig.cs b/ExpandedSearchInfo/Configs/BaseConfig.cs new file mode 100755 index 0000000..c9b64c5 --- /dev/null +++ b/ExpandedSearchInfo/Configs/BaseConfig.cs @@ -0,0 +1,6 @@ +namespace ExpandedSearchInfo.Configs { + public abstract class BaseConfig { + public bool Enabled { get; set; } = true; + public bool DefaultExpanded { get; set; } = true; + } +} diff --git a/ExpandedSearchInfo/Configs/CarrdConfig.cs b/ExpandedSearchInfo/Configs/CarrdConfig.cs new file mode 100755 index 0000000..78bf833 --- /dev/null +++ b/ExpandedSearchInfo/Configs/CarrdConfig.cs @@ -0,0 +1,4 @@ +namespace ExpandedSearchInfo.Configs { + public class CarrdConfig : BaseConfig { + } +} \ No newline at end of file diff --git a/ExpandedSearchInfo/Configs/FListConfig.cs b/ExpandedSearchInfo/Configs/FListConfig.cs new file mode 100755 index 0000000..485c053 --- /dev/null +++ b/ExpandedSearchInfo/Configs/FListConfig.cs @@ -0,0 +1,4 @@ +namespace ExpandedSearchInfo.Configs { + public class FListConfig : BaseConfig { + } +} \ No newline at end of file diff --git a/ExpandedSearchInfo/Configs/PastebinConfig.cs b/ExpandedSearchInfo/Configs/PastebinConfig.cs new file mode 100755 index 0000000..f49ccd5 --- /dev/null +++ b/ExpandedSearchInfo/Configs/PastebinConfig.cs @@ -0,0 +1,4 @@ +namespace ExpandedSearchInfo.Configs { + public class PastebinConfig : BaseConfig { + } +} \ No newline at end of file diff --git a/ExpandedSearchInfo/Configs/PlainTextConfig.cs b/ExpandedSearchInfo/Configs/PlainTextConfig.cs new file mode 100755 index 0000000..92df8fb --- /dev/null +++ b/ExpandedSearchInfo/Configs/PlainTextConfig.cs @@ -0,0 +1,4 @@ +namespace ExpandedSearchInfo.Configs { + public class PlainTextConfig : BaseConfig { + } +} \ No newline at end of file diff --git a/ExpandedSearchInfo/Configs/RefsheetConfig.cs b/ExpandedSearchInfo/Configs/RefsheetConfig.cs new file mode 100755 index 0000000..4a73136 --- /dev/null +++ b/ExpandedSearchInfo/Configs/RefsheetConfig.cs @@ -0,0 +1,4 @@ +namespace ExpandedSearchInfo.Configs { + public class RefsheetConfig : BaseConfig { + } +} \ No newline at end of file diff --git a/ExpandedSearchInfo/ExpandedSearchInfo.csproj b/ExpandedSearchInfo/ExpandedSearchInfo.csproj index 9cbb8e9..902f88b 100755 --- a/ExpandedSearchInfo/ExpandedSearchInfo.csproj +++ b/ExpandedSearchInfo/ExpandedSearchInfo.csproj @@ -27,10 +27,10 @@ - - - - + + + + diff --git a/ExpandedSearchInfo/ExpandedSearchInfo.yaml b/ExpandedSearchInfo/ExpandedSearchInfo.yaml old mode 100755 new mode 100644 diff --git a/ExpandedSearchInfo/GameFunctions.cs b/ExpandedSearchInfo/GameFunctions.cs old mode 100755 new mode 100644 index a581900..e2742da --- a/ExpandedSearchInfo/GameFunctions.cs +++ b/ExpandedSearchInfo/GameFunctions.cs @@ -44,4 +44,4 @@ namespace ExpandedSearchInfo { return result; } } -} +} \ No newline at end of file diff --git a/ExpandedSearchInfo/Plugin.cs b/ExpandedSearchInfo/Plugin.cs old mode 100755 new mode 100644 index 385b01f..c03910a --- a/ExpandedSearchInfo/Plugin.cs +++ b/ExpandedSearchInfo/Plugin.cs @@ -1,9 +1,12 @@ -using Dalamud.Plugin; +using Dalamud.Game.Command; +using Dalamud.Plugin; namespace ExpandedSearchInfo { + // ReSharper disable once ClassNeverInstantiated.Global public class Plugin : IDalamudPlugin { public string Name => "Expanded Search Info"; + internal PluginConfiguration Config { get; private set; } = null!; internal DalamudPluginInterface Interface { get; private set; } = null!; internal GameFunctions Functions { get; private set; } = null!; internal SearchInfoRepository Repository { get; private set; } = null!; @@ -12,15 +15,27 @@ namespace ExpandedSearchInfo { public void Initialize(DalamudPluginInterface pluginInterface) { this.Interface = pluginInterface; + this.Config = (PluginConfiguration?) this.Interface.GetPluginConfig() ?? new PluginConfiguration(); + this.Config.Initialise(this); + this.Functions = new GameFunctions(this); this.Repository = new SearchInfoRepository(this); this.Ui = new PluginUi(this); + + this.Interface.CommandManager.AddHandler("/esi", new CommandInfo(this.OnCommand) { + HelpMessage = "Toggles Expanded Search Info's configuration window", + }); } public void Dispose() { + this.Interface.CommandManager.RemoveHandler("/esi"); this.Ui.Dispose(); this.Repository.Dispose(); this.Functions.Dispose(); } + + private void OnCommand(string command, string arguments) { + this.Ui.ConfigVisible = !this.Ui.ConfigVisible; + } } } diff --git a/ExpandedSearchInfo/PluginConfiguration.cs b/ExpandedSearchInfo/PluginConfiguration.cs new file mode 100755 index 0000000..bbb89fe --- /dev/null +++ b/ExpandedSearchInfo/PluginConfiguration.cs @@ -0,0 +1,28 @@ +using Dalamud.Configuration; +using ExpandedSearchInfo.Configs; + +namespace ExpandedSearchInfo { + public class PluginConfiguration : IPluginConfiguration { + private Plugin Plugin { get; set; } = null!; + + public int Version { get; set; } = 1; + + public ProviderConfigs Configs { get; set; } = new(); + + internal void Initialise(Plugin plugin) { + this.Plugin = plugin; + } + + internal void Save() { + this.Plugin.Interface.SavePluginConfig(this); + } + } + + public class ProviderConfigs { + public CarrdConfig Carrd { get; set; } = new(); + public FListConfig FList { get; set; } = new(); + public PastebinConfig Pastebin { get; set; } = new(); + public PlainTextConfig PlainText { get; set; } = new(); + public RefsheetConfig Refsheet { get; set; } = new(); + } +} \ No newline at end of file diff --git a/ExpandedSearchInfo/PluginUi.cs b/ExpandedSearchInfo/PluginUi.cs old mode 100755 new mode 100644 index 972b57e..6d8367a --- a/ExpandedSearchInfo/PluginUi.cs +++ b/ExpandedSearchInfo/PluginUi.cs @@ -8,13 +8,26 @@ namespace ExpandedSearchInfo { public class PluginUi : IDisposable { private Plugin Plugin { get; } + private bool _configVisible; + + internal bool ConfigVisible { + get => this._configVisible; + set => this._configVisible = value; + } + internal PluginUi(Plugin plugin) { this.Plugin = plugin; this.Plugin.Interface.UiBuilder.OnBuildUi += this.Draw; + this.Plugin.Interface.UiBuilder.OnOpenConfigUi += this.OnOpenConfigUi; + } + + private void OnOpenConfigUi(object sender, EventArgs e) { + this.ConfigVisible = true; } public void Dispose() { + this.Plugin.Interface.UiBuilder.OnOpenConfigUi -= this.OnOpenConfigUi; this.Plugin.Interface.UiBuilder.OnBuildUi -= this.Draw; } @@ -34,6 +47,88 @@ namespace ExpandedSearchInfo { } private void Draw() { + this.DrawConfig(); + this.DrawExpandedSearchInfo(); + } + + private void DrawConfig() { + if (!this.ConfigVisible) { + return; + } + + ImGui.SetNextWindowSize(new Vector2(500, -1), ImGuiCond.FirstUseEver); + + if (!ImGui.Begin($"{this.Plugin.Name} settings", ref this._configVisible)) { + return; + } + + ImGui.PushTextWrapPos(); + + if (ImGui.Button("Clear cache")) { + this.Plugin.Repository.SearchInfos.Clear(); + } + + ImGui.SameLine(); + + var cached = this.Plugin.Repository.SearchInfos.Count; + var playersString = cached switch { + 1 => "One player", + _ => $"{cached} players", + }; + ImGui.TextUnformatted($"{playersString} in the cache"); + + ImGui.Spacing(); + + ImGui.TextUnformatted("Expanded Search Info downloads information contained in search infos once and caches it for later retrieval. If you want to clear this cache, click the button above. You can also clear individual players from the cache with the button in their expanded info."); + + ImGui.Separator(); + + if (ImGui.CollapsingHeader("Providers", ImGuiTreeNodeFlags.DefaultOpen)) { + if (!ImGui.BeginTabBar("ESI tabs")) { + return; + } + + foreach (var provider in this.Plugin.Repository.AllProviders) { + if (!ImGui.BeginTabItem($"{provider.Name}##esi-provider")) { + continue; + } + + ImGui.Columns(2); + + ImGui.SetColumnWidth(0, ImGui.GetWindowWidth() / 3); + + ImGui.TextUnformatted(provider.Description); + + ImGui.NextColumn(); + + var enabled = provider.Config.Enabled; + if (ImGui.Checkbox($"Enabled##{provider.Name}", ref enabled)) { + provider.Config.Enabled = enabled; + this.Plugin.Config.Save(); + } + + var defaultOpen = provider.Config.DefaultExpanded; + if (ImGui.Checkbox($"Open by default##{provider.Name}", ref defaultOpen)) { + provider.Config.DefaultExpanded = defaultOpen; + this.Plugin.Config.Save(); + } + + provider.DrawConfig(); + + ImGui.Columns(1); + + ImGui.EndTabItem(); + } + + ImGui.EndTabBar(); + } + + ImGui.PopTextWrapPos(); + + ImGui.End(); + } + + private void DrawExpandedSearchInfo() { // check if the examine window is open var addon = this.Plugin.Interface.Framework.Gui.GetAddonByName("CharacterInspect", 1); if (addon == null || !addon.Visible) { @@ -78,7 +173,11 @@ namespace ExpandedSearchInfo { for (var i = 0; i < expanded.Sections.Count; i++) { var section = expanded.Sections[i]; - if (!ImGui.CollapsingHeader($"{section.Name}##{i}", ImGuiTreeNodeFlags.DefaultOpen)) { + var flags = section.Provider.Config.DefaultExpanded switch { + true => ImGuiTreeNodeFlags.DefaultOpen, + false => ImGuiTreeNodeFlags.None, + }; + if (!ImGui.CollapsingHeader($"{section.Name}##{i}", flags)) { continue; } diff --git a/ExpandedSearchInfo/Providers/BaseHtmlProvider.cs b/ExpandedSearchInfo/Providers/BaseHtmlProvider.cs old mode 100755 new mode 100644 index a612f48..f57e979 --- a/ExpandedSearchInfo/Providers/BaseHtmlProvider.cs +++ b/ExpandedSearchInfo/Providers/BaseHtmlProvider.cs @@ -5,14 +5,23 @@ using System.Threading.Tasks; using AngleSharp; using AngleSharp.Html.Dom; using AngleSharp.Html.Parser; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; namespace ExpandedSearchInfo.Providers { public abstract class BaseHtmlProvider : IProvider { private IBrowsingContext Context { get; } = BrowsingContext.New(); + public abstract string Name { get; } + + public abstract string Description { get; } + + public abstract BaseConfig Config { get; } + public abstract bool ExtractsUris { get; } + public abstract void DrawConfig(); + public abstract bool Matches(Uri uri); public abstract IEnumerable? ExtractUris(int actorId, string info); diff --git a/ExpandedSearchInfo/Providers/CarrdProvider.cs b/ExpandedSearchInfo/Providers/CarrdProvider.cs old mode 100755 new mode 100644 index ddc1cae..5ee8841 --- a/ExpandedSearchInfo/Providers/CarrdProvider.cs +++ b/ExpandedSearchInfo/Providers/CarrdProvider.cs @@ -3,12 +3,28 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using AngleSharp.Dom; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; namespace ExpandedSearchInfo.Providers { public class CarrdProvider : BaseHtmlProvider { + private Plugin Plugin { get; } + + public override string Name => "carrd.co/crd.co"; + + public override string Description => "This provider provides information for carrd.co and crd.co URLs."; + + public override BaseConfig Config => this.Plugin.Config.Configs.Carrd; + public override bool ExtractsUris => false; + internal CarrdProvider(Plugin plugin) { + this.Plugin = plugin; + } + + public override void DrawConfig() { + } + public override bool Matches(Uri uri) => uri.Host.EndsWith(".carrd.co") || uri.Host.EndsWith(".crd.co"); public override IEnumerable? ExtractUris(int actorId, string info) => null; @@ -58,6 +74,7 @@ namespace ExpandedSearchInfo.Providers { } return new TextSection( + this, $"{document.Title} (carrd.co)", response.RequestMessage.RequestUri, text diff --git a/ExpandedSearchInfo/Providers/FListProvider.cs b/ExpandedSearchInfo/Providers/FListProvider.cs old mode 100755 new mode 100644 index 9713fff..7b257f8 --- a/ExpandedSearchInfo/Providers/FListProvider.cs +++ b/ExpandedSearchInfo/Providers/FListProvider.cs @@ -4,22 +4,29 @@ using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; -using AngleSharp; using AngleSharp.Dom; -using Dalamud.Plugin; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; namespace ExpandedSearchInfo.Providers { public class FListProvider : BaseHtmlProvider { - private Plugin Plugin { get; } + public override string Name => "F-List"; + + public override string Description => "This provider provides information for F-List URLs. It also searches for F-List profiles matching the character's name if /c/ is in their search info."; + + public override BaseConfig Config => this.Plugin.Config.Configs.FList; + public override bool ExtractsUris => true; internal FListProvider(Plugin plugin) { this.Plugin = plugin; } + public override void DrawConfig() { + } + public override bool Matches(Uri uri) => (uri.Host == "www.f-list.net" || uri.Host == "f-list.net") && uri.AbsolutePath.StartsWith("/c/"); public override IEnumerable? ExtractUris(int actorId, string info) { @@ -44,7 +51,13 @@ namespace ExpandedSearchInfo.Providers { var error = document.QuerySelector("#DisplayedMessage"); if (error != null) { - if (error.Text().Contains("No such character exists")) { + var errorText = error.Text(); + + if (errorText.Contains("No such character exists")) { + return null; + } + + if (errorText.Contains("has been banned")) { return null; } } @@ -84,6 +97,7 @@ namespace ExpandedSearchInfo.Providers { var charName = document.Title.Split('-')[2].Trim(); return new FListSection( + this, $"{charName} (F-List)", response.RequestMessage.RequestUri, info, diff --git a/ExpandedSearchInfo/Providers/IProvider.cs b/ExpandedSearchInfo/Providers/IProvider.cs old mode 100755 new mode 100644 index 9a32e24..b0cd31c --- a/ExpandedSearchInfo/Providers/IProvider.cs +++ b/ExpandedSearchInfo/Providers/IProvider.cs @@ -2,10 +2,17 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; namespace ExpandedSearchInfo.Providers { public interface IProvider { + string Name { get; } + + string Description { get; } + + BaseConfig Config { get; } + /// /// If this provider is capable of parsing the search info for custom Uris, this should be true. /// @@ -14,6 +21,8 @@ namespace ExpandedSearchInfo.Providers { /// bool ExtractsUris { get; } + void DrawConfig(); + /// /// Determine if this provider should run on the given Uri. /// diff --git a/ExpandedSearchInfo/Providers/PastebinProvider.cs b/ExpandedSearchInfo/Providers/PastebinProvider.cs old mode 100755 new mode 100644 index 58f1238..1a5fea9 --- a/ExpandedSearchInfo/Providers/PastebinProvider.cs +++ b/ExpandedSearchInfo/Providers/PastebinProvider.cs @@ -4,14 +4,30 @@ using System.Linq; using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; namespace ExpandedSearchInfo.Providers { public class PastebinProvider : IProvider { private static readonly Regex Matcher = new(@"pb:(\S+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private Plugin Plugin { get; } + + public string Name => "pastebin.com"; + + public string Description => "This provider provides information from pastebin.com URLs. It also works on tags such as \"pb:pasteid\"."; + + public BaseConfig Config => this.Plugin.Config.Configs.Pastebin; + public bool ExtractsUris => true; + public PastebinProvider(Plugin plugin) { + this.Plugin = plugin; + } + + public void DrawConfig() { + } + public bool Matches(Uri uri) => uri.Host == "pastebin.com" && uri.AbsolutePath.Length > 1; public IEnumerable? ExtractUris(int actorId, string info) { @@ -30,7 +46,7 @@ namespace ExpandedSearchInfo.Providers { var info = await response.Content.ReadAsStringAsync(); - return new TextSection($"Pastebin ({id})", response.RequestMessage.RequestUri, info); + return new TextSection(this, $"Pastebin ({id})", response.RequestMessage.RequestUri, info); } } } diff --git a/ExpandedSearchInfo/Providers/PlainTextProvider.cs b/ExpandedSearchInfo/Providers/PlainTextProvider.cs old mode 100755 new mode 100644 index 1626268..28258fc --- a/ExpandedSearchInfo/Providers/PlainTextProvider.cs +++ b/ExpandedSearchInfo/Providers/PlainTextProvider.cs @@ -2,12 +2,28 @@ using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; namespace ExpandedSearchInfo.Providers { public class PlainTextProvider : IProvider { + private Plugin Plugin { get; } + + public string Name => "Plain text"; + + public string Description => "This provider provides information for any URL that provides plain text."; + + public BaseConfig Config => this.Plugin.Config.Configs.PlainText; + public bool ExtractsUris => false; + internal PlainTextProvider(Plugin plugin) { + this.Plugin = plugin; + } + + public void DrawConfig() { + } + public bool Matches(Uri uri) => true; public IEnumerable? ExtractUris(int actorId, string info) => null; @@ -20,7 +36,7 @@ namespace ExpandedSearchInfo.Providers { var info = await response.Content.ReadAsStringAsync(); var uri = response.RequestMessage.RequestUri; - return new TextSection($"Text##{uri}", response.RequestMessage.RequestUri, info); + return new TextSection(this, $"Text##{uri}", response.RequestMessage.RequestUri, info); } } } diff --git a/ExpandedSearchInfo/Providers/RefsheetProvider.cs b/ExpandedSearchInfo/Providers/RefsheetProvider.cs old mode 100755 new mode 100644 index 05ced3d..a989862 --- a/ExpandedSearchInfo/Providers/RefsheetProvider.cs +++ b/ExpandedSearchInfo/Providers/RefsheetProvider.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; +using ExpandedSearchInfo.Configs; using ExpandedSearchInfo.Sections; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -11,8 +12,23 @@ namespace ExpandedSearchInfo.Providers { public class RefsheetProvider : BaseHtmlProvider { private const string JsonLineStart = "var props = "; + private Plugin Plugin { get; } + + public override string Name => "Refsheet"; + + public override string Description => "This provider provides information for refsheet.net and ref.st URLs."; + + public override BaseConfig Config => this.Plugin.Config.Configs.Refsheet; + public override bool ExtractsUris => false; + internal RefsheetProvider(Plugin plugin) { + this.Plugin = plugin; + } + + public override void DrawConfig() { + } + public override bool Matches(Uri uri) => uri.Host == "refsheet.net" || uri.Host == "ref.st"; public override IEnumerable? ExtractUris(int actorId, string info) => null; @@ -95,6 +111,7 @@ namespace ExpandedSearchInfo.Providers { } return new RefsheetSection( + this, $"{name} (Refsheet)", response.RequestMessage.RequestUri, attributes, diff --git a/ExpandedSearchInfo/SearchInfoRepository.cs b/ExpandedSearchInfo/SearchInfoRepository.cs old mode 100755 new mode 100644 index 8590c0b..cb518f4 --- a/ExpandedSearchInfo/SearchInfoRepository.cs +++ b/ExpandedSearchInfo/SearchInfoRepository.cs @@ -29,6 +29,7 @@ namespace ExpandedSearchInfo { internal int LastActorId { get; private set; } private List Providers { get; } = new(); + internal IEnumerable AllProviders => this.Providers; internal SearchInfoRepository(Plugin plugin) { this.Plugin = plugin; @@ -53,11 +54,11 @@ namespace ExpandedSearchInfo { } private void AddProviders() { - this.Providers.Add(new PastebinProvider()); - this.Providers.Add(new CarrdProvider()); + this.Providers.Add(new PastebinProvider(this.Plugin)); + this.Providers.Add(new CarrdProvider(this.Plugin)); this.Providers.Add(new FListProvider(this.Plugin)); - this.Providers.Add(new RefsheetProvider()); - this.Providers.Add(new PlainTextProvider()); + this.Providers.Add(new RefsheetProvider(this.Plugin)); + this.Providers.Add(new PlainTextProvider(this.Plugin)); } private void ProcessSearchInfo(int actorId, string info) { @@ -93,7 +94,7 @@ namespace ExpandedSearchInfo { // extract uris from the search info with providers var extractedUris = this.Providers - .Where(provider => provider.ExtractsUris) + .Where(provider => provider.Config.Enabled && provider.ExtractsUris) .Select(provider => provider.ExtractUris(actorId, info)) .Where(uris => uris != null) .SelectMany(uris => uris); @@ -151,7 +152,7 @@ namespace ExpandedSearchInfo { // find the providers that run on this uri var matching = this.Providers - .Where(provider => provider.Matches(uri)) + .Where(provider => provider.Config.Enabled && provider.Matches(uri)) .ToList(); // skip the uri if no providers diff --git a/ExpandedSearchInfo/Sections/FListSection.cs b/ExpandedSearchInfo/Sections/FListSection.cs old mode 100755 new mode 100644 index e2ba151..f868216 --- a/ExpandedSearchInfo/Sections/FListSection.cs +++ b/ExpandedSearchInfo/Sections/FListSection.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using ExpandedSearchInfo.Providers; using ImGuiNET; namespace ExpandedSearchInfo.Sections { public class FListSection : ISearchInfoSection { + public IProvider Provider { get; } public string Name { get; } public Uri Uri { get; } @@ -15,7 +17,8 @@ namespace ExpandedSearchInfo.Sections { private List> Maybe { get; } private List> No { get; } - internal FListSection(string name, Uri uri, string info, List> stats, List> fave, List> yes, List> maybe, List> no) { + internal FListSection(IProvider provider, string name, Uri uri, string info, List> stats, List> fave, List> yes, List> maybe, List> no) { + this.Provider = provider; this.Name = name; this.Uri = uri; diff --git a/ExpandedSearchInfo/Sections/ISearchInfoSection.cs b/ExpandedSearchInfo/Sections/ISearchInfoSection.cs old mode 100755 new mode 100644 index 835dcdd..08d1cf8 --- a/ExpandedSearchInfo/Sections/ISearchInfoSection.cs +++ b/ExpandedSearchInfo/Sections/ISearchInfoSection.cs @@ -1,7 +1,9 @@ using System; +using ExpandedSearchInfo.Providers; namespace ExpandedSearchInfo.Sections { public interface ISearchInfoSection { + IProvider Provider { get; } string Name { get; } Uri Uri { get; } diff --git a/ExpandedSearchInfo/Sections/RefsheetSection.cs b/ExpandedSearchInfo/Sections/RefsheetSection.cs old mode 100755 new mode 100644 index 8ae7027..60602db --- a/ExpandedSearchInfo/Sections/RefsheetSection.cs +++ b/ExpandedSearchInfo/Sections/RefsheetSection.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using ExpandedSearchInfo.Providers; using ImGuiNET; namespace ExpandedSearchInfo.Sections { public class RefsheetSection : ISearchInfoSection { + public IProvider Provider { get; } public string Name { get; } public Uri Uri { get; } @@ -11,7 +13,8 @@ namespace ExpandedSearchInfo.Sections { private string Notes { get; } private List> Cards { get; } - internal RefsheetSection(string name, Uri uri, List> attributes, string notes, List> cards) { + internal RefsheetSection(IProvider provider, string name, Uri uri, List> attributes, string notes, List> cards) { + this.Provider = provider; this.Name = name; this.Uri = uri; this.Attributes = attributes; diff --git a/ExpandedSearchInfo/Sections/TextSection.cs b/ExpandedSearchInfo/Sections/TextSection.cs old mode 100755 new mode 100644 index 0e9369e..31ad051 --- a/ExpandedSearchInfo/Sections/TextSection.cs +++ b/ExpandedSearchInfo/Sections/TextSection.cs @@ -1,13 +1,16 @@ using System; -using ImGuiNET; +using ExpandedSearchInfo.Providers; namespace ExpandedSearchInfo.Sections { public class TextSection : ISearchInfoSection { - private string Info { get; } + public IProvider Provider { get; } public string Name { get; } public Uri Uri { get; } - internal TextSection(string name, Uri uri, string info) { + private string Info { get; } + + internal TextSection(IProvider provider, string name, Uri uri, string info) { + this.Provider = provider; this.Name = name; this.Uri = uri; this.Info = info; diff --git a/ExpandedSearchInfo/Util.cs b/ExpandedSearchInfo/Util.cs old mode 100755 new mode 100644 index 0e2d304..a0ea113 --- a/ExpandedSearchInfo/Util.cs +++ b/ExpandedSearchInfo/Util.cs @@ -33,4 +33,4 @@ namespace ExpandedSearchInfo { } } } -} +} \ No newline at end of file