From 19535676169fea739dec9b582ad1470c768faae9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 8 Feb 2017 21:59:09 +0300 Subject: Discord: support for changing nick names in chats --- protocols/Discord/src/dispatch.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'protocols/Discord/src/dispatch.cpp') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index fe581e61b9..e28f6f70d2 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -34,6 +34,7 @@ static handlers[] = // these structures must me sorted alphabetically { L"GUILD_CREATE", &CDiscordProto::OnCommandGuildCreate }, { L"GUILD_DELETE", &CDiscordProto::OnCommandGuildDelete }, { L"GUILD_MEMBER_REMOVE", &CDiscordProto::OnCommandGuildRemoveMember }, + { L"GUILD_MEMBER_UPDATE", &CDiscordProto::OnCommandGuildUpdateMember }, { L"GUILD_SYNC", &CDiscordProto::OnCommandGuildSync }, { L"MESSAGE_ACK", &CDiscordProto::OnCommandMessageAck }, @@ -260,6 +261,34 @@ void CDiscordProto::OnCommandGuildRemoveMember(const JSONNode &pRoot) } } +void CDiscordProto::OnCommandGuildUpdateMember(const JSONNode &pRoot) +{ + SnowFlake guildId = ::getId(pRoot["guild_id"]); + CMStringW wszUserId = pRoot["user"]["id"].as_mstring(); + CMStringW wszUserNick = pRoot["nick"].as_mstring(), wszOldNick; + + for (int i = 0; i < arUsers.getCount(); i++) { + CDiscordUser &pUser = arUsers[i]; + if (pUser.guildId != guildId) + continue; + + SESSION_INFO *si = pci->SM_FindSession(pUser.wszUsername, m_szModuleName); + if (si != nullptr) { + USERINFO *ui = pci->UM_FindUser(si->pUsers, wszUserId); + if (ui != nullptr) + wszOldNick = ui->pszNick; + } + + GCDEST gcd = { m_szModuleName, pUser.wszUsername, GC_EVENT_NICK }; + GCEVENT gce = { &gcd }; + gce.ptszUID = wszUserId; + gce.ptszNick = wszOldNick; + gce.ptszText = wszUserNick; + Chat_Event(&gce); + } +} + + ///////////////////////////////////////////////////////////////////////////////////////// // reading a new message -- cgit v1.2.3