From ffc1007914c3ffdc4cf322828907f35dd4101773 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 23 Jan 2017 19:07:27 +0300 Subject: Discord: now we can write messages into guild chats --- protocols/Discord/src/groupchat.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp index 1285a40245..607d6152c6 100644 --- a/protocols/Discord/src/groupchat.cpp +++ b/protocols/Discord/src/groupchat.cpp @@ -17,8 +17,41 @@ along with this program. If not, see . #include "stdafx.h" -int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM) +int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam) { + GCHOOK *gch = (GCHOOK*)lParam; + if (gch == NULL) + return 0; + + if (mir_strcmpi(gch->pDest->pszModule, m_szModuleName)) + return 0; + + CDiscordUser *pUser = FindUserByChannel(_wtoi64(gch->pDest->ptszID)); + if (pUser == NULL) + return 0; + + switch (gch->pDest->iType) { + case GC_USER_MESSAGE: + if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) { + rtrimw(gch->ptszText); + + if (m_bOnline) { + wchar_t *wszText = NEWWSTR_ALLOCA(gch->ptszText); + Chat_UnescapeTags(wszText); + + JSONNode body; body << WCHAR_PARAM("content", wszText); + CMStringA szUrl(FORMAT, "/channels/%lld/messages", pUser->channelId); + Push(new AsyncHttpRequest(this, REQUEST_POST, szUrl, &CDiscordProto::OnReceiveMessage, &body)); + } + } + break; + + case GC_USER_PRIVMESS: + case GC_USER_LOGMENU: + case GC_USER_NICKLISTMENU: + break; + } + return 0; } -- cgit v1.2.3