feat: handle special characters

This commit is contained in:
Anna 2020-08-04 19:30:29 -04:00
parent e8272e8010
commit 15f0df08f3
6 changed files with 70 additions and 5 deletions

56
NoSoliciting/CharUtil.cs Normal file
View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NoSoliciting {
public static class RMTUtil {
private static readonly Dictionary<char, string> replacements = new Dictionary<char, string>() {
// alphabet
['\ue070'] = "?",
['\ue071'] = "A",
['\ue072'] = "B",
['\ue073'] = "C",
['\ue074'] = "D",
['\ue075'] = "E",
['\ue076'] = "F",
['\ue077'] = "G",
['\ue078'] = "H",
['\ue079'] = "I",
['\ue07a'] = "J",
['\ue07b'] = "K",
['\ue07c'] = "L",
['\ue07d'] = "M",
['\ue07e'] = "N",
['\ue07f'] = "O",
['\ue080'] = "P",
['\ue081'] = "Q",
['\ue082'] = "R",
['\ue083'] = "S",
['\ue084'] = "T",
['\ue085'] = "U",
['\ue086'] = "V",
['\ue087'] = "W",
['\ue088'] = "X",
['\ue089'] = "Y",
['\ue08a'] = "Z",
// letters in other sets
['\ue022'] = "A",
['\ue024'] = "_A",
['\ue0b0'] = "E",
};
public static string Normalise(string input) {
if (input == null) {
throw new ArgumentNullException(nameof(input), "input cannot be null");
}
foreach (KeyValuePair<char, string> entry in replacements) {
input = input.Replace($"{entry.Key}", entry.Value);
}
return input.Normalize(NormalizationForm.FormKD);
}
}
}

View File

@ -49,6 +49,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\ImGuiScene.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Users\Kyle\AppData\Roaming\XIVLauncher\addon\Hooks\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -59,6 +63,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CharUtil.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="PFPacket.cs" />
<Compile Include="Plugin.cs" />
@ -95,4 +100,4 @@
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.6\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.6\build\Microsoft.NetFramework.Analyzers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.6\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.6\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
</Target>
</Project>
</Project>

View File

@ -18,7 +18,8 @@ namespace NoSoliciting {
this.pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null");
this.ui = new PluginUI(this);
this.Config = this.pi.GetPluginConfig() as PluginConfiguration ?? new PluginConfiguration(this.pi);
this.Config = this.pi.GetPluginConfig() as PluginConfiguration ?? new PluginConfiguration();
this.Config.Initialise(this.pi);
this.rmt = new RMTDetection(this);

View File

@ -1,19 +1,20 @@
using Dalamud.Configuration;
using Dalamud.Plugin;
using Newtonsoft.Json;
using System;
namespace NoSoliciting {
[Serializable]
public class PluginConfiguration : IPluginConfiguration {
[NonSerialized]
private readonly DalamudPluginInterface pi;
private DalamudPluginInterface pi;
public int Version { get; set; } = 1;
public bool FilterChat { get; set; } = true;
public bool FilterPartyFinder { get; set; } = true;
public PluginConfiguration(DalamudPluginInterface pi) {
public void Initialise(DalamudPluginInterface pi) {
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
}

View File

@ -37,6 +37,8 @@ namespace NoSoliciting {
private static readonly Regex rmtRegex = new Regex(@"Off Code( *)", RegexOptions.Compiled);
public static bool IsRMT(string msg) {
msg = RMTUtil.Normalise(msg);
return rmtSubstrings.Any(needle => msg.Contains(needle))
|| rmtRegex.IsMatch(msg);
}

View File

@ -25,7 +25,7 @@ namespace NoSoliciting {
throw new ArgumentNullException(nameof(desc), "description string cannot be null");
}
desc = desc.ToLowerInvariant();
desc = RMTUtil.Normalise(desc).ToLowerInvariant();
bool containsSell = selling.Any(needle => desc.Contains(needle));
bool containsContent = content.Any(needle => desc.Contains(needle));