From b9d42763699f1c60f2ea0c3187378df1b2131e75 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 2 May 2024 21:15:12 +0300 Subject: Discord: no need to include zero discriminator into nicks --- protocols/Discord/src/dispatch.cpp | 2 +- protocols/Discord/src/guilds.cpp | 4 ++-- protocols/Discord/src/proto.cpp | 4 +--- protocols/Discord/src/stdafx.h | 1 + protocols/Discord/src/utils.cpp | 11 +++++++++++ 5 files changed, 16 insertions(+), 6 deletions(-) (limited to 'protocols/Discord') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index d24d0ab60e..995efac43a 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -289,7 +289,7 @@ void CDiscordProto::OnCommandGuildMemberUpdated(const JSONNode &pRoot) if (gm == nullptr) return; - gm->wszDiscordId = pRoot["user"]["username"].as_mstring() + L"#" + pRoot["user"]["discriminator"].as_mstring(); + gm->wszDiscordId = getNick(pRoot["user"]); gm->wszNick = pRoot["nick"].as_mstring(); if (gm->wszNick.IsEmpty()) gm->wszNick = pRoot["user"]["username"].as_mstring(); diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index b149059972..bf8336be1b 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -250,7 +250,7 @@ CDiscordGuildMember* CDiscordProto::ProcessGuildUser(CDiscordGuild *pGuild, cons bNew = true; } - pm->wszDiscordId = pUser["username"].as_mstring() + L"#" + pUser["discriminator"].as_mstring(); + pm->wszDiscordId = getNick(pUser); pm->wszNick = pRoot["nick"].as_mstring(); if (pm->wszNick.IsEmpty()) pm->wszNick = pUser["username"].as_mstring(); @@ -301,7 +301,7 @@ void CDiscordProto::ProcessChatUser(CDiscordUser *pChat, SnowFlake userId, const // otherwise let's create a user and insert him into all guild's chats pm = new CDiscordGuildMember(userId); - pm->wszDiscordId = pRoot["author"]["username"].as_mstring() + L"#" + pRoot["author"]["discriminator"].as_mstring(); + pm->wszDiscordId = getNick(pRoot["author"]); pm->wszNick = pRoot["nick"].as_mstring(); if (pm->wszNick.IsEmpty()) pm->wszNick = pRoot["author"]["username"].as_mstring(); diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 19db84f38a..c4ac40a83d 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -338,9 +338,7 @@ void CDiscordProto::OnReceiveUserinfo(MHttpResponse *pReply, AsyncHttpRequest*) return; } - auto &data = root.data(); - CMStringW wszUserId(data["username"].as_mstring() + L"#" + data["discriminator"].as_mstring()); - ForkThread(&CDiscordProto::SearchThread, wszUserId.Detach()); + ForkThread(&CDiscordProto::SearchThread, getNick(root.data()).Detach()); } HANDLE CDiscordProto::SearchBasic(const wchar_t *wszId) diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 3b3bbc819a..1c137e42fa 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -76,6 +76,7 @@ void BuildStatusList(const CDiscordGuild *pGuild, SESSION_INFO *si); void CopyId(const CMStringW &nick); SnowFlake getId(const JSONNode &pNode); +CMStringW getNick(const JSONNode &pNode); CMStringW PrepareMessageText(const JSONNode &pRoot); int StrToStatus(const CMStringW &str); time_t StringToDate(const CMStringW &str); diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index dcd94ebe71..b703fc63bb 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -59,6 +59,17 @@ int SerialNext() ///////////////////////////////////////////////////////////////////////////////////////// +CMStringW getNick(const JSONNode &pNode) +{ + CMStringW name = pNode["username"].as_mstring(), discriminator = pNode["discriminator"].as_mstring(); + if (discriminator == L"0") + return name; + + return name + L"#" + discriminator; +} + +///////////////////////////////////////////////////////////////////////////////////////// + SnowFlake getId(const JSONNode &pNode) { return _wtoi64(pNode.as_mstring()); -- cgit v1.2.3