mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Implemented AutoMod and write pubsub automod messages TODO: implement that the AutoMod message gets deleted if dealt with \nFixes #887
This commit is contained in:
parent
cd5c373e01
commit
1434225603
6 changed files with 190 additions and 39 deletions
|
@ -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 = [=]() {
|
||||
|
|
|
@ -52,8 +52,9 @@ std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
|
|||
MessageColor(QColor("red")),
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::AutoModDeny, action.msgID});
|
||||
builder.emplace<TextElement>(action.msgID, MessageElementFlag::Text,
|
||||
MessageColor::Text);
|
||||
// builder.emplace<TextElement>(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<TimestampElement>();
|
||||
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<TextElement>(text, MessageElementFlag::Text,
|
||||
MessageColor::System);
|
||||
}
|
||||
|
||||
Message *MessageBuilder::operator->()
|
||||
{
|
||||
return this->message_.get();
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace chatterino {
|
|||
struct BanAction;
|
||||
struct UnbanAction;
|
||||
struct AutomodAction;
|
||||
struct AutomodUserAction;
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -123,6 +123,8 @@ struct AutomodUserAction : PubSubAction {
|
|||
ActionUser target;
|
||||
|
||||
QString message;
|
||||
|
||||
qint8 type;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue