Add remaining pubsub messages to chat

This commit is contained in:
Rasmus Karlsson 2018-04-29 13:24:37 +02:00
parent d05a59ef51
commit e31dc09e91
4 changed files with 93 additions and 12 deletions

View file

@ -114,18 +114,54 @@ void Application::initialize()
debug::Log("WHISPER RECEIVED LOL"); // debug::Log("WHISPER RECEIVED LOL"); //
}); });
this->twitch.pubsub->sig.moderation.chatCleared.connect([&](const auto &action) { this->twitch.pubsub->sig.moderation.chatCleared.connect([this](const auto &action) {
debug::Log("Chat cleared by {}", action.source.name); // auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
if (chan->isEmpty()) {
return;
}
QString text = QString("%1 cleared the chat").arg(action.source.name);
auto msg = messages::Message::createSystemMessage(text);
util::postToThread([chan, msg] { chan->addMessage(msg); });
}); });
this->twitch.pubsub->sig.moderation.modeChanged.connect([&](const auto &action) { this->twitch.pubsub->sig.moderation.modeChanged.connect([this](const auto &action) {
debug::Log("Mode {} was turned {} by {} (duration {})", (int &)action.mode, auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
(bool &)action.state, action.source.name, action.args.duration); if (chan->isEmpty()) {
return;
}
QString text =
QString("%1 turned %2 %3 mode") //
.arg(action.source.name)
.arg(action.state == providers::twitch::ModeChangedAction::State::On ? "on" : "off")
.arg(action.getModeName());
if (action.duration > 0) {
text.append(" (" + QString::number(action.duration) + " seconds)");
}
auto msg = messages::Message::createSystemMessage(text);
util::postToThread([chan, msg] { chan->addMessage(msg); });
}); });
this->twitch.pubsub->sig.moderation.moderationStateChanged.connect([&](const auto &action) { this->twitch.pubsub->sig.moderation.moderationStateChanged.connect([this](const auto &action) {
debug::Log("User {} was {} by {}", action.target.id, action.modded ? "modded" : "unmodded", auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
action.source.name); if (chan->isEmpty()) {
return;
}
QString text;
if (action.modded) {
text = QString("%1 modded %2").arg(action.source.name, action.target.name);
} else {
text = QString("%1 unmodded %2").arg(action.source.name, action.target.name);
}
auto msg = messages::Message::createSystemMessage(text);
util::postToThread([chan, msg] { chan->addMessage(msg); });
}); });
this->twitch.pubsub->sig.moderation.userBanned.connect([&](const auto &action) { this->twitch.pubsub->sig.moderation.userBanned.connect([&](const auto &action) {

View file

@ -212,6 +212,7 @@ void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
{ {
return;
auto app = getApp(); auto app = getApp();
MessagePtr msg = Message::createSystemMessage(message->content()); MessagePtr msg = Message::createSystemMessage(message->content());

View file

@ -226,7 +226,7 @@ PubSub::PubSub()
bool ok; bool ok;
action.args.duration = QString(durationArg.GetString()).toUInt(&ok, 10); action.duration = QString(durationArg.GetString()).toUInt(&ok, 10);
this->sig.moderation.modeChanged.invoke(action); this->sig.moderation.modeChanged.invoke(action);
}; };
@ -290,6 +290,21 @@ PubSub::PubSub()
ModerationStateAction action(data, roomID); ModerationStateAction action(data, roomID);
getTargetUser(data, action.target); getTargetUser(data, action.target);
try {
const auto &args = getArgs(data);
if (args.Size() < 1) {
return;
}
if (!rj::getSafe(args[0], action.target.name)) {
return;
}
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
}
action.modded = false; action.modded = false;
this->sig.moderation.moderationStateChanged.invoke(action); this->sig.moderation.moderationStateChanged.invoke(action);
@ -299,6 +314,21 @@ PubSub::PubSub()
ModerationStateAction action(data, roomID); ModerationStateAction action(data, roomID);
getTargetUser(data, action.target); getTargetUser(data, action.target);
try {
const auto &args = getArgs(data);
if (args.Size() < 1) {
return;
}
if (!rj::getSafe(args[0], action.target.name)) {
return;
}
} catch (const std::runtime_error &ex) {
debug::Log("Error parsing moderation action: {}", ex.what());
}
action.modded = true; action.modded = true;
this->sig.moderation.moderationStateChanged.invoke(action); this->sig.moderation.moderationStateChanged.invoke(action);

View file

@ -41,9 +41,23 @@ struct ModeChangedAction : PubSubAction {
On, On,
} state; } state;
union { uint32_t duration = 0;
uint32_t duration;
} args; const char *getModeName() const
{
switch (this->mode) {
case Mode::Slow:
return "slow";
case Mode::R9K:
return "r9k";
case Mode::SubscribersOnly:
return "subscribers-only";
case Mode::EmoteOnly:
return "emote-only";
default:
return "unknown";
}
}
}; };
struct BanAction : PubSubAction { struct BanAction : PubSubAction {