diff options
author | George Hazan <george.hazan@gmail.com> | 2024-05-02 21:15:12 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-05-02 21:15:12 +0300 |
commit | b9d42763699f1c60f2ea0c3187378df1b2131e75 (patch) | |
tree | 1845cc342e021053baa9d0c1aae80c947ac06623 /protocols | |
parent | 7800bc4031eec1be0ac77320e4ab933e2f34b196 (diff) |
Discord: no need to include zero discriminator into nicks
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Discord/src/dispatch.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/guilds.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/stdafx.h | 1 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 11 |
5 files changed, 16 insertions, 6 deletions
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());
|