Fix automod messages not being parsed/showing up properly (#2742)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Unversioned
|
## Unversioned
|
||||||
|
|
||||||
|
- Bugfix: Automod messages now work properly again. (#2682)
|
||||||
- Bugfix: `Login expired` message no longer highlights all tabs. (#2735)
|
- Bugfix: `Login expired` message no longer highlights all tabs. (#2735)
|
||||||
|
|
||||||
## 2.3.1
|
## 2.3.1
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ MessageBuilder::MessageBuilder(const AutomodUserAction &action)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AutomodUserAction::RemovePermitted: {
|
case AutomodUserAction::RemovePermitted: {
|
||||||
text = QString("%1 removed %2 as a permitted term term on AutoMod.")
|
text = QString("%1 removed %2 as a permitted term on AutoMod.")
|
||||||
.arg(action.source.name)
|
.arg(action.source.name)
|
||||||
.arg(action.message);
|
.arg(action.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -583,7 +583,7 @@ PubSub::PubSub()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this->moderationActionHandlers["add_permitted_term"] =
|
this->channelTermsActionHandlers["add_permitted_term"] =
|
||||||
[this](const auto &data, const auto &roomID) {
|
[this](const auto &data, const auto &roomID) {
|
||||||
// This term got a pass through automod
|
// This term got a pass through automod
|
||||||
AutomodUserAction action(data, roomID);
|
AutomodUserAction action(data, roomID);
|
||||||
@@ -591,15 +591,13 @@ PubSub::PubSub()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto &args = getArgs(data);
|
|
||||||
action.type = AutomodUserAction::AddPermitted;
|
action.type = AutomodUserAction::AddPermitted;
|
||||||
|
if (!rj::getSafe(data, "text", action.message))
|
||||||
if (args.Size() < 1)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rj::getSafe(args[0], action.message))
|
if (!rj::getSafe(data, "requester_login", action.source.name))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -609,11 +607,11 @@ PubSub::PubSub()
|
|||||||
catch (const std::runtime_error &ex)
|
catch (const std::runtime_error &ex)
|
||||||
{
|
{
|
||||||
qCDebug(chatterinoPubsub)
|
qCDebug(chatterinoPubsub)
|
||||||
<< "Error parsing moderation action:" << ex.what();
|
<< "Error parsing channel terms action:" << ex.what();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this->moderationActionHandlers["add_blocked_term"] =
|
this->channelTermsActionHandlers["add_blocked_term"] =
|
||||||
[this](const auto &data, const auto &roomID) {
|
[this](const auto &data, const auto &roomID) {
|
||||||
// A term has been added
|
// A term has been added
|
||||||
AutomodUserAction action(data, roomID);
|
AutomodUserAction action(data, roomID);
|
||||||
@@ -621,15 +619,13 @@ PubSub::PubSub()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto &args = getArgs(data);
|
|
||||||
action.type = AutomodUserAction::AddBlocked;
|
action.type = AutomodUserAction::AddBlocked;
|
||||||
|
if (!rj::getSafe(data, "text", action.message))
|
||||||
if (args.Size() < 1)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rj::getSafe(args[0], action.message))
|
if (!rj::getSafe(data, "requester_login", action.source.name))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -639,7 +635,7 @@ PubSub::PubSub()
|
|||||||
catch (const std::runtime_error &ex)
|
catch (const std::runtime_error &ex)
|
||||||
{
|
{
|
||||||
qCDebug(chatterinoPubsub)
|
qCDebug(chatterinoPubsub)
|
||||||
<< "Error parsing moderation action:" << ex.what();
|
<< "Error parsing channel terms action:" << ex.what();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -672,6 +668,33 @@ PubSub::PubSub()
|
|||||||
<< "Error parsing moderation action:" << ex.what();
|
<< "Error parsing moderation action:" << ex.what();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this->channelTermsActionHandlers["delete_permitted_term"] =
|
||||||
|
[this](const auto &data, const auto &roomID) {
|
||||||
|
// This term got deleted
|
||||||
|
AutomodUserAction action(data, roomID);
|
||||||
|
getCreatedByUser(data, action.source);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
action.type = AutomodUserAction::RemovePermitted;
|
||||||
|
if (!rj::getSafe(data, "text", action.message))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rj::getSafe(data, "requester_login", action.source.name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->signals_.moderation.automodUserMessage.invoke(action);
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error &ex)
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoPubsub)
|
||||||
|
<< "Error parsing channel terms action:" << ex.what();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this->moderationActionHandlers["delete_blocked_term"] =
|
this->moderationActionHandlers["delete_blocked_term"] =
|
||||||
[this](const auto &data, const auto &roomID) {
|
[this](const auto &data, const auto &roomID) {
|
||||||
@@ -703,16 +726,47 @@ PubSub::PubSub()
|
|||||||
<< "Error parsing moderation action:" << ex.what();
|
<< "Error parsing moderation action:" << ex.what();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this->channelTermsActionHandlers["delete_blocked_term"] =
|
||||||
this->moderationActionHandlers["modified_automod_properties"] =
|
|
||||||
[this](const auto &data, const auto &roomID) {
|
[this](const auto &data, const auto &roomID) {
|
||||||
// The automod settings got modified
|
// This term got deleted
|
||||||
AutomodUserAction action(data, roomID);
|
AutomodUserAction action(data, roomID);
|
||||||
|
|
||||||
getCreatedByUser(data, action.source);
|
getCreatedByUser(data, action.source);
|
||||||
action.type = AutomodUserAction::Properties;
|
|
||||||
this->signals_.moderation.automodUserMessage.invoke(action);
|
try
|
||||||
|
{
|
||||||
|
action.type = AutomodUserAction::RemoveBlocked;
|
||||||
|
if (!rj::getSafe(data, "text", action.message))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rj::getSafe(data, "requester_login", action.source.name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->signals_.moderation.automodUserMessage.invoke(action);
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error &ex)
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoPubsub)
|
||||||
|
<< "Error parsing channel terms action:" << ex.what();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We don't get this one anymore or anything similiar
|
||||||
|
// We need some new topic so we can listen
|
||||||
|
//
|
||||||
|
//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 = AutomodUserAction::Properties;
|
||||||
|
// this->signals_.moderation.automodUserMessage.invoke(action);
|
||||||
|
// };
|
||||||
|
|
||||||
this->moderationActionHandlers["denied_automod_message"] = [](const auto
|
this->moderationActionHandlers["denied_automod_message"] = [](const auto
|
||||||
&data,
|
&data,
|
||||||
const auto
|
const auto
|
||||||
@@ -1059,6 +1113,7 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg)
|
|||||||
void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
||||||
{
|
{
|
||||||
QString topic;
|
QString topic;
|
||||||
|
qCDebug(chatterinoPubsub) << rj::stringify(outerData).c_str();
|
||||||
|
|
||||||
if (!rj::getSafe(outerData, "topic", topic))
|
if (!rj::getSafe(outerData, "topic", topic))
|
||||||
{
|
{
|
||||||
@@ -1122,27 +1177,63 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
|
|||||||
assert(topicParts.length() == 3);
|
assert(topicParts.length() == 3);
|
||||||
const auto &data = msg["data"];
|
const auto &data = msg["data"];
|
||||||
|
|
||||||
std::string moderationAction;
|
std::string moderationEventType;
|
||||||
|
|
||||||
if (!rj::getSafe(data, "moderation_action", moderationAction))
|
if (!rj::getSafe(msg, "type", moderationEventType))
|
||||||
{
|
{
|
||||||
qCDebug(chatterinoPubsub) << "Missing moderation action in data:"
|
qCDebug(chatterinoPubsub) << "Bad moderator event data";
|
||||||
<< rj::stringify(data).c_str();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (moderationEventType == "moderation_action")
|
||||||
auto handlerIt = this->moderationActionHandlers.find(moderationAction);
|
|
||||||
|
|
||||||
if (handlerIt == this->moderationActionHandlers.end())
|
|
||||||
{
|
{
|
||||||
qCDebug(chatterinoPubsub)
|
std::string moderationAction;
|
||||||
<< "No handler found for moderation action"
|
|
||||||
<< moderationAction.c_str();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invoke handler function
|
if (!rj::getSafe(data, "moderation_action", moderationAction))
|
||||||
handlerIt->second(data, topicParts[2]);
|
{
|
||||||
|
qCDebug(chatterinoPubsub)
|
||||||
|
<< "Missing moderation action in data:"
|
||||||
|
<< rj::stringify(data).c_str();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto handlerIt =
|
||||||
|
this->moderationActionHandlers.find(moderationAction);
|
||||||
|
|
||||||
|
if (handlerIt == this->moderationActionHandlers.end())
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoPubsub)
|
||||||
|
<< "No handler found for moderation action"
|
||||||
|
<< moderationAction.c_str();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Invoke handler function
|
||||||
|
handlerIt->second(data, topicParts[2]);
|
||||||
|
}
|
||||||
|
else if (moderationEventType == "channel_terms_action")
|
||||||
|
{
|
||||||
|
std::string channelTermsAction;
|
||||||
|
|
||||||
|
if (!rj::getSafe(data, "type", channelTermsAction))
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoPubsub)
|
||||||
|
<< "Missing channel terms action in data:"
|
||||||
|
<< rj::stringify(data).c_str();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto handlerIt =
|
||||||
|
this->channelTermsActionHandlers.find(channelTermsAction);
|
||||||
|
|
||||||
|
if (handlerIt == this->channelTermsActionHandlers.end())
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoPubsub)
|
||||||
|
<< "No handler found for channel terms action"
|
||||||
|
<< channelTermsAction.c_str();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Invoke handler function
|
||||||
|
handlerIt->second(data, topicParts[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (topic.startsWith("community-points-channel-v1."))
|
else if (topic.startsWith("community-points-channel-v1."))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -179,6 +179,10 @@ private:
|
|||||||
const QString &)>>
|
const QString &)>>
|
||||||
moderationActionHandlers;
|
moderationActionHandlers;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::function<void(const rapidjson::Value &,
|
||||||
|
const QString &)>>
|
||||||
|
channelTermsActionHandlers;
|
||||||
|
|
||||||
void onMessage(websocketpp::connection_hdl hdl, WebsocketMessagePtr msg);
|
void onMessage(websocketpp::connection_hdl hdl, WebsocketMessagePtr msg);
|
||||||
void onConnectionOpen(websocketpp::connection_hdl hdl);
|
void onConnectionOpen(websocketpp::connection_hdl hdl);
|
||||||
void onConnectionClose(websocketpp::connection_hdl hdl);
|
void onConnectionClose(websocketpp::connection_hdl hdl);
|
||||||
|
|||||||
Reference in New Issue
Block a user