diff --git a/src/Application.cpp b/src/Application.cpp index 6c7efabf9..2870c6ed6 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -251,6 +251,21 @@ void Application::initPubsub() }); }); + this->twitch.pubsub->signals_.moderation.automodUserMessage.connect( + [&](const auto &action) { + auto chan = + this->twitch.server->getChannelOrEmptyByID(action.roomID); + + if (chan->isEmpty()) + { + return; + } + + auto msg = MessageBuilder(action).release(); + + postToThread([chan, msg] { chan->addMessage(msg); }); + }); + this->twitch.pubsub->start(); auto RequestModerationActions = [=]() { diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 9df5fc279..9a4b1a00d 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -40,10 +40,10 @@ std::pair makeAutomodMessage( MessageColor(QColor("blue"))); builder.emplace( ("Held a message for reason: " + action.reason + - ". Allow will post it in chat."), + ". Allow will post it in chat. "), MessageElementFlag::Text, MessageColor::Text); builder - .emplace(" Allow", MessageElementFlag::Text, + .emplace("Allow", MessageElementFlag::Text, MessageColor(QColor("green")), FontStyle::ChatMediumBold) ->setLink({Link::AutoModAllow, action.msgID}); @@ -52,8 +52,9 @@ std::pair makeAutomodMessage( MessageColor(QColor("red")), FontStyle::ChatMediumBold) ->setLink({Link::AutoModDeny, action.msgID}); - builder.emplace(action.msgID, MessageElementFlag::Text, - MessageColor::Text); + // builder.emplace(action.msgID, + // MessageElementFlag::Text, + // MessageColor::Text); builder.message().flags.set(MessageFlag::AutoMod); auto message1 = builder.release(); @@ -236,6 +237,47 @@ MessageBuilder::MessageBuilder(const UnbanAction &action) this->message().searchText = text; } +MessageBuilder::MessageBuilder(const AutomodUserAction &action) + : MessageBuilder() +{ + this->emplace(); + this->message().flags.set(MessageFlag::System); + + QString text; + if (action.type == 1) + { + text = QString("%1 added %2 as a permitted term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + else if (action.type == 2) + { + text = QString("%1 added %2 as a blocked term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + else if (action.type == 3) + { + text = QString("%1 removed %2 as a permitted term term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + else if (action.type == 4) + { + text = QString("%1 removed %2 as a blocked term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + else if (action.type == 5) + { + text = QString("%1 modified the AutoMod properties.") + .arg(action.source.name); + } + + this->emplace(text, MessageElementFlag::Text, + MessageColor::System); +} + Message *MessageBuilder::operator->() { return this->message_.get(); diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index a0171cb2b..8fe7915e2 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -10,6 +10,7 @@ namespace chatterino { struct BanAction; struct UnbanAction; struct AutomodAction; +struct AutomodUserAction; struct Message; using MessagePtr = std::shared_ptr; @@ -44,6 +45,7 @@ public: bool multipleTimes); MessageBuilder(const BanAction &action, uint32_t count = 1); MessageBuilder(const UnbanAction &action); + MessageBuilder(const AutomodUserAction &action); Message *operator->(); Message &message(); diff --git a/src/providers/twitch/PubsubActions.hpp b/src/providers/twitch/PubsubActions.hpp index 5f1dcce48..6377b6d4e 100644 --- a/src/providers/twitch/PubsubActions.hpp +++ b/src/providers/twitch/PubsubActions.hpp @@ -123,6 +123,8 @@ struct AutomodUserAction : PubSubAction { ActionUser target; QString message; + + qint8 type; }; } // namespace chatterino diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index e2ce1b9e2..f5fb54255 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -528,12 +528,10 @@ PubSub::PubSub() getCreatedByUser(data, action.source); getTargetUser(data, action.target); - qDebug() << "test1111"; try { const auto &args = getArgs(data); const auto &msgID = getMsgID(data); - // qDebug() << QString::fromStdString(rj::stringify(data)); if (args.Size() < 1) { @@ -574,54 +572,144 @@ PubSub::PubSub() } }; - this->moderationActionHandlers["denied_automod_message"] = + this->moderationActionHandlers["add_permitted_term"] = [this](const auto &data, const auto &roomID) { - // This message got denied by a moderator + // This term got a pass through automod AutomodUserAction action(data, roomID); - getCreatedByUser(data, action.source); - qDebug() << "test2222"; - qDebug() << QString::fromStdString(rj::stringify(data)); + + try + { + const auto &args = getArgs(data); + action.type = 1; + + if (args.Size() < 1) + { + return; + } + + if (!rj::getSafe(args[0], action.message)) + { + return; + } + + this->signals_.moderation.automodUserMessage.invoke(action); + } + catch (const std::runtime_error &ex) + { + log("Error parsing moderation action: {}", ex.what()); + } }; 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)); + AutomodUserAction action(data, roomID); + getCreatedByUser(data, action.source); + + try + { + const auto &args = getArgs(data); + action.type = 2; + + if (args.Size() < 1) + { + return; + } + + if (!rj::getSafe(args[0], action.message)) + { + return; + } + + this->signals_.moderation.automodUserMessage.invoke(action); + } + catch (const std::runtime_error &ex) + { + log("Error parsing moderation action: {}", ex.what()); + } + }; + + this->moderationActionHandlers["delete_permitted_term"] = + [this](const auto &data, const auto &roomID) { + // This term got deleted + AutomodUserAction action(data, roomID); + getCreatedByUser(data, action.source); + + try + { + const auto &args = getArgs(data); + action.type = 3; + + if (args.Size() < 1) + { + return; + } + + if (!rj::getSafe(args[0], action.message)) + { + return; + } + + this->signals_.moderation.automodUserMessage.invoke(action); + } + catch (const std::runtime_error &ex) + { + log("Error parsing moderation action: {}", ex.what()); + } + }; + + this->moderationActionHandlers["delete_blocked_term"] = + [this](const auto &data, const auto &roomID) { + // This term got deleted + AutomodUserAction action(data, roomID); + + getCreatedByUser(data, action.source); + + try + { + const auto &args = getArgs(data); + action.type = 4; + + if (args.Size() < 1) + { + return; + } + + if (!rj::getSafe(args[0], action.message)) + { + return; + } + + this->signals_.moderation.automodUserMessage.invoke(action); + } + catch (const std::runtime_error &ex) + { + log("Error parsing moderation action: {}", ex.what()); + } + }; + + this->moderationActionHandlers["modified_automod_properties"] = + [this](const auto &data, const auto &roomID) { + // The automod settings got modified + AutomodUserAction action(data, roomID); + getCreatedByUser(data, action.source); + action.type = 5; + this->signals_.moderation.automodUserMessage.invoke(action); + }; + + this->moderationActionHandlers["denied_automod_message"] = + [this](const auto &data, const auto &roomID) { + // This message got denied by a moderator + // 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)); + // 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( websocketpp::log::alevel::frame_payload); diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 1f4aa2d88..682a976d7 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1676,6 +1676,8 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, { getApp()->accounts->twitch.getCurrent()->autoModAllow(link.value); } + break; + case Link::AutoModDeny: { getApp()->accounts->twitch.getCurrent()->autoModDeny(link.value);