diff options
author | George Hazan <ghazan@miranda.im> | 2020-02-10 17:48:06 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-02-10 17:48:06 +0300 |
commit | 968c4a1f08396b1734114e589f6abd54abe2c43d (patch) | |
tree | c71dd4e8eb93a8112fb71ae6df753ef071d3dd4b /protocols/Discord | |
parent | 492705d668efe34d73093a04e9412b1cc42033c3 (diff) |
Discord: code cleaning
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/gateway.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/stdafx.h | 13 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 9 |
4 files changed, 25 insertions, 3 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index 6b5e320904..fe3bf8e800 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -259,7 +259,7 @@ void CDiscordProto::GatewaySendIdentify() void CDiscordProto::GatewaySendGuildInfo(SnowFlake id) { JSONNode payload(JSON_ARRAY); payload.set_name("d"); - payload << INT64_PARAM("", id); + payload << SINT64_PARAM("", id); JSONNode root; root << INT_PARAM("op", 12) << payload; diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 0ab49eb03c..cda830c3d5 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -409,7 +409,7 @@ int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc) // no channel - we need to create one if (pUser->channelId == 0) { - JSONNode list(JSON_ARRAY); list.set_name("recipients"); list << INT64_PARAM("", pUser->id); + JSONNode list(JSON_ARRAY); list.set_name("recipients"); list << SINT64_PARAM("", pUser->id); JSONNode body; body << list; CMStringA szUrl(FORMAT, "/users/%lld/channels", m_ownId); @@ -424,7 +424,7 @@ int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc) // we generate a random 64-bit integer and pass it to the server // to distinguish our own messages from these generated by another clients SnowFlake nonce; Utils_GetRandom(&nonce, sizeof(nonce)); nonce = abs(nonce); - JSONNode body; body << WCHAR_PARAM("content", wszText) << INT64_PARAM("nonce", nonce); + JSONNode body; body << WCHAR_PARAM("content", wszText) << SINT64_PARAM("nonce", nonce); CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId); AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, szUrl, nullptr, &body); diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 568f5db2ed..4d9ba98487 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -63,6 +63,19 @@ extern IconItem g_iconList[]; #include "version.h" #include "proto.h" +struct SINT64_PARAM : public PARAM +{ + int64_t iValue; + __forceinline SINT64_PARAM(const char *_name, int64_t _value) : + PARAM(_name), iValue(_value) + { + } +}; + +JSONNode& operator<<(JSONNode &json, const SINT64_PARAM ¶m); + +///////////////////////////////////////////////////////////////////////////////////////// + void BuildStatusList(const CDiscordGuild *pGuild, SESSION_INFO *si); SnowFlake getId(const JSONNode &pNode); diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index d2b8f701d3..0a96809354 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -32,6 +32,15 @@ int StrToStatus(const CMStringW &str) ///////////////////////////////////////////////////////////////////////////////////////// +JSONNode& operator<<(JSONNode &json, const SINT64_PARAM ¶m) +{ + char str[40]; + _i64toa(param.iValue, str, 10); + return json << CHAR_PARAM(param.szName, str); +} + +///////////////////////////////////////////////////////////////////////////////////////// + time_t StringToDate(const CMStringW &str) { struct tm T = { 0 }; |