Created
November 10, 2018 20:44
-
-
Save oprypin/5c15d5bbde635196a66e340279423082 to your computer and use it in GitHub Desktop.
Patches to integrate bridge bot messages (FromGitter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --unified --recursive konversation-1.7.2/src/viewer/chatwindow.cpp konversation-1.7.2.new/src/viewer/chatwindow.cpp | |
--- konversation-1.7.2/src/viewer/chatwindow.cpp 2017-05-09 17:29:00.000000000 +0200 | |
+++ konversation-1.7.2.new/src/viewer/chatwindow.cpp 2017-11-07 00:13:25.359449297 +0100 | |
@@ -278,7 +278,15 @@ | |
void ChatWindow::append(const QString& nickname, const QString& message, const QHash<QString, QString> &messageTags, const QString& label) | |
{ | |
if(!textView) return; | |
- textView->append(nickname, message, messageTags, label); | |
+ QString nickname_ = nickname; | |
+ QString message_ = message; | |
+ QRegExp boldNickname("^\x02?<([^>]+)>\x0f? (.*)$"); | |
+ if(nickname == "FromGitter" && boldNickname.indexIn(message) != -1) | |
+ { | |
+ nickname_ = "@" + boldNickname.capturedTexts()[1]; | |
+ message_ = boldNickname.capturedTexts()[2]; | |
+ } | |
+ textView->append(nickname_, message_, messageTags, label); | |
} | |
void ChatWindow::appendQuery(const QString& nickname, const QString& message, const QHash<QString, QString> &messageTags, bool inChannel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit a13c0ee83df6610ccfeee282ede7157b601049e3 | |
Author: Oleh Prypin <[email protected]> | |
Date: Sat Nov 10 21:40:41 2018 +0100 | |
Substitute nickname in messages sent by FromGitter (bridge bot) | |
Replace 'FromGitter' '<SomePerson> Some message.' | |
with '@SomePerson' 'Some message.' | |
diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp | |
index c38c3d6bc..d859ab8bf 100644 | |
--- a/src/core/coresession.cpp | |
+++ b/src/core/coresession.cpp | |
@@ -330,6 +330,11 @@ void CoreSession::recvMessageFromServer(NetworkId networkId, Message::Type type, | |
if (_ignoreListManager.match(rawMsg, networkName) == IgnoreListManager::HardStrictness) | |
return; | |
+ QRegExp msgWithNickname("^\x02?<([^>]+)>\x0f? (.*)$"); | |
+ if (rawMsg.sender == "[email protected]" && msgWithNickname.indexIn(rawMsg.text) != -1) { | |
+ rawMsg.sender = "@" + msgWithNickname.capturedTexts()[1] + "[email protected]"; | |
+ rawMsg.text = msgWithNickname.capturedTexts()[2]; | |
+ } | |
if (currentNetwork && _highlightRuleManager.match(rawMsg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks())) | |
rawMsg.flags |= Message::Flag::Highlight; | |
@@ -386,6 +391,7 @@ void CoreSession::processMessages() | |
Q_ASSERT(!createBuffer); | |
bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, BufferInfo::StatusBuffer, ""); | |
} | |
+ captureGitterUser(rawMsg, bufferInfo); | |
Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, senderPrefixes(rawMsg.sender, bufferInfo), | |
realName(rawMsg.sender, rawMsg.networkId), avatarUrl(rawMsg.sender, rawMsg.networkId), | |
rawMsg.flags); | |
@@ -412,6 +418,7 @@ void CoreSession::processMessages() | |
} | |
bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo; | |
} | |
+ captureGitterUser(rawMsg, bufferInfo); | |
Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, senderPrefixes(rawMsg.sender, bufferInfo), | |
realName(rawMsg.sender, rawMsg.networkId), avatarUrl(rawMsg.sender, rawMsg.networkId), | |
rawMsg.flags); | |
@@ -430,6 +437,7 @@ void CoreSession::processMessages() | |
// add the StatusBuffer to the Cache in case there are more Messages for the original target | |
bufferInfoCache[rawMsg.networkId][rawMsg.target] = bufferInfo; | |
} | |
+ captureGitterUser(rawMsg, bufferInfo); | |
Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, senderPrefixes(rawMsg.sender, bufferInfo), | |
realName(rawMsg.sender, rawMsg.networkId), avatarUrl(rawMsg.sender, rawMsg.networkId), | |
rawMsg.flags); | |
@@ -447,6 +455,19 @@ void CoreSession::processMessages() | |
_messageQueue.clear(); | |
} | |
+void CoreSession::captureGitterUser(const RawMessage &rawMsg, const BufferInfo &bufferInfo) | |
+{ | |
+ if (rawMsg.sender.startsWith("@") && rawMsg.sender.endsWith("[email protected]")) { | |
+ CoreNetwork *currentNetwork = network(bufferInfo.networkId()); | |
+ if (currentNetwork) { | |
+ IrcChannel *currentChannel = currentNetwork->ircChannel(bufferInfo.bufferName()); | |
+ if (currentChannel) { | |
+ currentChannel->joinIrcUsers({rawMsg.sender.mid(1)}, {""}); | |
+ } | |
+ } | |
+ } | |
+} | |
+ | |
QString CoreSession::senderPrefixes(const QString &sender, const BufferInfo &bufferInfo) const | |
{ | |
CoreNetwork *currentNetwork = network(bufferInfo.networkId()); | |
diff --git a/src/core/coresession.h b/src/core/coresession.h | |
index b4903ff43..58b591a5c 100644 | |
--- a/src/core/coresession.h | |
+++ b/src/core/coresession.h | |
@@ -254,6 +254,8 @@ private: | |
QScriptEngine *scriptEngine; | |
+ void captureGitterUser(const RawMessage &rawMsg, const BufferInfo &bufferInfo); | |
+ | |
/** | |
* This method obtains the prefixes of the message's sender within a channel, by looking up their channelmodes, and | |
* processing them to prefixes based on the network's settings. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment