Fix bug preventing all non-image messages from being sent (closes #30)

This commit is contained in:
Oliver 2025-12-21 21:30:54 -07:00
parent 455a301875
commit 1ce2e01f5c

View file

@ -28,7 +28,7 @@ export function chatImageLinks() {
type: Boolean,
default: true,
config: true,
requiresReload: true,
requiresReload: false,
onChange: (newValue) => {
if (newValue) {
hookID = Hooks.on(`chatMessage`, chatMessageHandler);
@ -37,13 +37,6 @@ export function chatImageLinks() {
};
},
});
game.settings.register(__ID__, key + `-showPromptAgain`, {
scope: `user`,
type: Boolean,
default: true,
config: false,
});
// #endregion Registration
// #region Implementation
@ -65,9 +58,6 @@ const pattern = new RegExp(
// MARK: Mutate & Resend
const handled = new Set();
async function mutateAndResendMessage(chatLog, message, options) {
const match = message.match(pattern);
if (!match) { return };
const validMatches = new Set();
const matches = message.match(pattern);
@ -99,7 +89,14 @@ async function mutateAndResendMessage(chatLog, message, options) {
*/
function chatMessageHandler(chatLog, message, options) {
if (!game.settings.get(__ID__, key)) { return };
// Don't re-process the same message
if (handled.has(message)) { return };
// Prevent cancellation for non-matching messages
const match = message.match(pattern);
if (!match) { return };
mutateAndResendMessage(chatLog, message, options);
return false;
};