NoSoliciting/NoSoliciting/PluginConfiguration.cs

163 lines
5.6 KiB
C#
Raw Permalink Normal View History

2020-08-04 22:22:57 +00:00
using Dalamud.Configuration;
using Dalamud.Plugin;
using Newtonsoft.Json;
2020-08-04 22:22:57 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
2020-12-21 02:49:10 +00:00
using NoSoliciting.Ml;
2020-08-04 22:22:57 +00:00
namespace NoSoliciting {
[Serializable]
public class PluginConfiguration : IPluginConfiguration {
2021-02-16 17:15:00 +00:00
public static readonly PluginConfiguration Default = new();
2020-12-21 02:49:10 +00:00
private DalamudPluginInterface Interface { get; set; } = null!;
2020-08-04 22:22:57 +00:00
public int Version { get; set; } = 2;
2020-12-21 02:49:10 +00:00
public bool AdvancedMode { get; set; }
2020-12-21 02:49:10 +00:00
public bool CustomChatFilter { get; set; }
2021-02-16 17:15:00 +00:00
public List<string> ChatSubstrings { get; } = new();
public List<string> ChatRegexes { get; } = new();
2020-12-21 02:49:10 +00:00
[JsonIgnore]
2021-02-16 17:15:00 +00:00
public List<Regex> CompiledChatRegexes { get; private set; } = new();
2020-12-21 02:49:10 +00:00
public bool CustomPFFilter { get; set; }
2021-02-16 17:15:00 +00:00
public List<string> PFSubstrings { get; } = new();
public List<string> PFRegexes { get; } = new();
2020-12-21 02:49:10 +00:00
[JsonIgnore]
public List<Regex> CompiledPfRegexes { get; private set; } = new();
2020-12-21 02:49:10 +00:00
public bool FilterHugeItemLevelPFs { get; set; }
public bool FollowGameLanguage { get; set; }
2021-02-16 17:15:00 +00:00
public HashSet<MessageCategory> BasicMlFilters { get; set; } = new() {
2020-12-21 02:49:10 +00:00
MessageCategory.RmtGil,
MessageCategory.RmtContent,
MessageCategory.Phishing,
};
2021-02-16 17:15:00 +00:00
public Dictionary<MessageCategory, HashSet<ChatType>> MlFilters { get; set; } = new() {
2020-12-21 02:49:10 +00:00
[MessageCategory.RmtGil] = new HashSet<ChatType> {
2023-09-29 00:59:42 +00:00
ChatType.None,
2020-12-21 02:49:10 +00:00
ChatType.Say,
2021-10-29 19:46:24 +00:00
ChatType.Shout,
2020-12-21 02:49:10 +00:00
},
[MessageCategory.RmtContent] = new HashSet<ChatType> {
ChatType.None,
2023-09-29 00:59:42 +00:00
ChatType.Say,
ChatType.Shout,
2020-12-21 02:49:10 +00:00
},
[MessageCategory.Phishing] = new HashSet<ChatType> {
2023-09-29 00:59:42 +00:00
ChatType.None,
2020-12-21 02:49:10 +00:00
ChatType.TellIncoming,
},
[MessageCategory.Roleplaying] = new HashSet<ChatType> {
ChatType.None,
ChatType.Shout,
ChatType.Yell,
},
[MessageCategory.FreeCompany] = new HashSet<ChatType> {
ChatType.None,
ChatType.Shout,
ChatType.Yell,
ChatType.TellIncoming,
},
[MessageCategory.Static] = new HashSet<ChatType> {
ChatType.None,
},
[MessageCategory.StaticSub] = new HashSet<ChatType> {
ChatType.None,
},
2020-12-21 02:49:10 +00:00
[MessageCategory.Trade] = new HashSet<ChatType> {
ChatType.None,
2023-09-29 00:59:42 +00:00
ChatType.Shout,
ChatType.Yell,
2020-12-21 02:49:10 +00:00
},
[MessageCategory.Community] = new HashSet<ChatType> {
ChatType.None,
2023-09-29 00:59:42 +00:00
ChatType.Shout,
ChatType.Yell,
},
[MessageCategory.Fluff] = new HashSet<ChatType> {
ChatType.None,
2023-09-29 00:59:42 +00:00
ChatType.Shout,
ChatType.Yell,
},
2020-12-21 02:49:10 +00:00
};
public bool LogFilteredPfs { get; set; } = true;
public bool LogFilteredChat { get; set; } = true;
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));
2020-08-04 23:30:29 +00:00
public void Initialise(DalamudPluginInterface pi) {
this.Interface = pi;
this.CompileRegexes();
2020-08-04 22:22:57 +00:00
}
public void Save() {
this.Interface.SavePluginConfig(this);
2020-08-04 22:22:57 +00:00
}
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();
}
2020-12-21 02:49:10 +00:00
internal bool MlEnabledOn(MessageCategory category, ChatType chatType) {
2021-08-22 22:07:28 +00:00
HashSet<ChatType>? filtered;
2020-12-21 02:49:10 +00:00
if (this.AdvancedMode) {
if (!this.MlFilters.TryGetValue(category, out filtered)) {
return false;
}
} else {
// check to see if the user has this category filtered
2020-12-21 02:49:10 +00:00
if (!this.BasicMlFilters.Contains(category)) {
return false;
}
// get the chat types that this category is enabled on by default
2020-12-21 02:49:10 +00:00
if (!Default.MlFilters.TryGetValue(category, out filtered)) {
return false;
}
}
return filtered.Contains(chatType);
}
internal IEnumerable<MessageCategory> CreateFiltersClone() {
var filters = new HashSet<MessageCategory>();
foreach (var category in (MessageCategory[]) Enum.GetValues(typeof(MessageCategory))) {
if (this.AdvancedMode) {
if (this.MlFilters.TryGetValue(category, out var filtered) && filtered.Count > 0) {
filters.Add(category);
}
} else {
if (this.BasicMlFilters.Contains(category)) {
filters.Add(category);
}
}
}
return filters;
}
2020-08-04 22:22:57 +00:00
}
}