mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-22 15:57:44 +01:00
feat: add OnCheckChatMessageHandled, refactor ChatGui a bit
This commit is contained in:
parent
474294d604
commit
af9d50266c
3 changed files with 72 additions and 41 deletions
|
|
@ -92,14 +92,37 @@ namespace Dalamud.Game {
|
||||||
public ChatHandlers(Dalamud dalamud) {
|
public ChatHandlers(Dalamud dalamud) {
|
||||||
this.dalamud = dalamud;
|
this.dalamud = dalamud;
|
||||||
|
|
||||||
|
dalamud.Framework.Gui.Chat.OnCheckMessageHandled += OnCheckMessageHandled;
|
||||||
dalamud.Framework.Gui.Chat.OnChatMessageRaw += OnChatMessage;
|
dalamud.Framework.Gui.Chat.OnChatMessageRaw += OnChatMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCheckMessageHandled(XivChatType type, uint senderid, ref SeString sender, ref SeString message, ref bool isHandled) {
|
||||||
|
var textVal = message.TextValue;
|
||||||
|
|
||||||
|
var matched = this.rmtRegex.IsMatch(textVal);
|
||||||
|
if (matched)
|
||||||
|
{
|
||||||
|
// This seems to be a RMT ad - let's not show it
|
||||||
|
Log.Debug("Handled RMT ad: " + message.TextValue);
|
||||||
|
isHandled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (this.dalamud.Configuration.BadWords != null &&
|
||||||
|
this.dalamud.Configuration.BadWords.Any(x => textVal.Contains(x)))
|
||||||
|
{
|
||||||
|
// This seems to be in the user block list - let's not show it
|
||||||
|
Log.Debug("Blocklist triggered");
|
||||||
|
isHandled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string LastLink { get; private set; }
|
public string LastLink { get; private set; }
|
||||||
|
|
||||||
private void OnChatMessage(XivChatType type, uint senderId, ref StdString sender,
|
private void OnChatMessage(XivChatType type, uint senderId, ref StdString sender,
|
||||||
ref StdString message, ref bool isHandled) {
|
ref StdString message, bool isHandled) {
|
||||||
|
|
||||||
if (type == XivChatType.Notice && !this.hasSeenLoadingMsg) {
|
if (type == XivChatType.Notice && !this.hasSeenLoadingMsg) {
|
||||||
var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
|
var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString();
|
||||||
|
|
@ -142,25 +165,9 @@ namespace Dalamud.Game {
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var matched = this.rmtRegex.IsMatch(message.Value);
|
|
||||||
if (matched) {
|
|
||||||
// This seems to be a RMT ad - let's not show it
|
|
||||||
Log.Debug("Handled RMT ad");
|
|
||||||
isHandled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var messageVal = message.Value;
|
var messageVal = message.Value;
|
||||||
var senderVal = sender.Value;
|
var senderVal = sender.Value;
|
||||||
|
|
||||||
if (this.dalamud.Configuration.BadWords != null &&
|
|
||||||
this.dalamud.Configuration.BadWords.Any(x => messageVal.Contains(x))) {
|
|
||||||
// This seems to be in the user block list - let's not show it
|
|
||||||
Log.Debug("Blocklist triggered");
|
|
||||||
isHandled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == XivChatType.RetainerSale)
|
if (type == XivChatType.RetainerSale)
|
||||||
{
|
{
|
||||||
foreach (var regex in retainerSaleRegexes[dalamud.StartInfo.Language])
|
foreach (var regex in retainerSaleRegexes[dalamud.StartInfo.Language])
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Dalamud.Game.Chat;
|
using Dalamud.Game.Chat;
|
||||||
|
using Dalamud.Game.Chat.SeStringHandling;
|
||||||
using Dalamud.Game.Internal.Libc;
|
using Dalamud.Game.Internal.Libc;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
|
@ -54,13 +55,12 @@ namespace Dalamud.Game.Command {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dalamud.Framework.Gui.Chat.OnChatMessageRaw += OnChatMessage;
|
dalamud.Framework.Gui.Chat.OnCheckMessageHandled += OnCheckMessageHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnChatMessage(XivChatType type, uint senderId, ref StdString sender,
|
private void OnCheckMessageHandled(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) {
|
||||||
ref StdString message, ref bool isHandled) {
|
|
||||||
if (type == XivChatType.ErrorMessage && senderId == 0) {
|
if (type == XivChatType.ErrorMessage && senderId == 0) {
|
||||||
var cmdMatch = this.currentLangCommandRegex.Match(message.Value).Groups["command"];
|
var cmdMatch = this.currentLangCommandRegex.Match(message.TextValue).Groups["command"];
|
||||||
if (cmdMatch.Success) {
|
if (cmdMatch.Success) {
|
||||||
// Yes, it's a chat command.
|
// Yes, it's a chat command.
|
||||||
var command = cmdMatch.Value;
|
var command = cmdMatch.Value;
|
||||||
|
|
|
||||||
|
|
@ -11,30 +11,52 @@ using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Game.Internal.Gui {
|
namespace Dalamud.Game.Internal.Gui {
|
||||||
public sealed class ChatGui : IDisposable {
|
public sealed class ChatGui : IDisposable {
|
||||||
|
private readonly Queue<XivChatEntry> chatQueue = new Queue<XivChatEntry>();
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, bool isHandled);
|
||||||
|
public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, bool isHandled);
|
||||||
|
public delegate void OnCheckMessageHandledDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that allows you to stop messages from appearing in chat by setting the isHandled parameter to true.
|
||||||
|
/// </summary>
|
||||||
|
public event OnCheckMessageHandledDelegate OnCheckMessageHandled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that will be fired when a chat message is sent to chat by the game.
|
||||||
|
/// </summary>
|
||||||
|
public event OnMessageDelegate OnChatMessage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that will be fired when a chat message is sent by the game, containing raw, unparsed data.
|
||||||
|
/// </summary>
|
||||||
|
[Obsolete("Please use OnChatMessage instead. For modifications, it will take precedence.")]
|
||||||
|
public event OnMessageRawDelegate OnChatMessageRaw;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Hooks
|
||||||
|
|
||||||
|
private readonly Hook<PrintMessageDelegate> printMessageHook;
|
||||||
|
|
||||||
|
private readonly Hook<PopulateItemLinkDelegate> populateItemLinkHook;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Delegates
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate IntPtr PrintMessageDelegate(IntPtr manager, XivChatType chatType, IntPtr senderName,
|
private delegate IntPtr PrintMessageDelegate(IntPtr manager, XivChatType chatType, IntPtr senderName,
|
||||||
IntPtr message,
|
IntPtr message,
|
||||||
uint senderId, IntPtr parameter);
|
uint senderId, IntPtr parameter);
|
||||||
|
|
||||||
public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message,
|
|
||||||
ref bool isHandled);
|
|
||||||
|
|
||||||
public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message,
|
|
||||||
ref bool isHandled);
|
|
||||||
|
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate void PopulateItemLinkDelegate(IntPtr linkObjectPtr, IntPtr itemInfoPtr);
|
private delegate void PopulateItemLinkDelegate(IntPtr linkObjectPtr, IntPtr itemInfoPtr);
|
||||||
|
|
||||||
private readonly Queue<XivChatEntry> chatQueue = new Queue<XivChatEntry>();
|
#endregion
|
||||||
|
|
||||||
private readonly Hook<PrintMessageDelegate> printMessageHook;
|
|
||||||
|
|
||||||
public event OnMessageDelegate OnChatMessage;
|
|
||||||
[Obsolete("Please use OnChatMessage instead. For modifications, it will take precedence.")]
|
|
||||||
public event OnMessageRawDelegate OnChatMessageRaw;
|
|
||||||
|
|
||||||
private readonly Hook<PopulateItemLinkDelegate> populateItemLinkHook;
|
|
||||||
|
|
||||||
public int LastLinkedItemId { get; private set; }
|
public int LastLinkedItemId { get; private set; }
|
||||||
public byte LastLinkedItemFlags { get; private set; }
|
public byte LastLinkedItemFlags { get; private set; }
|
||||||
|
|
@ -106,8 +128,10 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
|
|
||||||
// Call events
|
// Call events
|
||||||
var isHandled = false;
|
var isHandled = false;
|
||||||
OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled);
|
OnCheckMessageHandled?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled);
|
||||||
OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, ref isHandled);
|
|
||||||
|
OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, isHandled);
|
||||||
|
OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, isHandled);
|
||||||
|
|
||||||
var newEdited = parsedMessage.Encode();
|
var newEdited = parsedMessage.Encode();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue