summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Discord/src/dispatch.cpp8
-rw-r--r--protocols/Discord/src/proto.h1
-rw-r--r--protocols/Discord/src/utils.cpp26
3 files changed, 35 insertions, 0 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 1f4f9b3993..0da160b973 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -370,6 +370,14 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
else {
debugLogA("store a message into the group channel id %lld", channelId);
+ SESSION_INFO *si = pci->SM_FindSession(wszChannelId, m_szModuleName);
+ if (si == NULL) {
+ debugLogA("nessage to unknown channal %lld ignored", channelId);
+ return;
+ }
+
+ ParseSpecialChars(si, wszText);
+
GCDEST gcd = { m_szModuleName, wszChannelId, GC_EVENT_MESSAGE };
GCEVENT gce = { &gcd };
gce.dwFlags = GCEF_ADDTOLOG;
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 29c0319719..133ff1f40c 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -206,6 +206,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void Chat_SendPrivateMessage(GCHOOK *gch);
void Chat_ProcessLogMenu(GCHOOK *gch);
+ void ParseSpecialChars(SESSION_INFO *si, CMStringW &str);
//////////////////////////////////////////////////////////////////////////////////////
// misc methods
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index f84ecfb61a..b1390a9ec0 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -268,3 +268,29 @@ void CDiscordProto::ProcessType(CDiscordUser *pUser, const JSONNode &pRoot)
break;
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDiscordProto::ParseSpecialChars(SESSION_INFO *si, CMStringW &str)
+{
+ for (int i = 0; (i = str.Find('<', i)) != -1; i++) {
+ int iEnd = str.Find('>', i + 1);
+ if (iEnd == -1)
+ return;
+
+ CMStringW wszWord = str.Mid(i + 1, iEnd - i - 1);
+ if (wszWord[0] == '@' && wszWord[1] == '!') { // member highlight
+ USERINFO *ui = pci->UM_FindUser(si->pUsers, wszWord.c_str()+2);
+ if (ui != nullptr)
+ str.Replace(L"<" + wszWord + L">", CMStringW('@') + ui->pszNick);
+ }
+ else if (wszWord[0] == '#') {
+ CDiscordUser *pUser = FindUserByChannel(_wtoi64(wszWord.c_str() + 1));
+ if (pUser != nullptr) {
+ ptrW wszNick(getWStringA(pUser->hContact, "Nick"));
+ if (wszNick != NULL)
+ str.Replace(L"<" + wszWord + L">", wszNick);
+ }
+ }
+ }
+}