From cd5c373e017a7526cb319f01abb8e934976ba083 Mon Sep 17 00:00:00 2001 From: apa420 Date: Sun, 20 Jan 2019 17:03:45 +0100 Subject: [PATCH] smol commit, idk if I will continue this --- src/providers/twitch/PubsubActions.hpp | 8 ++++++++ src/providers/twitch/PubsubClient.cpp | 10 ++++++++++ src/providers/twitch/PubsubClient.hpp | 1 + src/providers/twitch/TwitchAccount.cpp | 23 +++++++++-------------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/providers/twitch/PubsubActions.hpp b/src/providers/twitch/PubsubActions.hpp index 03013ff4c..5f1dcce48 100644 --- a/src/providers/twitch/PubsubActions.hpp +++ b/src/providers/twitch/PubsubActions.hpp @@ -117,4 +117,12 @@ struct AutomodAction : PubSubAction { QString msgID; }; +struct AutomodUserAction : PubSubAction { + using PubSubAction::PubSubAction; + + ActionUser target; + + QString message; +}; + } // namespace chatterino diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index c60665882..e2ce1b9e2 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -577,40 +577,50 @@ PubSub::PubSub() this->moderationActionHandlers["denied_automod_message"] = [this](const auto &data, const auto &roomID) { // This message got denied by a moderator + AutomodUserAction action(data, roomID); + + getCreatedByUser(data, action.source); qDebug() << "test2222"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->moderationActionHandlers["add_blocked_term"] = [this](const auto &data, const auto &roomID) { // A term has been added qDebug() << "test3333"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->moderationActionHandlers["approved_automod_message"] = [this](const auto &data, const auto &roomID) { // This message got approved by a moderator qDebug() << "test5555"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->moderationActionHandlers["add_permitted_term"] = [this](const auto &data, const auto &roomID) { // This term got a pass through automod qDebug() << "test6666"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->moderationActionHandlers["modified_automod_properties"] = [this](const auto &data, const auto &roomID) { // The automod settings got modified qDebug() << "test4444"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->moderationActionHandlers["delete_blocked_term"] = [this](const auto &data, const auto &roomID) { // This term got deleted qDebug() << "test7777"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->moderationActionHandlers["delete_permitted_term"] = [this](const auto &data, const auto &roomID) { // This term got deleted qDebug() << "test8888"; + qDebug() << QString::fromStdString(rj::stringify(data)); }; this->websocketClient.set_access_channels(websocketpp::log::alevel::all); this->websocketClient.clear_access_channels( diff --git a/src/providers/twitch/PubsubClient.hpp b/src/providers/twitch/PubsubClient.hpp index 403abcaaa..9e2def087 100644 --- a/src/providers/twitch/PubsubClient.hpp +++ b/src/providers/twitch/PubsubClient.hpp @@ -114,6 +114,7 @@ public: Signal userUnbanned; Signal automodMessage; + Signal automodUserMessage; } moderation; struct { diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index afe02784b..1d798f8ce 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -419,28 +419,21 @@ void TwitchAccount::autoModAllow(const QString msgID) QString url("https://api.twitch.tv/kraken/chat/twitchbot/approve"); NetworkRequest req(url, NetworkRequestType::Post); - req.setRawHeader("Content-type", "application/json"); - /*req.setRawHeader curl - i - H 'Client-ID: abcd' - - H 'Accept: application/vnd.twitchtv.v5+json' - - H 'Authorization: OAuth efgh' - - H "Content-type: application/json" --data '{"msg_id":"msgid"}';*/ + req.setRawHeader("Content-Type", "application/json"); + auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8(); qDebug() << qba; + + req.setRawHeader("Content-Length", QByteArray::number(qba.size())); req.setPayload(qba); req.setCaller(QThread::currentThread()); req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken()); req.onError([=](int errorCode) { - qDebug() << "you just got an error 4HEad" << errorCode; + log("[TwitchAccounts::autoModAllow] Error {}", errorCode); return true; }); - req.onReplyCreated([=](QNetworkReply *reply) -> void { - // - // - return; - }); - req.execute(); } @@ -449,15 +442,17 @@ void TwitchAccount::autoModDeny(const QString msgID) QString url("https://api.twitch.tv/kraken/chat/twitchbot/deny"); NetworkRequest req(url, NetworkRequestType::Post); - req.setRawHeader("Content-type", "application/json"); + req.setRawHeader("Content-Type", "application/json"); auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8(); qDebug() << qba; + + req.setRawHeader("Content-Length", QByteArray::number(qba.size())); req.setPayload(qba); req.setCaller(QThread::currentThread()); req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken()); req.onError([=](int errorCode) { - qDebug() << "you just got an error 4HEad" << errorCode; + log("[TwitchAccounts::autoModDeny] Error {}", errorCode); return true; }); req.execute();