summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-09-21 12:27:45 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-09-21 12:27:53 +0300
commita487776816aacc4ee218e7acd481527362bfc7ff (patch)
tree268c84ff76a2048e87a8891603009b649e904c93 /protocols
parentfece278124b9e75a6a0e4f9ca9a4854b5f163d4e (diff)
Discord: attempt to gather as much information as possible
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Discord/src/dispatch.cpp57
-rw-r--r--protocols/Discord/src/guilds.cpp102
-rw-r--r--protocols/Discord/src/proto.h3
-rw-r--r--protocols/Discord/src/version.h4
4 files changed, 89 insertions, 77 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index f9d38405cf..6a9776c304 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -95,7 +95,8 @@ void CDiscordProto::OnCommandChannelCreated(const JSONNode &pRoot)
// group channel for a guild
CDiscordUser *pUser = ProcessGuildChannel(pGuild, pRoot);
if (pUser != nullptr)
- ApplyUsersToChannel(pGuild, *pUser);
+ for (int i = 0; i < pGuild->arChatUsers.getCount(); i++)
+ AddUserToChannel(*pUser, pGuild->arChatUsers[i]);
}
}
@@ -183,56 +184,8 @@ void CDiscordProto::OnCommandGuildCreated(const JSONNode &pRoot)
void CDiscordProto::OnCommandGuildSync(const JSONNode &pRoot)
{
CDiscordGuild *pGuild = FindGuild(::getId(pRoot["id"]));
- if (pGuild == nullptr)
- return;
-
- // store all guild members
- const JSONNode &pMembers = pRoot["members"];
- for (auto it = pMembers.begin(); it != pMembers.end(); ++it) {
- const JSONNode &m = *it;
-
- CMStringW wszUserId = m["user"]["id"].as_mstring();
- SnowFlake userId = _wtoi64(wszUserId);
- CDiscordGuildMember *pm = pGuild->FindUser(userId);
- if (pm == nullptr) {
- pm = new CDiscordGuildMember(userId);
- pGuild->arChatUsers.insert(pm);
- }
-
- pm->wszNick = m["nick"].as_mstring();
- if (pm->wszNick.IsEmpty())
- pm->wszNick = m["user"]["username"].as_mstring() + L"#" + m["user"]["discriminator"].as_mstring();
-
- if (userId == pGuild->ownerId)
- pm->wszRole = L"@owner";
- else {
- CDiscordRole *pRole = nullptr;
- const JSONNode &pRoles = m["roles"];
- for (auto itr = pRoles.begin(); itr != pRoles.end(); ++itr) {
- SnowFlake roleId = ::getId(*itr);
- if (pRole = pGuild->arRoles.find((CDiscordRole*)&roleId))
- break;
- }
- pm->wszRole = (pRole == nullptr) ? L"@everyone" : pRole->wszName;
- }
- pm->iStatus = ID_STATUS_OFFLINE;
- }
-
- // parse online statuses
- const JSONNode &pStatuses = pRoot["presences"];
- for (auto it = pStatuses.begin(); it != pStatuses.end(); ++it) {
- const JSONNode &s = *it;
- CDiscordGuildMember *gm = pGuild->FindUser(::getId(s["user"]["id"]));
- if (gm != nullptr)
- gm->iStatus = StrToStatus(s["status"].as_mstring());
- }
-
- // append users to all chat rooms
- for (int i = 0; i < arUsers.getCount(); i++) {
- CDiscordUser &pUser = arUsers[i];
- if (pUser.guildId == pGuild->id)
- ApplyUsersToChannel(pGuild, pUser);
- }
+ if (pGuild != nullptr)
+ ParseGuildContents(pGuild, pRoot);
}
void CDiscordProto::OnCommandGuildDeleted(const JSONNode &pRoot)
@@ -425,6 +378,8 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
gce.time = (DWORD)StringToDate(pRoot["timestamp"].as_mstring());
gce.bIsMe = msg.authorId == m_ownId;
Chat_Event(&gce);
+
+ debugLogW(L"New channel %s message from %s: %s", si->ptszID, gce.ptszUID, gce.ptszText);
}
}
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp
index dcc19ad354..98f5d3dcaa 100644
--- a/protocols/Discord/src/guilds.cpp
+++ b/protocols/Discord/src/guilds.cpp
@@ -94,14 +94,16 @@ void CDiscordProto::ProcessGuild(const JSONNode &p)
CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JSONNode &pch)
{
+ CMStringW wszChannelId = pch["id"].as_mstring();
+ SnowFlake channelId = _wtoi64(wszChannelId);
+ CMStringW wszChannelName = pGuild->wszName + L"#" + pch["name"].as_mstring();
+
// filter our all channels but the text ones
- if (pch["type"].as_int() != 0)
+ if (pch["type"].as_int() != 0) {
return nullptr;
+ }
- CMStringW wszChannelName = pGuild->wszName + L"#" + pch["name"].as_mstring();
- CMStringW wszChannelId = pch["id"].as_mstring();
CMStringW wszTopic = pch["topic"].as_mstring();
- SnowFlake channelId = _wtoi64(wszChannelId);
GCSessionInfoBase *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszChannelId, wszChannelName);
BuildStatusList(pGuild, wszChannelId);
@@ -144,32 +146,86 @@ CDiscordUser* CDiscordProto::ProcessGuildChannel(CDiscordGuild *pGuild, const JS
/////////////////////////////////////////////////////////////////////////////////////////
-void CDiscordProto::ApplyUsersToChannel(CDiscordGuild *pGuild, const CDiscordUser &pUser)
+void CDiscordProto::AddUserToChannel(const CDiscordUser &pChannel, const CDiscordGuildMember &pUser)
{
- GCEVENT gce = { m_szModuleName, pUser.wszUsername, GC_EVENT_JOIN };
+ GCEVENT gce = { m_szModuleName, pChannel.wszUsername, GC_EVENT_JOIN };
gce.time = time(0);
gce.dwFlags = GCEF_SILENT;
- for (int i = 0; i < pGuild->arChatUsers.getCount(); i++) {
- CDiscordGuildMember &m = pGuild->arChatUsers[i];
+ wchar_t wszUserId[100];
+ _i64tow_s(pUser.userId, wszUserId, _countof(wszUserId), 10);
+
+ gce.ptszStatus = pUser.wszRole;
+ gce.bIsMe = (pUser.userId == m_ownId);
+ gce.ptszUID = wszUserId;
+ gce.ptszNick = pUser.wszNick;
+ Chat_Event(&gce);
+
+ int flags = GC_SSE_ONLYLISTED;
+ switch (pUser.iStatus) {
+ case ID_STATUS_ONLINE: case ID_STATUS_NA: case ID_STATUS_DND:
+ flags += GC_SSE_ONLINE;
+ break;
+ default:
+ flags += GC_SSE_OFFLINE;
+ }
+ Chat_SetStatusEx(m_szModuleName, pChannel.wszUsername, flags, wszUserId);
+}
- wchar_t wszUserId[100];
- _i64tow_s(m.userId, wszUserId, _countof(wszUserId), 10);
+/////////////////////////////////////////////////////////////////////////////////////////
- gce.ptszStatus = m.wszRole;
- gce.bIsMe = (m.userId == m_ownId);
- gce.ptszUID = wszUserId;
- gce.ptszNick = m.wszNick;
- Chat_Event(&gce);
+void CDiscordProto::ParseGuildContents(CDiscordGuild *pGuild, const JSONNode &pRoot)
+{
+ LIST<CDiscordGuildMember> newMembers(10);
+
+ // store all guild members
+ const JSONNode &pMembers = pRoot["members"];
+ for (auto it = pMembers.begin(); it != pMembers.end(); ++it) {
+ const JSONNode &m = *it;
+
+ CMStringW wszUserId = m["user"]["id"].as_mstring();
+ SnowFlake userId = _wtoi64(wszUserId);
+ CDiscordGuildMember *pm = pGuild->FindUser(userId);
+ if (pm == nullptr) {
+ pm = new CDiscordGuildMember(userId);
+ pGuild->arChatUsers.insert(pm);
+ newMembers.insert(pm);
+ }
+
+ pm->wszNick = m["nick"].as_mstring();
+ if (pm->wszNick.IsEmpty())
+ pm->wszNick = m["user"]["username"].as_mstring() + L"#" + m["user"]["discriminator"].as_mstring();
+
+ if (userId == pGuild->ownerId)
+ pm->wszRole = L"@owner";
+ else {
+ CDiscordRole *pRole = nullptr;
+ const JSONNode &pRoles = m["roles"];
+ for (auto itr = pRoles.begin(); itr != pRoles.end(); ++itr) {
+ SnowFlake roleId = ::getId(*itr);
+ if (pRole = pGuild->arRoles.find((CDiscordRole*)&roleId))
+ break;
+ }
+ pm->wszRole = (pRole == nullptr) ? L"@everyone" : pRole->wszName;
+ }
+ pm->iStatus = ID_STATUS_OFFLINE;
+ }
+
+ // parse online statuses
+ const JSONNode &pStatuses = pRoot["presences"];
+ for (auto it = pStatuses.begin(); it != pStatuses.end(); ++it) {
+ const JSONNode &s = *it;
+ CDiscordGuildMember *gm = pGuild->FindUser(::getId(s["user"]["id"]));
+ if (gm != nullptr)
+ gm->iStatus = StrToStatus(s["status"].as_mstring());
+ }
- int flags = GC_SSE_ONLYLISTED;
- switch (m.iStatus) {
- case ID_STATUS_ONLINE: case ID_STATUS_NA: case ID_STATUS_DND:
- flags += GC_SSE_ONLINE;
- break;
- default:
- flags += GC_SSE_OFFLINE;
+ for (int k = 0; k < newMembers.getCount(); k++) {
+ CDiscordGuildMember *pm = newMembers[k];
+ for (int i = 0; i < arUsers.getCount(); i++) {
+ CDiscordUser &pUser = arUsers[i];
+ if (pUser.guildId == pGuild->id)
+ AddUserToChannel(pUser, *pm);
}
- Chat_SetStatusEx(m_szModuleName, pUser.wszUsername, flags, wszUserId);
}
}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 3b11a71f2e..1dd1b733b7 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -270,7 +270,8 @@ class CDiscordProto : public PROTO<CDiscordProto>
}
void ProcessGuild(const JSONNode&);
- void ApplyUsersToChannel(CDiscordGuild *guild, const CDiscordUser&);
+ void AddUserToChannel(const CDiscordUser &pChannel, const CDiscordGuildMember &pUser);
+ void ParseGuildContents(CDiscordGuild *guild, const JSONNode &);
CDiscordUser* ProcessGuildChannel(CDiscordGuild *guild, const JSONNode&);
void ProcessRole(CDiscordGuild *guild, const JSONNode&);
void ProcessType(CDiscordUser *pUser, const JSONNode&);
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index 150d7b25f8..a7660661d8 100644
--- a/protocols/Discord/src/version.h
+++ b/protocols/Discord/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 5
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 3
+#define __RELEASE_NUM 1
+#define __BUILD_NUM 1
#include <stdver.h>