2020-08-04 22:22:57 +00:00
|
|
|
|
using Dalamud.Configuration;
|
|
|
|
|
using Dalamud.Plugin;
|
2020-08-22 03:27:12 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
using System;
|
2020-08-06 04:17:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-22 03:27:12 +00:00
|
|
|
|
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
|
|
|
|
|
2021-03-04 01:15:11 +00:00
|
|
|
|
private DalamudPluginInterface Interface { get; set; } = null!;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2021-04-28 16:50:26 +00:00
|
|
|
|
public int Version { get; set; } = 2;
|
2020-08-21 17:46:42 +00:00
|
|
|
|
|
2020-12-21 02:49:10 +00:00
|
|
|
|
public bool AdvancedMode { get; set; }
|
2020-08-06 04:17:14 +00:00
|
|
|
|
|
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
|
|
|
|
|
2020-08-22 03:27:12 +00:00
|
|
|
|
[JsonIgnore]
|
2021-02-16 17:15:00 +00:00
|
|
|
|
public List<Regex> CompiledChatRegexes { get; private set; } = new();
|
2020-08-06 04:17:14 +00:00
|
|
|
|
|
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
|
|
|
|
|
2020-08-22 03:27:12 +00:00
|
|
|
|
[JsonIgnore]
|
2021-04-28 16:50:26 +00:00
|
|
|
|
public List<Regex> CompiledPfRegexes { get; private set; } = new();
|
2020-08-06 04:17:14 +00:00
|
|
|
|
|
2020-12-21 02:49:10 +00:00
|
|
|
|
public bool FilterHugeItemLevelPFs { get; set; }
|
|
|
|
|
|
2021-04-28 14:15:41 +00:00
|
|
|
|
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-17 00:41:59 +00:00
|
|
|
|
|
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,
|
|
|
|
|
},
|
2021-03-31 18:37:08 +00:00
|
|
|
|
[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
|
|
|
|
},
|
2021-03-02 18:19:47 +00:00
|
|
|
|
[MessageCategory.Community] = new HashSet<ChatType> {
|
|
|
|
|
ChatType.None,
|
2023-09-29 00:59:42 +00:00
|
|
|
|
ChatType.Shout,
|
|
|
|
|
ChatType.Yell,
|
2021-03-02 18:19:47 +00:00
|
|
|
|
},
|
2021-07-20 00:51:28 +00:00
|
|
|
|
[MessageCategory.Fluff] = new HashSet<ChatType> {
|
|
|
|
|
ChatType.None,
|
2023-09-29 00:59:42 +00:00
|
|
|
|
ChatType.Shout,
|
|
|
|
|
ChatType.Yell,
|
2021-07-20 00:51:28 +00:00
|
|
|
|
},
|
2020-12-21 02:49:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public bool LogFilteredPfs { get; set; } = true;
|
|
|
|
|
public bool LogFilteredChat { get; set; } = true;
|
2020-08-23 14:55:52 +00:00
|
|
|
|
|
2021-02-17 00:41:59 +00:00
|
|
|
|
public bool ConsiderPrivatePfs { get; set; }
|
|
|
|
|
|
2021-04-25 19:19:42 +00:00
|
|
|
|
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) {
|
2021-03-04 01:15:11 +00:00
|
|
|
|
this.Interface = pi;
|
2020-08-22 03:27:12 +00:00
|
|
|
|
this.CompileRegexes();
|
2020-08-04 22:22:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save() {
|
2021-03-04 01:15:11 +00:00
|
|
|
|
this.Interface.SavePluginConfig(this);
|
2020-08-04 22:22:57 +00:00
|
|
|
|
}
|
2020-08-22 03:27:12 +00:00
|
|
|
|
|
|
|
|
|
public void CompileRegexes() {
|
|
|
|
|
this.CompiledChatRegexes = this.ChatRegexes
|
2021-04-25 19:19:42 +00:00
|
|
|
|
.Where(reg => !string.IsNullOrWhiteSpace(reg))
|
2020-08-22 03:27:12 +00:00
|
|
|
|
.Select(reg => new Regex(reg, RegexOptions.Compiled))
|
|
|
|
|
.ToList();
|
2021-04-28 16:50:26 +00:00
|
|
|
|
this.CompiledPfRegexes = this.PFRegexes
|
2021-04-25 19:19:42 +00:00
|
|
|
|
.Where(reg => !string.IsNullOrWhiteSpace(reg))
|
2020-08-22 03:27:12 +00:00
|
|
|
|
.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 {
|
2021-03-02 18:19:47 +00:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 18:19:47 +00:00
|
|
|
|
// 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);
|
|
|
|
|
}
|
2021-05-16 00:31:22 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|