Added deleted messages, will also add the disabled tag to denied automod messages

This commit is contained in:
apa420 2019-04-19 22:44:02 +02:00
parent 4cf656fe62
commit 4f79d6fc07
10 changed files with 78 additions and 1 deletions

View file

@ -264,6 +264,7 @@ void Application::initPubsub()
auto msg = MessageBuilder(action).release();
postToThread([chan, msg] { chan->addMessage(msg); });
chan->deleteMessage(msg->id);
});
this->twitch.pubsub->start();

View file

@ -212,6 +212,31 @@ void Channel::replaceMessage(MessagePtr message, MessagePtr replacement)
}
}
void Channel::deleteMessage(QString messageID)
{
LimitedQueueSnapshot<MessagePtr> snapshot = this->getMessageSnapshot();
int snapshotLength = snapshot.size();
int end = std::max(0, snapshotLength - 20);
QTime minimumTime = QTime::currentTime().addSecs(-5);
for (int i = snapshotLength - 1; i >= end; --i)
{
auto &s = snapshot[i];
if (s->parseTime < minimumTime)
{
break;
}
if (s->id == messageID)
{
s->flags.set(MessageFlag::Disabled);
break;
}
}
}
void Channel::addRecentChatter(const MessagePtr &message)
{
}

View file

@ -62,6 +62,7 @@ public:
void addOrReplaceTimeout(MessagePtr message);
void disableAllMessages();
void replaceMessage(MessagePtr message, MessagePtr replacement);
void deleteMessage(QString messageID);
QStringList modList;

View file

@ -73,6 +73,10 @@ ModerationAction::ModerationAction(const QString &action)
{
this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban);
}
else if (action.startsWith("/delete"))
{
this->image_ = Image::fromPixmap(getApp()->resources->pajaDank);
}
else
{
QString xD = action;

View file

@ -267,6 +267,41 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
}
}
void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
{
// check parameter count
if (message->parameters().length() < 1)
{
return;
}
QString chanName;
if (!trimChannelName(message->parameter(0), chanName))
{
return;
}
auto app = getApp();
// get channel
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
if (chan->isEmpty())
{
log("[IrcMessageHandler:handleClearMessageMessage] Twitch channel {} "
"not "
"found",
chanName);
return;
}
auto tags = message->tags();
QString targetID = tags.value("target-msg-id").toString();
chan->deleteMessage(targetID);
}
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
{
auto app = getApp();

View file

@ -27,6 +27,7 @@ public:
void handleRoomStateMessage(Communi::IrcMessage *message);
void handleClearChatMessage(Communi::IrcMessage *message);
void handleClearMessageMessage(Communi::IrcMessage *message);
void handleUserStateMessage(Communi::IrcMessage *message);
void handleWhisperMessage(Communi::IrcMessage *message);

View file

@ -710,6 +710,9 @@ PubSub::PubSub()
// qDebug() << QString::fromStdString(rj::stringify(data));
};
this->moderationActionHandlers["delete"] =
[this](const auto &data, const auto &roomID) { qDebug() << "xd"; };
this->websocketClient.set_access_channels(websocketpp::log::alevel::all);
this->websocketClient.clear_access_channels(
websocketpp::log::alevel::frame_payload);

View file

@ -582,6 +582,7 @@ void TwitchMessageBuilder::parseMessageID()
{
this->messageID = iterator.value().toString();
}
this->message().id = this->messageID;
}
void TwitchMessageBuilder::parseRoomID()

View file

@ -156,6 +156,10 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message)
{
handler.handleClearChatMessage(message);
}
else if (command == "CLEARMSG")
{
handler.handleClearMessageMessage(message);
}
else if (command == "USERSTATE")
{
handler.handleUserStateMessage(message);

View file

@ -1667,7 +1667,9 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
case Link::UserAction:
{
QString value = link.value;
value.replace("{user}", layout->getMessage()->loginName).replace("{channel}", this->channel_->getName());
value.replace("{user}", layout->getMessage()->loginName)
.replace("{channel}", this->channel_->getName())
.replace("{msg-id}", layout->getMessage()->id);
this->channel_->sendMessage(value);
}
break;