From 2651148625bef56f1fe32c638259d20abb001d68 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 12 Feb 2017 21:04:03 +0300 Subject: support for Discord message markup --- protocols/Discord/src/utils.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'protocols/Discord/src/utils.cpp') 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); + } + } + } +} -- cgit v1.2.3