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
|
|
|
|
|
|
|
|
|
public int Version { get; set; } = 1;
|
|
|
|
|
|
2020-09-04 18:01:10 +00:00
|
|
|
|
[Obsolete("Use FilterStatus")]
|
2020-08-04 22:22:57 +00:00
|
|
|
|
public bool FilterChat { get; set; } = true;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
|
2020-09-04 18:01:10 +00:00
|
|
|
|
[Obsolete("Use FilterStatus")]
|
2020-08-21 09:00:04 +00:00
|
|
|
|
public bool FilterFCRecruitments { get; set; } = false;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
|
2020-09-04 18:01:10 +00:00
|
|
|
|
[Obsolete("Use FilterStatus")]
|
2020-08-21 09:00:04 +00:00
|
|
|
|
public bool FilterChatRPAds { get; set; } = false;
|
|
|
|
|
|
2020-09-04 18:01:10 +00:00
|
|
|
|
[Obsolete("Use FilterStatus")]
|
2020-08-04 22:22:57 +00:00
|
|
|
|
public bool FilterPartyFinder { get; set; } = true;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
|
2020-09-04 18:01:10 +00:00
|
|
|
|
[Obsolete("Use FilterStatus")]
|
2020-08-21 09:00:04 +00:00
|
|
|
|
public bool FilterPartyFinderRPAds { get; set; } = false;
|
2020-08-04 22:22:57 +00:00
|
|
|
|
|
2021-02-16 17:15:00 +00:00
|
|
|
|
public Dictionary<string, bool> FilterStatus { get; private set; } = new();
|
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-02-16 17:15:00 +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-02-25 01:20:04 +00:00
|
|
|
|
public bool UseMachineLearning { get; set; } = true;
|
2020-12-21 02:49:10 +00:00
|
|
|
|
|
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> {
|
|
|
|
|
ChatType.Say,
|
|
|
|
|
},
|
|
|
|
|
[MessageCategory.RmtContent] = new HashSet<ChatType> {
|
|
|
|
|
ChatType.None,
|
|
|
|
|
},
|
|
|
|
|
[MessageCategory.Phishing] = new HashSet<ChatType> {
|
|
|
|
|
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.Trade] = new HashSet<ChatType> {
|
|
|
|
|
ChatType.None,
|
|
|
|
|
},
|
2021-03-02 18:19:47 +00:00
|
|
|
|
[MessageCategory.Community] = new HashSet<ChatType> {
|
|
|
|
|
ChatType.None,
|
|
|
|
|
},
|
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; }
|
|
|
|
|
|
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
|
|
|
|
|
.Select(reg => new Regex(reg, RegexOptions.Compiled))
|
|
|
|
|
.ToList();
|
|
|
|
|
this.CompiledPFRegexes = this.PFRegexes
|
|
|
|
|
.Select(reg => new Regex(reg, RegexOptions.Compiled))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2020-12-21 02:49:10 +00:00
|
|
|
|
|
|
|
|
|
internal bool MlEnabledOn(MessageCategory category, ChatType chatType) {
|
|
|
|
|
HashSet<ChatType> filtered;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2020-08-04 22:22:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|