2018-06-26 14:09:39 +02:00
|
|
|
#include "MessageBuilder.hpp"
|
2018-06-28 00:24:21 +02:00
|
|
|
|
2019-01-20 14:45:59 +01:00
|
|
|
#include "Application.hpp"
|
2018-06-28 00:24:21 +02:00
|
|
|
#include "common/LinkParser.hpp"
|
2020-04-13 12:31:06 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2019-01-20 14:45:59 +01:00
|
|
|
#include "messages/Image.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "messages/MessageElement.hpp"
|
2019-03-13 15:26:55 +01:00
|
|
|
#include "providers/LinkResolver.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "providers/twitch/PubsubActions.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-08-07 01:35:24 +02:00
|
|
|
#include "util/FormatTime.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-12-27 01:22:12 +01:00
|
|
|
#include <QDateTime>
|
2019-01-20 14:45:59 +01:00
|
|
|
#include <QImageReader>
|
2017-12-27 01:22:12 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
MessagePtr makeSystemMessage(const QString &text)
|
|
|
|
{
|
|
|
|
return MessageBuilder(systemMessage, text).release();
|
|
|
|
}
|
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
MessagePtr makeSystemMessage(const QString &text, const QTime &time)
|
|
|
|
{
|
|
|
|
return MessageBuilder(systemMessage, text, time).release();
|
|
|
|
}
|
|
|
|
|
2022-01-14 02:44:13 +01:00
|
|
|
EmotePtr makeAutoModBadge()
|
|
|
|
{
|
|
|
|
return std::make_shared<Emote>(Emote{
|
|
|
|
EmoteName{}, ImageSet{Image::fromPixmap(getResources().twitch.automod)},
|
|
|
|
Tooltip{"AutoMod"},
|
|
|
|
Url{"https://dashboard.twitch.tv/settings/moderation/automod"}});
|
|
|
|
}
|
|
|
|
|
2021-05-08 14:49:30 +02:00
|
|
|
MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action)
|
|
|
|
{
|
|
|
|
auto builder = MessageBuilder();
|
2021-07-11 12:19:35 +02:00
|
|
|
QString text("AutoMod: ");
|
2021-05-08 14:49:30 +02:00
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.message().flags.set(MessageFlag::PubSub);
|
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
// AutoMod shield badge
|
2022-01-14 02:44:13 +01:00
|
|
|
builder.emplace<BadgeElement>(makeAutoModBadge(),
|
|
|
|
MessageElementFlag::BadgeChannelAuthority);
|
2021-07-11 12:19:35 +02:00
|
|
|
// AutoMod "username"
|
2021-05-08 14:49:30 +02:00
|
|
|
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::BoldUsername,
|
|
|
|
MessageColor(QColor("blue")),
|
|
|
|
FontStyle::ChatMediumBold);
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
"AutoMod:", MessageElementFlag::NonBoldUsername,
|
|
|
|
MessageColor(QColor("blue")));
|
|
|
|
switch (action.type)
|
|
|
|
{
|
|
|
|
case AutomodInfoAction::OnHold: {
|
2021-07-11 12:19:35 +02:00
|
|
|
QString info("Hey! Your message is being checked "
|
|
|
|
"by mods and has not been sent.");
|
|
|
|
text += info;
|
|
|
|
builder.emplace<TextElement>(info, MessageElementFlag::Text,
|
2021-05-08 14:49:30 +02:00
|
|
|
MessageColor::Text);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AutomodInfoAction::Denied: {
|
2021-07-11 12:19:35 +02:00
|
|
|
QString info("Mods have removed your message.");
|
|
|
|
text += info;
|
|
|
|
builder.emplace<TextElement>(info, MessageElementFlag::Text,
|
2021-05-08 14:49:30 +02:00
|
|
|
MessageColor::Text);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AutomodInfoAction::Approved: {
|
2021-07-11 12:19:35 +02:00
|
|
|
QString info("Mods have accepted your message.");
|
|
|
|
text += info;
|
|
|
|
builder.emplace<TextElement>(info, MessageElementFlag::Text,
|
2021-05-08 14:49:30 +02:00
|
|
|
MessageColor::Text);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.message().flags.set(MessageFlag::AutoMod);
|
2021-07-11 12:19:35 +02:00
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
2021-05-08 14:49:30 +02:00
|
|
|
|
|
|
|
auto message = builder.release();
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2019-01-20 01:02:04 +01:00
|
|
|
std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
|
|
|
|
const AutomodAction &action)
|
|
|
|
{
|
2021-07-11 12:19:35 +02:00
|
|
|
MessageBuilder builder, builder2;
|
2019-01-20 01:02:04 +01:00
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
//
|
|
|
|
// Builder for AutoMod message with explanation
|
|
|
|
builder.message().loginName = "automod";
|
2019-01-20 01:02:04 +01:00
|
|
|
builder.message().flags.set(MessageFlag::PubSub);
|
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
// AutoMod shield badge
|
2022-01-14 02:44:13 +01:00
|
|
|
builder.emplace<BadgeElement>(makeAutoModBadge(),
|
|
|
|
MessageElementFlag::BadgeChannelAuthority);
|
2021-07-11 12:19:35 +02:00
|
|
|
// AutoMod "username"
|
2019-01-25 14:19:09 +01:00
|
|
|
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::BoldUsername,
|
|
|
|
MessageColor(QColor("blue")),
|
|
|
|
FontStyle::ChatMediumBold);
|
2019-01-20 01:02:04 +01:00
|
|
|
builder.emplace<TextElement>(
|
|
|
|
"AutoMod:", MessageElementFlag::NonBoldUsername,
|
2019-01-20 14:45:59 +01:00
|
|
|
MessageColor(QColor("blue")));
|
2021-07-11 12:19:35 +02:00
|
|
|
// AutoMod header message
|
2019-01-20 01:02:04 +01:00
|
|
|
builder.emplace<TextElement>(
|
|
|
|
("Held a message for reason: " + action.reason +
|
2019-01-21 18:33:57 +01:00
|
|
|
". Allow will post it in chat. "),
|
2019-01-20 01:02:04 +01:00
|
|
|
MessageElementFlag::Text, MessageColor::Text);
|
2021-07-11 12:19:35 +02:00
|
|
|
// Allow link button
|
2019-01-20 14:45:59 +01:00
|
|
|
builder
|
2019-01-21 18:33:57 +01:00
|
|
|
.emplace<TextElement>("Allow", MessageElementFlag::Text,
|
2019-01-20 14:45:59 +01:00
|
|
|
MessageColor(QColor("green")),
|
|
|
|
FontStyle::ChatMediumBold)
|
|
|
|
->setLink({Link::AutoModAllow, action.msgID});
|
2021-07-11 12:19:35 +02:00
|
|
|
// Deny link button
|
2019-01-20 14:45:59 +01:00
|
|
|
builder
|
|
|
|
.emplace<TextElement>(" Deny", MessageElementFlag::Text,
|
|
|
|
MessageColor(QColor("red")),
|
|
|
|
FontStyle::ChatMediumBold)
|
|
|
|
->setLink({Link::AutoModDeny, action.msgID});
|
2021-07-11 12:19:35 +02:00
|
|
|
// ID of message caught by AutoMod
|
|
|
|
// builder.emplace<TextElement>(action.msgID, MessageElementFlag::Text,
|
|
|
|
// MessageColor::Text);
|
2019-01-20 01:02:04 +01:00
|
|
|
builder.message().flags.set(MessageFlag::AutoMod);
|
2021-07-11 12:19:35 +02:00
|
|
|
auto text1 =
|
|
|
|
QString("AutoMod: Held a message for reason: %1. Allow will post "
|
|
|
|
"it in chat. Allow Deny")
|
|
|
|
.arg(action.reason);
|
|
|
|
builder.message().messageText = text1;
|
|
|
|
builder.message().searchText = text1;
|
2019-01-20 01:02:04 +01:00
|
|
|
|
|
|
|
auto message1 = builder.release();
|
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
//
|
|
|
|
// Builder for offender's message
|
|
|
|
builder2.emplace<TimestampElement>();
|
|
|
|
builder2.emplace<TwitchModerationElement>();
|
2021-07-11 13:33:35 +02:00
|
|
|
builder2.message().loginName = action.target.login;
|
2021-07-11 12:19:35 +02:00
|
|
|
builder2.message().flags.set(MessageFlag::PubSub);
|
2019-01-20 01:02:04 +01:00
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
// sender username
|
|
|
|
builder2
|
2019-01-25 14:19:09 +01:00
|
|
|
.emplace<TextElement>(
|
2021-07-11 13:33:35 +02:00
|
|
|
action.target.displayName + ":", MessageElementFlag::BoldUsername,
|
|
|
|
MessageColor(action.target.color), FontStyle::ChatMediumBold)
|
|
|
|
->setLink({Link::UserInfo, action.target.login});
|
2021-07-11 12:19:35 +02:00
|
|
|
builder2
|
2021-07-11 13:33:35 +02:00
|
|
|
.emplace<TextElement>(action.target.displayName + ":",
|
2019-01-20 01:02:04 +01:00
|
|
|
MessageElementFlag::NonBoldUsername,
|
2021-07-11 13:33:35 +02:00
|
|
|
MessageColor(action.target.color))
|
|
|
|
->setLink({Link::UserInfo, action.target.login});
|
2021-07-11 12:19:35 +02:00
|
|
|
// sender's message caught by AutoMod
|
|
|
|
builder2.emplace<TextElement>(action.message, MessageElementFlag::Text,
|
|
|
|
MessageColor::Text);
|
|
|
|
builder2.message().flags.set(MessageFlag::AutoMod);
|
2021-07-11 13:33:35 +02:00
|
|
|
auto text2 =
|
|
|
|
QString("%1: %2").arg(action.target.displayName, action.message);
|
2021-07-11 12:19:35 +02:00
|
|
|
builder2.message().messageText = text2;
|
|
|
|
builder2.message().searchText = text2;
|
2019-01-20 01:02:04 +01:00
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
auto message2 = builder2.release();
|
2019-01-20 01:02:04 +01:00
|
|
|
|
|
|
|
return std::make_pair(message1, message2);
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
MessageBuilder::MessageBuilder()
|
2018-08-11 22:23:06 +02:00
|
|
|
: message_(std::make_shared<Message>())
|
2018-08-07 01:35:24 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
MessageBuilder::MessageBuilder(SystemMessageTag, const QString &text,
|
|
|
|
const QTime &time)
|
2018-08-07 01:35:24 +02:00
|
|
|
: MessageBuilder()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplace<TimestampElement>(time);
|
2019-05-01 12:07:35 +02:00
|
|
|
|
|
|
|
// check system message for links
|
|
|
|
// (e.g. needed for sub ticket message in sub only mode)
|
2019-05-03 08:58:54 +02:00
|
|
|
const QStringList textFragments = text.split(QRegularExpression("\\s"));
|
2019-05-01 12:07:35 +02:00
|
|
|
for (const auto &word : textFragments)
|
|
|
|
{
|
2019-05-03 08:58:54 +02:00
|
|
|
const auto linkString = this->matchLink(word);
|
2019-05-01 12:07:35 +02:00
|
|
|
if (linkString.isEmpty())
|
|
|
|
{
|
|
|
|
this->emplace<TextElement>(word, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->addLink(word, linkString);
|
|
|
|
}
|
|
|
|
}
|
2018-08-07 07:55:31 +02:00
|
|
|
this->message().flags.set(MessageFlag::System);
|
|
|
|
this->message().flags.set(MessageFlag::DoNotTriggerNotification);
|
2019-05-01 16:43:52 +02:00
|
|
|
this->message().messageText = text;
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().searchText = text;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
MessageBuilder::MessageBuilder(TimeoutMessageTag,
|
2020-10-03 13:37:07 +02:00
|
|
|
const QString &systemMessageText, int times,
|
|
|
|
const QTime &time)
|
2020-07-18 16:03:51 +02:00
|
|
|
: MessageBuilder()
|
|
|
|
{
|
|
|
|
QString username = systemMessageText.split(" ").at(0);
|
|
|
|
QString remainder = systemMessageText.mid(username.length() + 1);
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
|
2020-10-03 13:37:07 +02:00
|
|
|
this->emplace<TimestampElement>(time);
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(username, text)
|
|
|
|
->setLink({Link::UserInfo, username});
|
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("%1 (%2 times)").arg(remainder.trimmed()).arg(times), text);
|
|
|
|
|
|
|
|
this->message().messageText = text;
|
|
|
|
this->message().searchText = text;
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
|
|
|
|
const QString &durationInSeconds,
|
2021-04-25 15:44:12 +02:00
|
|
|
bool multipleTimes, const QTime &time)
|
2018-08-07 01:35:24 +02:00
|
|
|
: MessageBuilder()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
QString fullText;
|
2018-08-07 01:35:24 +02:00
|
|
|
QString text;
|
|
|
|
|
2020-10-03 13:37:07 +02:00
|
|
|
this->emplace<TimestampElement>(time);
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(username, fullText)
|
|
|
|
->setLink({Link::UserInfo, username});
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!durationInSeconds.isEmpty())
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
text.append("has been timed out");
|
2018-08-07 01:35:24 +02:00
|
|
|
|
|
|
|
// TODO: Implement who timed the user out
|
|
|
|
|
|
|
|
text.append(" for ");
|
|
|
|
bool ok = true;
|
|
|
|
int timeoutSeconds = durationInSeconds.toInt(&ok);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (ok)
|
|
|
|
{
|
2018-08-07 01:35:24 +02:00
|
|
|
text.append(formatTime(timeoutSeconds));
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
text.append("has been permanently banned");
|
2018-08-07 01:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
text.append(".");
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (multipleTimes)
|
|
|
|
{
|
2018-08-07 01:35:24 +02:00
|
|
|
text.append(" (multiple times)");
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
this->message().flags.set(MessageFlag::System);
|
|
|
|
this->message().flags.set(MessageFlag::Timeout);
|
|
|
|
this->message().flags.set(MessageFlag::DoNotTriggerNotification);
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().timeoutUser = username;
|
2020-07-18 16:03:51 +02:00
|
|
|
|
|
|
|
this->emplaceSystemTextAndUpdate(text, fullText);
|
|
|
|
this->message().messageText = fullText;
|
|
|
|
this->message().searchText = fullText;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 12:31:06 +02:00
|
|
|
// XXX: This does not belong in the MessageBuilder, this should be part of the TwitchMessageBuilder
|
2018-08-07 01:35:24 +02:00
|
|
|
MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
|
2018-08-08 15:35:54 +02:00
|
|
|
: MessageBuilder()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2020-04-13 12:31:06 +02:00
|
|
|
auto current = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
this->emplace<TimestampElement>();
|
2018-08-07 07:55:31 +02:00
|
|
|
this->message().flags.set(MessageFlag::System);
|
|
|
|
this->message().flags.set(MessageFlag::Timeout);
|
2021-07-11 13:33:35 +02:00
|
|
|
this->message().timeoutUser = action.target.login;
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().count = count;
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
|
2020-04-13 12:31:06 +02:00
|
|
|
if (action.target.id == current->getUserId())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate("You were", text);
|
2020-04-13 12:31:06 +02:00
|
|
|
if (action.isBan())
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate("banned", text);
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("timed out for %1").arg(formatTime(action.duration)),
|
|
|
|
text);
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
|
|
|
|
2021-07-11 13:33:35 +02:00
|
|
|
if (!action.source.login.isEmpty())
|
2020-04-13 12:31:06 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate("by", text);
|
|
|
|
this->emplaceSystemTextAndUpdate(
|
2021-07-11 13:33:35 +02:00
|
|
|
action.source.login + (action.reason.isEmpty() ? "." : ":"),
|
2020-07-18 16:03:51 +02:00
|
|
|
text)
|
2021-07-11 13:33:35 +02:00
|
|
|
->setLink({Link::UserInfo, action.source.login});
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
if (!action.reason.isEmpty())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("\"%1\".").arg(action.reason), text);
|
2018-08-07 01:35:24 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-13 12:31:06 +02:00
|
|
|
if (action.isBan())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.source.login, text)
|
|
|
|
->setLink({Link::UserInfo, action.source.login});
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate("banned", text);
|
2020-04-13 12:31:06 +02:00
|
|
|
if (action.reason.isEmpty())
|
|
|
|
{
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.target.login, text)
|
|
|
|
->setLink({Link::UserInfo, action.target.login});
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.target.login + ":",
|
|
|
|
text)
|
|
|
|
->setLink({Link::UserInfo, action.target.login});
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("\"%1\".").arg(action.reason), text);
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.source.login, text)
|
|
|
|
->setLink({Link::UserInfo, action.source.login});
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate("timed out", text);
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.target.login, text)
|
|
|
|
->setLink({Link::UserInfo, action.target.login});
|
2020-04-13 12:31:06 +02:00
|
|
|
if (action.reason.isEmpty())
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("for %1.").arg(formatTime(action.duration)), text);
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("for %1: \"%2\".")
|
|
|
|
.arg(formatTime(action.duration))
|
|
|
|
.arg(action.reason),
|
|
|
|
text);
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
2018-08-07 01:35:24 +02:00
|
|
|
|
2020-04-13 12:31:06 +02:00
|
|
|
if (count > 1)
|
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
QString("(%1 times)").arg(count), text);
|
2020-04-13 12:31:06 +02:00
|
|
|
}
|
2018-08-07 01:35:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 16:43:52 +02:00
|
|
|
this->message().messageText = text;
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().searchText = text;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
MessageBuilder::MessageBuilder(const UnbanAction &action)
|
2018-08-08 15:35:54 +02:00
|
|
|
: MessageBuilder()
|
2017-07-31 00:57:42 +02:00
|
|
|
{
|
2018-08-07 01:35:24 +02:00
|
|
|
this->emplace<TimestampElement>();
|
2018-08-07 07:55:31 +02:00
|
|
|
this->message().flags.set(MessageFlag::System);
|
|
|
|
this->message().flags.set(MessageFlag::Untimeout);
|
2018-08-07 01:35:24 +02:00
|
|
|
|
2021-07-11 13:33:35 +02:00
|
|
|
this->message().timeoutUser = action.target.login;
|
2018-08-07 01:35:24 +02:00
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
QString text;
|
|
|
|
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.source.login, text)
|
|
|
|
->setLink({Link::UserInfo, action.source.login});
|
2020-07-18 16:03:51 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(
|
|
|
|
action.wasBan() ? "unbanned" : "untimedout", text);
|
2021-07-11 13:33:35 +02:00
|
|
|
this->emplaceSystemTextAndUpdate(action.target.login, text)
|
|
|
|
->setLink({Link::UserInfo, action.target.login});
|
2018-08-07 01:35:24 +02:00
|
|
|
|
2019-05-01 16:43:52 +02:00
|
|
|
this->message().messageText = text;
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().searchText = text;
|
|
|
|
}
|
|
|
|
|
2019-01-21 18:33:57 +01:00
|
|
|
MessageBuilder::MessageBuilder(const AutomodUserAction &action)
|
|
|
|
: MessageBuilder()
|
|
|
|
{
|
|
|
|
this->emplace<TimestampElement>();
|
|
|
|
this->message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
QString text;
|
2019-01-22 23:20:43 +01:00
|
|
|
switch (action.type)
|
2019-01-21 18:33:57 +01:00
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case AutomodUserAction::AddPermitted: {
|
2019-01-22 23:20:43 +01:00
|
|
|
text = QString("%1 added %2 as a permitted term on AutoMod.")
|
2021-07-11 13:33:35 +02:00
|
|
|
.arg(action.source.login, action.message);
|
2019-01-22 23:20:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case AutomodUserAction::AddBlocked: {
|
2019-01-22 23:20:43 +01:00
|
|
|
text = QString("%1 added %2 as a blocked term on AutoMod.")
|
2021-07-11 13:33:35 +02:00
|
|
|
.arg(action.source.login, action.message);
|
2019-01-22 23:20:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case AutomodUserAction::RemovePermitted: {
|
2021-05-08 14:14:49 +02:00
|
|
|
text = QString("%1 removed %2 as a permitted term on AutoMod.")
|
2021-07-11 13:33:35 +02:00
|
|
|
.arg(action.source.login, action.message);
|
2019-01-22 23:20:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case AutomodUserAction::RemoveBlocked: {
|
2019-01-22 23:20:43 +01:00
|
|
|
text = QString("%1 removed %2 as a blocked term on AutoMod.")
|
2021-07-11 13:33:35 +02:00
|
|
|
.arg(action.source.login, action.message);
|
2019-01-22 23:20:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case AutomodUserAction::Properties: {
|
2019-01-22 23:20:43 +01:00
|
|
|
text = QString("%1 modified the AutoMod properties.")
|
2021-07-11 13:33:35 +02:00
|
|
|
.arg(action.source.login);
|
2019-01-22 23:20:43 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-01-21 18:33:57 +01:00
|
|
|
}
|
2021-07-11 12:19:35 +02:00
|
|
|
this->message().messageText = text;
|
|
|
|
this->message().searchText = text;
|
2019-01-21 18:33:57 +01:00
|
|
|
|
|
|
|
this->emplace<TextElement>(text, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
Message *MessageBuilder::operator->()
|
|
|
|
{
|
|
|
|
return this->message_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Message &MessageBuilder::message()
|
|
|
|
{
|
|
|
|
return *this->message_;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessagePtr MessageBuilder::release()
|
|
|
|
{
|
2018-08-11 22:23:06 +02:00
|
|
|
std::shared_ptr<Message> ptr;
|
|
|
|
this->message_.swap(ptr);
|
|
|
|
return ptr;
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 11:36:36 +02:00
|
|
|
std::weak_ptr<Message> MessageBuilder::weakOf()
|
|
|
|
{
|
|
|
|
return this->message_;
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
void MessageBuilder::append(std::unique_ptr<MessageElement> element)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().elements.push_back(std::move(element));
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MessageBuilder::matchLink(const QString &string)
|
|
|
|
{
|
2018-06-28 00:24:21 +02:00
|
|
|
LinkParser linkParser(string);
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
static QRegularExpression httpRegex(
|
|
|
|
"\\bhttps?://", QRegularExpression::CaseInsensitiveOption);
|
|
|
|
static QRegularExpression ftpRegex(
|
|
|
|
"\\bftps?://", QRegularExpression::CaseInsensitiveOption);
|
|
|
|
static QRegularExpression spotifyRegex(
|
|
|
|
"\\bspotify:", QRegularExpression::CaseInsensitiveOption);
|
2017-08-12 12:09:26 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!linkParser.hasMatch())
|
|
|
|
{
|
2017-08-12 12:09:26 +02:00
|
|
|
return QString();
|
|
|
|
}
|
2017-08-05 18:44:14 +02:00
|
|
|
|
2018-06-28 00:24:21 +02:00
|
|
|
QString captured = linkParser.getCaptured();
|
2017-07-31 14:23:23 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
if (!captured.contains(httpRegex) && !captured.contains(ftpRegex) &&
|
2018-10-21 13:43:02 +02:00
|
|
|
!captured.contains(spotifyRegex))
|
|
|
|
{
|
2018-07-11 13:50:05 +02:00
|
|
|
captured.insert(0, "http://");
|
2017-07-26 12:01:23 +02:00
|
|
|
}
|
2017-09-24 18:43:24 +02:00
|
|
|
|
2017-07-31 14:23:23 +02:00
|
|
|
return captured;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-06-11 20:53:43 +02:00
|
|
|
|
2019-03-13 15:26:55 +01:00
|
|
|
void MessageBuilder::addLink(const QString &origLink,
|
|
|
|
const QString &matchedLink)
|
|
|
|
{
|
|
|
|
static QRegularExpression domainRegex(
|
|
|
|
R"(^(?:(?:ftp|http)s?:\/\/)?([^\/]+)(?:\/.*)?$)",
|
|
|
|
QRegularExpression::CaseInsensitiveOption);
|
|
|
|
|
|
|
|
QString lowercaseLinkString;
|
|
|
|
auto match = domainRegex.match(origLink);
|
|
|
|
if (match.isValid())
|
|
|
|
{
|
|
|
|
lowercaseLinkString = origLink.mid(0, match.capturedStart(1)) +
|
|
|
|
match.captured(1).toLower() +
|
|
|
|
origLink.mid(match.capturedEnd(1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lowercaseLinkString = origLink;
|
|
|
|
}
|
|
|
|
auto linkElement = Link(Link::Url, matchedLink);
|
|
|
|
|
|
|
|
auto textColor = MessageColor(MessageColor::Link);
|
|
|
|
auto linkMELowercase =
|
|
|
|
this->emplace<TextElement>(lowercaseLinkString,
|
|
|
|
MessageElementFlag::LowercaseLink, textColor)
|
|
|
|
->setLink(linkElement);
|
|
|
|
auto linkMEOriginal =
|
|
|
|
this->emplace<TextElement>(origLink, MessageElementFlag::OriginalLink,
|
|
|
|
textColor)
|
|
|
|
->setLink(linkElement);
|
|
|
|
|
2019-08-20 23:30:39 +02:00
|
|
|
LinkResolver::getLinkInfo(
|
|
|
|
matchedLink, nullptr,
|
|
|
|
[weakMessage = this->weakOf(), linkMELowercase, linkMEOriginal,
|
2020-05-10 12:11:10 +02:00
|
|
|
matchedLink](QString tooltipText, Link originalLink,
|
|
|
|
ImagePtr thumbnail) {
|
2019-08-20 23:30:39 +02:00
|
|
|
auto shared = weakMessage.lock();
|
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!tooltipText.isEmpty())
|
|
|
|
{
|
|
|
|
linkMELowercase->setTooltip(tooltipText);
|
|
|
|
linkMEOriginal->setTooltip(tooltipText);
|
|
|
|
}
|
|
|
|
if (originalLink.value != matchedLink &&
|
|
|
|
!originalLink.value.isEmpty())
|
|
|
|
{
|
|
|
|
linkMELowercase->setLink(originalLink)->updateLink();
|
|
|
|
linkMEOriginal->setLink(originalLink)->updateLink();
|
|
|
|
}
|
2020-05-10 12:11:10 +02:00
|
|
|
linkMELowercase->setThumbnail(thumbnail);
|
|
|
|
linkMELowercase->setThumbnailType(
|
|
|
|
MessageElement::ThumbnailType::Link_Thumbnail);
|
|
|
|
linkMEOriginal->setThumbnail(thumbnail);
|
|
|
|
linkMEOriginal->setThumbnailType(
|
|
|
|
MessageElement::ThumbnailType::Link_Thumbnail);
|
2019-08-20 23:30:39 +02:00
|
|
|
});
|
2019-03-13 15:26:55 +01:00
|
|
|
}
|
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
TextElement *MessageBuilder::emplaceSystemTextAndUpdate(const QString &text,
|
|
|
|
QString &toUpdate)
|
|
|
|
{
|
|
|
|
toUpdate.append(text + " ");
|
|
|
|
return this->emplace<TextElement>(text, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
}
|
|
|
|
|
2017-06-11 20:53:43 +02:00
|
|
|
} // namespace chatterino
|