From 3144d9c1f06a6b0dcb0f19d0375ec2c082dab82a Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Thu, 27 May 2021 17:45:04 -0400 Subject: [PATCH] common: strip format codes for Message ignores Strip IRC formatting codes from the message for ignore rules that match on Message contents. Pros: * Easier to set ignore rules for rainbow-messages or other format spam * Consistent with highlight rules/highlight ignore rules Cons: * Not possible to ignore messages matching a specific format pattern * Breaks existing ignores written to handle mid-message format codes Alternative: make it a setting! Requires protocol changes, new strings - would need to be after 0.14. NOTE: This impacts both the client and the core. Mismatching client/core versions will result in different behavior for ignoring messages with formatting codes inside the ignore rule itself. Example: The following message contains color codes... I love ^3IRC! ^It is the ^7best protocol ever! (Borrowed from https://modern.ircdocs.horse/formatting.html#examples ) If someone previously created a regular expression ignore rule for... "I love ...IRC" ("." is the regular expression replacement character) ...the ignore rule will need updated to remove the "..." as the formatting codes are no longer part of the match. Instead, the Message portion of the ignore rule would become... "I love IRC" --- src/common/ignorelistmanager.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/ignorelistmanager.cpp b/src/common/ignorelistmanager.cpp index d0ab71fb..028066e8 100644 --- a/src/common/ignorelistmanager.cpp +++ b/src/common/ignorelistmanager.cpp @@ -23,6 +23,8 @@ #include #include +#include "util.h" + int IgnoreListManager::indexOf(const QString& ignore) const { for (int i = 0; i < _ignoreList.count(); i++) { @@ -131,10 +133,12 @@ IgnoreListManager::StrictnessType IgnoreListManager::_match( if (item.scope() == GlobalScope || (item.scope() == NetworkScope && item.scopeRuleMatcher().match(network)) || (item.scope() == ChannelScope && item.scopeRuleMatcher().match(bufferName))) { QString str; - if (item.type() == MessageIgnore) - str = msgContents; - else + if (item.type() == MessageIgnore) { + // TODO: Make this configurable? Pre-0.14, format codes were not removed + str = stripFormatCodes(msgContents); + } else { str = msgSender; + } // qDebug() << "IgnoreListManager::match: "; // qDebug() << "string: " << str; -- 2.20.1