Skip to content

Commit

Permalink
Merge pull request #680 from Diyagi/CommandProcessorFix
Browse files Browse the repository at this point in the history
Command processor fix
  • Loading branch information
SlashNephy authored Sep 19, 2024
2 parents 40b1abe + c8ff3a3 commit 8314022
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Common/Api/Command/CommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Dalamud.Divination.Common.Api.Command.Attributes;
using Dalamud.Divination.Common.Api.Dalamud;
using Dalamud.Divination.Common.Api.Dalamud.Payload;
using Dalamud.Game;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
Expand All @@ -19,8 +20,13 @@ internal sealed partial class CommandProcessor : ICommandProcessor
private readonly IChatClient chatClient;
private readonly IChatGui chatGui;

private readonly Regex commandRegexCn;
private readonly Regex commandRegex;
private readonly Regex commandRegexEn = new(@"^The command (?<command>.+) does not exist\.$", RegexOptions.Compiled);
private readonly Regex commandRegexJp = new(@"^そのコマンドはありません。: (?<command>.+)$", RegexOptions.Compiled);
private readonly Regex commandRegexDe = new(@"^„(?<command>.+)“ existiert nicht als Textkommando\.$", RegexOptions.Compiled);
private readonly Regex commandRegexFr = new(@"^La commande texte “(?<command>.+)” n'existe pas\.$", RegexOptions.Compiled);
private readonly Regex commandRegexCn = new(@"^^(“|「)(?<command>.+)(”|」)(出现问题:该命令不存在|出現問題:該命令不存在)。$", RegexOptions.Compiled);
private readonly Regex currentLangCommandRegex;

private readonly List<DivinationCommand> commands = new();
private readonly object commandsLock = new();
private readonly string pluginName;
Expand All @@ -36,17 +42,17 @@ public CommandProcessor(string pluginName, string? prefix, IChatGui chatGui, ICh

chatGui.CheckMessageHandled += OnCheckMessageHandled;

var dalamudCommandManagerService =
commandManager.GetType().GetField("commandManagerService", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(commandManager)!;

commandRegex =
dalamudCommandManagerService.GetType().GetField("currentLangCommandRegex", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(
dalamudCommandManagerService) as Regex ?? throw new NotSupportedException();
commandRegexCn =
dalamudCommandManagerService.GetType().GetField("commandRegexCn", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(
dalamudCommandManagerService) as Regex ?? throw new NotSupportedException();

DalamudLog.Log.Debug(commandRegex.ToString());
var api = ServiceContainer.Get<IDalamudApi>();
currentLangCommandRegex = (ClientLanguage)api?.ClientState.ClientLanguage! switch
{
ClientLanguage.Japanese => commandRegexJp,
ClientLanguage.English => commandRegexEn,
ClientLanguage.German => commandRegexDe,
ClientLanguage.French => commandRegexFr,
_ => commandRegexEn,
};

DalamudLog.Log.Debug(currentLangCommandRegex.ToString());
}

public string? Prefix { get; }
Expand Down Expand Up @@ -154,7 +160,7 @@ private void OnCheckMessageHandled(XivChatType type, int timestamp, ref SeString
return;
}

var cmdMatch = commandRegex.Match(message.TextValue).Groups["command"];
var cmdMatch = currentLangCommandRegex.Match(message.TextValue).Groups["command"];
if (cmdMatch.Success)
{
var command = cmdMatch.Value;
Expand Down

0 comments on commit 8314022

Please sign in to comment.