2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "controllers/ignores/IgnoreController.hpp"
|
2020-02-28 19:04:25 +01:00
|
|
|
#include "controllers/ignores/IgnorePhrase.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "messages/Message.hpp"
|
2018-09-16 17:27:51 +02:00
|
|
|
#include "providers/chatterino/ChatterinoBadges.hpp"
|
2020-10-25 10:36:00 +01:00
|
|
|
#include "providers/ffz/FfzBadges.hpp"
|
2018-08-14 17:45:17 +02:00
|
|
|
#include "providers/twitch/TwitchBadges.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2020-07-04 15:15:59 +02:00
|
|
|
#include "providers/twitch/TwitchCommon.hpp"
|
2019-09-15 13:02:02 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/IrcHelpers.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/Window.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-31 00:37:22 +02:00
|
|
|
#include <QApplication>
|
2019-08-11 21:07:54 +02:00
|
|
|
#include <QColor>
|
2017-07-31 00:37:22 +02:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QMediaPlayer>
|
2018-09-23 20:21:50 +02:00
|
|
|
#include <QStringRef>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <boost/variant.hpp>
|
2017-07-31 00:37:22 +02:00
|
|
|
|
2019-08-11 14:01:47 +02:00
|
|
|
namespace {
|
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
// matches a mention with punctuation at the end, like "@username," or "@username!!!" where capture group would return "username"
|
|
|
|
const QRegularExpression mentionRegex("^@(\\w+)[.,!?;]*?$");
|
|
|
|
|
2019-12-14 12:13:19 +01:00
|
|
|
const QSet<QString> zeroWidthEmotes{
|
2020-03-27 21:23:32 +01:00
|
|
|
"SoSnowy", "IceCold", "SantaHat", "TopHat",
|
|
|
|
"ReinDeer", "CandyCane", "cvMask", "cvHazmat",
|
2019-12-06 05:10:56 +01:00
|
|
|
};
|
|
|
|
|
2019-08-11 21:07:54 +02:00
|
|
|
} // namespace
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2019-12-01 13:32:41 +01:00
|
|
|
namespace {
|
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
QColor getRandomColor(const QVariant &userId)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
int colorSeed = userId.toInt(&ok);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
// We were unable to convert the user ID to an integer, this means Twitch has decided to start using non-integer user IDs
|
|
|
|
// Just randomize the users color
|
|
|
|
colorSeed = std::rand();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto colorIndex = colorSeed % TWITCH_USERNAME_COLORS.size();
|
|
|
|
return TWITCH_USERNAME_COLORS[colorIndex];
|
|
|
|
}
|
|
|
|
|
2019-12-01 13:32:41 +01:00
|
|
|
QStringList parseTagList(const QVariantMap &tags, const QString &key)
|
|
|
|
{
|
|
|
|
auto iterator = tags.find(key);
|
|
|
|
if (iterator == tags.end())
|
|
|
|
return QStringList{};
|
|
|
|
|
|
|
|
return iterator.value().toString().split(
|
|
|
|
',', QString::SplitBehavior::SkipEmptyParts);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<QString, QString> parseBadgeInfos(const QVariantMap &tags)
|
|
|
|
{
|
|
|
|
std::map<QString, QString> badgeInfos;
|
|
|
|
|
|
|
|
for (QString badgeInfo : parseTagList(tags, "badge-info"))
|
|
|
|
{
|
|
|
|
QStringList parts = badgeInfo.split('/');
|
|
|
|
if (parts.size() != 2)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
badgeInfos.emplace(parts[0], parts[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return badgeInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Badge> parseBadges(const QVariantMap &tags)
|
|
|
|
{
|
|
|
|
std::vector<Badge> badges;
|
|
|
|
|
|
|
|
for (QString badge : parseTagList(tags, "badges"))
|
|
|
|
{
|
|
|
|
QStringList parts = badge.split('/');
|
|
|
|
if (parts.size() != 2)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
badges.emplace_back(parts[0], parts[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return badges;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
TwitchMessageBuilder::TwitchMessageBuilder(
|
|
|
|
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
|
|
|
const MessageParseArgs &_args)
|
2020-07-04 15:15:59 +02:00
|
|
|
: SharedMessageBuilder(_channel, _ircMessage, _args)
|
2017-12-31 00:50:07 +01:00
|
|
|
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
2018-02-04 16:33:46 +01:00
|
|
|
{
|
2018-08-08 19:42:14 +02:00
|
|
|
this->usernameColor_ = getApp()->themes->messages.textColors.system;
|
2018-02-04 16:33:46 +01:00
|
|
|
}
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
TwitchMessageBuilder::TwitchMessageBuilder(
|
|
|
|
Channel *_channel, const Communi::IrcMessage *_ircMessage,
|
|
|
|
const MessageParseArgs &_args, QString content, bool isAction)
|
2020-07-04 15:15:59 +02:00
|
|
|
: SharedMessageBuilder(_channel, _ircMessage, _args, content, isAction)
|
2018-02-04 16:33:46 +01:00
|
|
|
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-08-08 19:42:14 +02:00
|
|
|
this->usernameColor_ = getApp()->themes->messages.textColors.system;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 21:33:49 +01:00
|
|
|
bool TwitchMessageBuilder::isIgnored() const
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2020-07-04 15:15:59 +02:00
|
|
|
if (SharedMessageBuilder::isIgnored())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-04 15:15:59 +02:00
|
|
|
return true;
|
2018-01-23 21:33:49 +01:00
|
|
|
}
|
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
if (getSettings()->enableTwitchIgnoredUsers &&
|
2018-10-21 13:43:02 +02:00
|
|
|
this->tags.contains("user-id"))
|
|
|
|
{
|
2018-05-12 23:27:34 +02:00
|
|
|
auto sourceUserID = this->tags.value("user-id").toString();
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
for (const auto &user :
|
2018-10-21 13:43:02 +02:00
|
|
|
app->accounts->twitch.getCurrent()->getIgnores())
|
|
|
|
{
|
|
|
|
if (sourceUserID == user.id)
|
|
|
|
{
|
2019-04-14 16:57:41 +02:00
|
|
|
switch (static_cast<ShowIgnoredUsersMessages>(
|
|
|
|
getSettings()->showIgnoredUsersMessages.getValue()))
|
2019-04-12 22:12:39 +02:00
|
|
|
{
|
|
|
|
case ShowIgnoredUsersMessages::IfModerator:
|
|
|
|
if (this->channel->isMod() ||
|
|
|
|
this->channel->isBroadcaster())
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ShowIgnoredUsersMessages::IfBroadcaster:
|
|
|
|
if (this->channel->isBroadcaster())
|
|
|
|
return false;
|
|
|
|
break;
|
2019-07-27 12:48:55 +02:00
|
|
|
case ShowIgnoredUsersMessages::Never:
|
|
|
|
break;
|
2019-04-12 22:12:39 +02:00
|
|
|
}
|
2020-03-19 18:06:21 +01:00
|
|
|
|
2018-05-12 23:27:34 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 21:33:49 +01:00
|
|
|
return false;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2019-08-04 14:31:57 +02:00
|
|
|
void TwitchMessageBuilder::triggerHighlights()
|
|
|
|
{
|
|
|
|
if (this->historicalMessage_)
|
|
|
|
{
|
|
|
|
// Do nothing. Highlights should not be triggered on historical messages.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
SharedMessageBuilder::triggerHighlights();
|
2019-08-04 14:31:57 +02:00
|
|
|
}
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
MessagePtr TwitchMessageBuilder::build()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2020-07-04 15:15:59 +02:00
|
|
|
// PARSE
|
2019-08-23 16:52:04 +02:00
|
|
|
this->userId_ = this->ircMessage->tag("user-id").toString();
|
|
|
|
|
2020-07-04 15:15:59 +02:00
|
|
|
this->parse();
|
2017-08-12 13:18:48 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->userName == this->channel->getName())
|
|
|
|
{
|
2018-06-22 23:19:52 +02:00
|
|
|
this->senderIsBroadcaster = true;
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:16:56 +02:00
|
|
|
this->message().channelName = this->channel->getName();
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
this->parseMessageID();
|
2017-12-27 01:22:12 +01:00
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
this->parseRoomID();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
// If it is a reward it has to be appended first
|
|
|
|
if (this->args.channelPointRewardId != "")
|
|
|
|
{
|
|
|
|
const auto &reward = this->twitchChannel->channelPointReward(
|
|
|
|
this->args.channelPointRewardId);
|
|
|
|
if (reward)
|
|
|
|
{
|
|
|
|
this->appendChannelPointRewardMessage(reward.get(), this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
this->appendChannelName();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2019-04-13 19:14:58 +02:00
|
|
|
if (this->tags.contains("rm-deleted"))
|
|
|
|
{
|
|
|
|
this->message().flags.set(MessageFlag::Disabled);
|
|
|
|
}
|
|
|
|
|
2019-08-04 14:31:57 +02:00
|
|
|
this->historicalMessage_ = this->tags.contains("historical");
|
|
|
|
|
2020-04-15 23:15:45 +02:00
|
|
|
if (this->tags.contains("msg-id") &&
|
|
|
|
this->tags["msg-id"].toString().split(';').contains(
|
|
|
|
"highlighted-message"))
|
|
|
|
{
|
|
|
|
this->message().flags.set(MessageFlag::RedeemedHighlight);
|
|
|
|
}
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
// timestamp
|
2020-10-03 13:37:07 +02:00
|
|
|
this->emplace<TimestampElement>(
|
|
|
|
calculateMessageTimestamp(this->ircMessage));
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-22 23:19:52 +02:00
|
|
|
bool addModerationElement = true;
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->senderIsBroadcaster)
|
|
|
|
{
|
2018-06-22 23:19:52 +02:00
|
|
|
addModerationElement = false;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-22 23:19:52 +02:00
|
|
|
bool hasUserType = this->tags.contains("user-type");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (hasUserType)
|
|
|
|
{
|
2018-06-22 23:19:52 +02:00
|
|
|
QString userType = this->tags.value("user-type").toString();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (userType == "mod")
|
|
|
|
{
|
|
|
|
if (!args.isStaffOrBroadcaster)
|
|
|
|
{
|
2018-06-22 23:19:52 +02:00
|
|
|
addModerationElement = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (addModerationElement)
|
|
|
|
{
|
2018-06-22 23:19:52 +02:00
|
|
|
this->emplace<TwitchModerationElement>();
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
this->appendTwitchBadges();
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
this->appendChatterinoBadges();
|
2020-10-25 10:36:00 +01:00
|
|
|
this->appendFfzBadges();
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-08-12 13:18:48 +02:00
|
|
|
this->appendUsername();
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
// QString bits;
|
2017-07-02 18:12:11 +02:00
|
|
|
auto iterator = this->tags.find("bits");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator != this->tags.end())
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
this->hasBits_ = true;
|
2019-12-19 21:36:02 +01:00
|
|
|
this->bitsLeft = iterator.value().toInt();
|
2019-09-08 12:45:25 +02:00
|
|
|
this->bits = iterator.value().toString();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// twitch emotes
|
2020-09-26 14:21:46 +02:00
|
|
|
std::vector<TwitchEmoteOccurence> twitchEmotes;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
iterator = this->tags.find("emotes");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator != this->tags.end())
|
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
QStringList emoteString = iterator.value().toString().split('/');
|
2018-11-17 11:00:44 +01:00
|
|
|
std::vector<int> correctPositions;
|
2018-11-17 11:09:31 +01:00
|
|
|
for (int i = 0; i < this->originalMessage_.size(); ++i)
|
|
|
|
{
|
|
|
|
if (!this->originalMessage_.at(i).isLowSurrogate())
|
|
|
|
{
|
2018-11-17 11:00:44 +01:00
|
|
|
correctPositions.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
for (QString emote : emoteString)
|
|
|
|
{
|
2018-11-17 11:00:44 +01:00
|
|
|
this->appendTwitchEmote(emote, twitchEmotes, correctPositions);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2018-09-23 20:21:50 +02:00
|
|
|
}
|
|
|
|
|
2019-08-04 14:31:57 +02:00
|
|
|
// This runs through all ignored phrases and runs its replacements on this->originalMessage_
|
|
|
|
this->runIgnoreReplaces(twitchEmotes);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-09-23 20:21:50 +02:00
|
|
|
std::sort(twitchEmotes.begin(), twitchEmotes.end(),
|
2018-09-30 13:37:39 +02:00
|
|
|
[](const auto &a, const auto &b) {
|
2020-11-08 12:02:19 +01:00
|
|
|
return a.start < b.start;
|
2018-09-30 13:37:39 +02:00
|
|
|
});
|
2018-09-23 20:21:50 +02:00
|
|
|
twitchEmotes.erase(std::unique(twitchEmotes.begin(), twitchEmotes.end(),
|
|
|
|
[](const auto &first, const auto &second) {
|
2020-09-26 14:21:46 +02:00
|
|
|
return first.start == second.start;
|
2018-09-23 20:21:50 +02:00
|
|
|
}),
|
|
|
|
twitchEmotes.end());
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// words
|
2018-07-06 19:23:47 +02:00
|
|
|
QStringList splits = this->originalMessage_.split(' ');
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
this->addWords(splits, twitchEmotes);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2019-05-01 16:43:52 +02:00
|
|
|
this->message().messageText = this->originalMessage_;
|
2019-05-30 17:23:01 +02:00
|
|
|
this->message().searchText = this->message().localizedName + " " +
|
|
|
|
this->userName + ": " + this->originalMessage_;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-04 14:31:57 +02:00
|
|
|
// highlights
|
|
|
|
this->parseHighlights();
|
|
|
|
|
|
|
|
// highlighting incoming whispers if requested per setting
|
|
|
|
if (this->args.isReceivedWhisper && getSettings()->highlightInlineWhispers)
|
|
|
|
{
|
|
|
|
this->message().flags.set(MessageFlag::HighlightedWhisper, true);
|
2020-06-27 13:20:21 +02:00
|
|
|
this->message().highlightColor =
|
|
|
|
ColorProvider::instance().color(ColorType::Whisper);
|
2019-08-04 14:31:57 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
return this->release();
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2017-08-12 12:07:53 +02:00
|
|
|
|
2020-09-26 14:21:46 +02:00
|
|
|
bool doesWordContainATwitchEmote(
|
|
|
|
int cursor, const QString &word,
|
|
|
|
const std::vector<TwitchEmoteOccurence> &twitchEmotes,
|
|
|
|
std::vector<TwitchEmoteOccurence>::const_iterator ¤tTwitchEmoteIt)
|
|
|
|
{
|
|
|
|
if (currentTwitchEmoteIt == twitchEmotes.end())
|
|
|
|
{
|
|
|
|
// No emote to add!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto ¤tTwitchEmote = *currentTwitchEmoteIt;
|
|
|
|
|
|
|
|
auto wordEnd = cursor + word.length();
|
|
|
|
|
|
|
|
// Check if this emote fits within the word boundaries
|
|
|
|
if (currentTwitchEmote.start < cursor || currentTwitchEmote.end > wordEnd)
|
|
|
|
{
|
|
|
|
// this emote does not fit xd
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void TwitchMessageBuilder::addWords(
|
2018-09-30 13:37:39 +02:00
|
|
|
const QStringList &words,
|
2020-09-26 14:21:46 +02:00
|
|
|
const std::vector<TwitchEmoteOccurence> &twitchEmotes)
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
// cursor currently indicates what character index we're currently operating in the full list of words
|
|
|
|
int cursor = 0;
|
|
|
|
auto currentTwitchEmoteIt = twitchEmotes.begin();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-09-15 19:05:04 +02:00
|
|
|
for (auto word : words)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
while (doesWordContainATwitchEmote(cursor, word, twitchEmotes,
|
|
|
|
currentTwitchEmoteIt))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
auto wordEnd = cursor + word.length();
|
|
|
|
const auto ¤tTwitchEmote = *currentTwitchEmoteIt;
|
|
|
|
|
|
|
|
if (currentTwitchEmote.start == cursor)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
// This emote exists right at the start of the word!
|
|
|
|
this->emplace<EmoteElement>(currentTwitchEmote.ptr,
|
|
|
|
MessageElementFlag::TwitchEmote);
|
|
|
|
auto len = currentTwitchEmote.name.string.length();
|
|
|
|
cursor += len;
|
|
|
|
word = word.mid(len);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2020-09-26 14:21:46 +02:00
|
|
|
++currentTwitchEmoteIt;
|
2019-09-15 19:05:04 +02:00
|
|
|
|
2020-09-26 14:21:46 +02:00
|
|
|
if (word.isEmpty())
|
|
|
|
{
|
|
|
|
// space
|
|
|
|
cursor += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->message().elements.back()->setTrailingSpace(false);
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2020-09-26 14:21:46 +02:00
|
|
|
continue;
|
2019-09-15 19:05:04 +02:00
|
|
|
}
|
2020-09-26 14:21:46 +02:00
|
|
|
|
|
|
|
// Emote is not at the start
|
|
|
|
|
|
|
|
// 1. Add text before the emote
|
|
|
|
QString preText = word.left(currentTwitchEmote.start - cursor);
|
|
|
|
for (auto &variant : getApp()->emotes->emojis.parse(preText))
|
2019-09-15 19:05:04 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
boost::apply_visitor(
|
2020-11-08 12:02:19 +01:00
|
|
|
[&](auto &&arg) {
|
|
|
|
this->addTextOrEmoji(arg);
|
|
|
|
},
|
|
|
|
variant);
|
2019-09-15 19:05:04 +02:00
|
|
|
}
|
2020-09-26 14:21:46 +02:00
|
|
|
|
|
|
|
cursor += preText.size();
|
|
|
|
|
|
|
|
word = word.mid(preText.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (word.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// split words
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &variant : getApp()->emotes->emojis.parse(word))
|
|
|
|
{
|
2020-11-08 12:02:19 +01:00
|
|
|
boost::apply_visitor(
|
|
|
|
[&](auto &&arg) {
|
|
|
|
this->addTextOrEmoji(arg);
|
|
|
|
},
|
|
|
|
variant);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2020-09-26 14:21:46 +02:00
|
|
|
cursor += word.size() + 1;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void TwitchMessageBuilder::addTextOrEmoji(EmotePtr emote)
|
|
|
|
{
|
2020-07-04 15:15:59 +02:00
|
|
|
return SharedMessageBuilder::addTextOrEmoji(emote);
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
|
|
|
|
{
|
|
|
|
auto string = QString(string_);
|
2018-07-04 12:22:01 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->hasBits_ && this->tryParseCheermote(string))
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
// This string was parsed as a cheermote
|
|
|
|
return;
|
|
|
|
}
|
2017-08-12 12:09:26 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
// TODO: Implement ignored emotes
|
|
|
|
// Format of ignored emotes:
|
|
|
|
// Emote name: "forsenPuke" - if string in ignoredEmotes
|
|
|
|
// Will match emote regardless of source (i.e. bttv, ffz)
|
|
|
|
// Emote source + name: "bttv:nyanPls"
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->tryAppendEmote({string}))
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
// Successfully appended an emote
|
|
|
|
return;
|
|
|
|
}
|
2017-08-05 18:44:14 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
// Actually just text
|
|
|
|
auto linkString = this->matchLink(string);
|
2018-09-30 13:37:39 +02:00
|
|
|
auto textColor = this->action_ ? MessageColor(this->usernameColor_)
|
|
|
|
: MessageColor(MessageColor::Text);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2020-07-18 16:03:51 +02:00
|
|
|
if (!linkString.isEmpty())
|
|
|
|
{
|
|
|
|
this->addLink(string, linkString);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.startsWith('@'))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
auto match = mentionRegex.match(string);
|
|
|
|
// Only treat as @mention if valid username
|
|
|
|
if (match.hasMatch())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
QString username = match.captured(1);
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
|
2020-07-18 16:03:51 +02:00
|
|
|
textColor, FontStyle::ChatMediumBold)
|
|
|
|
->setLink({Link::UserInfo, username});
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(
|
2020-07-18 16:03:51 +02:00
|
|
|
string, MessageElementFlag::NonBoldUsername, textColor)
|
|
|
|
->setLink({Link::UserInfo, username});
|
|
|
|
return;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2020-07-18 16:03:51 +02:00
|
|
|
|
|
|
|
if (this->twitchChannel != nullptr && getSettings()->findAllUsernames)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-18 16:03:51 +02:00
|
|
|
auto chatters = this->twitchChannel->accessChatters();
|
|
|
|
if (chatters->contains(string))
|
|
|
|
{
|
|
|
|
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
|
|
|
|
textColor, FontStyle::ChatMediumBold)
|
|
|
|
->setLink({Link::UserInfo, string});
|
|
|
|
|
|
|
|
this->emplace<TextElement>(
|
|
|
|
string, MessageElementFlag::NonBoldUsername, textColor)
|
|
|
|
->setLink({Link::UserInfo, string});
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2020-07-18 16:03:51 +02:00
|
|
|
|
|
|
|
this->emplace<TextElement>(string, MessageElementFlag::Text, textColor);
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchMessageBuilder::parseMessageID()
|
|
|
|
{
|
|
|
|
auto iterator = this->tags.find("id");
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator != this->tags.end())
|
|
|
|
{
|
2019-04-28 02:25:05 +02:00
|
|
|
this->message().id = iterator.value().toString();
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
void TwitchMessageBuilder::parseRoomID()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->twitchChannel == nullptr)
|
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
auto iterator = this->tags.find("room-id");
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator != std::end(this->tags))
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->roomID_ = iterator.value().toString();
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->twitchChannel->roomId().isEmpty())
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
this->twitchChannel->setRoomId(this->roomID_);
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-11 22:18:01 +02:00
|
|
|
void TwitchMessageBuilder::parseUsernameColor()
|
2017-07-02 18:12:11 +02:00
|
|
|
{
|
2019-08-11 14:01:47 +02:00
|
|
|
const auto iterator = this->tags.find("color");
|
2019-08-11 22:18:01 +02:00
|
|
|
if (iterator != this->tags.end())
|
2019-08-11 14:01:47 +02:00
|
|
|
{
|
2019-08-11 22:18:01 +02:00
|
|
|
if (const auto color = iterator.value().toString(); !color.isEmpty())
|
|
|
|
{
|
|
|
|
this->usernameColor_ = QColor(color);
|
2020-10-18 15:16:56 +02:00
|
|
|
this->message().usernameColor = this->usernameColor_;
|
2019-08-11 22:18:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-08-11 14:01:47 +02:00
|
|
|
}
|
2019-08-11 22:18:01 +02:00
|
|
|
|
|
|
|
if (getSettings()->colorizeNicknames && this->tags.contains("user-id"))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-08-11 14:01:47 +02:00
|
|
|
this->usernameColor_ = getRandomColor(this->tags.value("user-id"));
|
2020-10-18 15:16:56 +02:00
|
|
|
this->message().usernameColor = this->usernameColor_;
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
2019-08-11 22:18:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchMessageBuilder::parseUsername()
|
|
|
|
{
|
2020-07-04 15:15:59 +02:00
|
|
|
SharedMessageBuilder::parseUsername();
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->userName.isEmpty() || this->args.trimSubscriberUsername)
|
|
|
|
{
|
2017-07-02 18:12:11 +02:00
|
|
|
this->userName = this->tags.value(QLatin1String("login")).toString();
|
|
|
|
}
|
2017-12-17 17:48:46 +01:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
// display name
|
|
|
|
// auto displayNameVariant = this->tags.value("display-name");
|
|
|
|
// if (displayNameVariant.isValid()) {
|
2018-08-06 21:17:03 +02:00
|
|
|
// this->userName = displayNameVariant.toString() + " (" +
|
|
|
|
// this->userName + ")";
|
2018-06-04 12:23:23 +02:00
|
|
|
// }
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().loginName = this->userName;
|
2019-08-10 13:11:53 +02:00
|
|
|
|
|
|
|
// Update current user color if this is our message
|
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
if (this->ircMessage->nick() == currentUser->getUserName())
|
|
|
|
{
|
|
|
|
currentUser->setColor(this->usernameColor_);
|
|
|
|
}
|
2017-08-12 13:18:48 +02:00
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2017-08-12 13:18:48 +02:00
|
|
|
void TwitchMessageBuilder::appendUsername()
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2017-07-23 11:59:05 +02:00
|
|
|
QString username = this->userName;
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().loginName = username;
|
2017-07-23 11:59:05 +02:00
|
|
|
QString localizedName;
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2017-08-12 13:18:48 +02:00
|
|
|
auto iterator = this->tags.find("display-name");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator != this->tags.end())
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
QString displayName =
|
|
|
|
parseTagString(iterator.value().toString()).trimmed();
|
2017-07-23 11:59:05 +02:00
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
if (QString::compare(displayName, this->userName,
|
2018-10-21 13:43:02 +02:00
|
|
|
Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
2017-07-23 11:59:05 +02:00
|
|
|
username = displayName;
|
2017-12-17 21:05:25 +01:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().displayName = displayName;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-23 11:59:05 +02:00
|
|
|
localizedName = displayName;
|
2017-12-17 21:05:25 +01:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().displayName = username;
|
|
|
|
this->message().localizedName = displayName;
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:59:05 +02:00
|
|
|
bool hasLocalizedName = !localizedName.isEmpty();
|
|
|
|
|
|
|
|
// The full string that will be rendered in the chat widget
|
2018-01-11 20:16:25 +01:00
|
|
|
QString usernameText;
|
2017-07-23 11:59:05 +02:00
|
|
|
|
|
|
|
pajlada::Settings::Setting<int> usernameDisplayMode(
|
2018-09-30 13:37:39 +02:00
|
|
|
"/appearance/messages/usernameDisplayMode",
|
|
|
|
UsernameDisplayMode::UsernameAndLocalizedName);
|
2017-07-23 11:59:05 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (usernameDisplayMode.getValue())
|
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case UsernameDisplayMode::Username: {
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-07-23 11:59:05 +02:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case UsernameDisplayMode::LocalizedName: {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (hasLocalizedName)
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = localizedName;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username;
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-07-23 11:59:05 +02:00
|
|
|
|
|
|
|
default:
|
2019-09-26 00:51:05 +02:00
|
|
|
case UsernameDisplayMode::UsernameAndLocalizedName: {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (hasLocalizedName)
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username + "(" + localizedName + ")";
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username;
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->args.isSentWhisper)
|
|
|
|
{
|
2017-07-02 18:12:11 +02:00
|
|
|
// TODO(pajlada): Re-implement
|
2018-08-06 21:17:03 +02:00
|
|
|
// userDisplayString +=
|
2019-10-07 22:42:34 +02:00
|
|
|
// IrcManager::instance().getUser().getUserName();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (this->args.isReceivedWhisper)
|
|
|
|
{
|
2018-02-04 16:33:46 +01:00
|
|
|
// Sender username
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
|
|
|
|
this->usernameColor_,
|
2018-05-23 04:22:17 +02:00
|
|
|
FontStyle::ChatMediumBold)
|
2018-08-26 10:42:00 +02:00
|
|
|
->setLink({Link::UserWhisper, this->message().displayName});
|
2018-02-04 16:33:46 +01:00
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
auto currentUser = app->accounts->twitch.getCurrent();
|
2018-02-04 16:33:46 +01:00
|
|
|
|
|
|
|
// Separator
|
2018-08-16 00:16:33 +02:00
|
|
|
this->emplace<TextElement>("->", MessageElementFlag::Username,
|
2018-09-30 13:37:39 +02:00
|
|
|
app->themes->messages.textColors.system,
|
|
|
|
FontStyle::ChatMedium);
|
2018-02-04 16:33:46 +01:00
|
|
|
|
2018-08-11 17:35:46 +02:00
|
|
|
QColor selfColor = currentUser->color();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!selfColor.isValid())
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
selfColor = app->themes->messages.textColors.system;
|
2018-02-04 16:33:46 +01:00
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
// Your own username
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(currentUser->getUserName() + ":",
|
|
|
|
MessageElementFlag::Username, selfColor,
|
|
|
|
FontStyle::ChatMediumBold);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!this->action_)
|
|
|
|
{
|
2018-02-04 16:33:46 +01:00
|
|
|
usernameText += ":";
|
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
|
|
|
|
this->usernameColor_,
|
2018-05-23 04:22:17 +02:00
|
|
|
FontStyle::ChatMediumBold)
|
2018-08-22 15:16:19 +02:00
|
|
|
->setLink({Link::UserInfo, this->message().displayName});
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-04 14:31:57 +02:00
|
|
|
void TwitchMessageBuilder::runIgnoreReplaces(
|
2020-09-26 14:21:46 +02:00
|
|
|
std::vector<TwitchEmoteOccurence> &twitchEmotes)
|
2017-07-31 01:19:25 +02:00
|
|
|
{
|
2020-02-23 22:15:13 +01:00
|
|
|
auto phrases = getCSettings().ignoredMessages.readOnly();
|
2020-09-26 14:21:46 +02:00
|
|
|
auto removeEmotesInRange = [](int pos, int len,
|
|
|
|
auto &twitchEmotes) mutable {
|
|
|
|
auto it = std::partition(
|
|
|
|
twitchEmotes.begin(), twitchEmotes.end(),
|
|
|
|
[pos, len](const auto &item) {
|
|
|
|
return !((item.start >= pos) && item.start < (pos + len));
|
|
|
|
});
|
|
|
|
for (auto copy = it; copy != twitchEmotes.end(); ++copy)
|
|
|
|
{
|
|
|
|
if ((*copy).ptr == nullptr)
|
2019-08-04 14:31:57 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
qDebug() << "remem nullptr" << (*copy).name.string;
|
2019-08-04 14:31:57 +02:00
|
|
|
}
|
2020-09-26 14:21:46 +02:00
|
|
|
}
|
|
|
|
std::vector<TwitchEmoteOccurence> v(it, twitchEmotes.end());
|
|
|
|
twitchEmotes.erase(it, twitchEmotes.end());
|
|
|
|
return v;
|
|
|
|
};
|
2019-08-04 14:31:57 +02:00
|
|
|
|
|
|
|
auto shiftIndicesAfter = [&twitchEmotes](int pos, int by) mutable {
|
|
|
|
for (auto &item : twitchEmotes)
|
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
auto &index = item.start;
|
2019-08-04 14:31:57 +02:00
|
|
|
if (index >= pos)
|
|
|
|
{
|
|
|
|
index += by;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase,
|
|
|
|
const QStringRef &midrepl,
|
|
|
|
int startIndex) mutable {
|
|
|
|
if (!phrase.containsEmote())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QStringRef> words = midrepl.split(' ');
|
|
|
|
int pos = 0;
|
|
|
|
for (const auto &word : words)
|
|
|
|
{
|
|
|
|
for (const auto &emote : phrase.getEmotes())
|
|
|
|
{
|
|
|
|
if (word == emote.first.string)
|
|
|
|
{
|
|
|
|
if (emote.second == nullptr)
|
|
|
|
{
|
2020-01-03 20:51:37 +01:00
|
|
|
qDebug() << "emote null" << emote.first.string;
|
2019-08-04 14:31:57 +02:00
|
|
|
}
|
2020-09-26 14:21:46 +02:00
|
|
|
twitchEmotes.push_back(TwitchEmoteOccurence{
|
|
|
|
startIndex + pos,
|
|
|
|
startIndex + pos + emote.first.string.length(),
|
|
|
|
emote.second,
|
|
|
|
emote.first,
|
|
|
|
});
|
2019-08-04 14:31:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pos += word.length() + 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-23 17:10:49 +01:00
|
|
|
for (const auto &phrase : *phrases)
|
2019-08-04 14:31:57 +02:00
|
|
|
{
|
|
|
|
if (phrase.isBlock())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-04 23:11:17 +01:00
|
|
|
const auto &pattern = phrase.getPattern();
|
|
|
|
if (pattern.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-04 14:31:57 +02:00
|
|
|
if (phrase.isRegex())
|
|
|
|
{
|
|
|
|
const auto ®ex = phrase.getRegex();
|
|
|
|
if (!regex.isValid())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QRegularExpressionMatch match;
|
|
|
|
int from = 0;
|
|
|
|
while ((from = this->originalMessage_.indexOf(regex, from,
|
|
|
|
&match)) != -1)
|
|
|
|
{
|
|
|
|
int len = match.capturedLength();
|
|
|
|
auto vret = removeEmotesInRange(from, len, twitchEmotes);
|
|
|
|
auto mid = this->originalMessage_.mid(from, len);
|
|
|
|
mid.replace(regex, phrase.getReplace());
|
|
|
|
|
|
|
|
int midsize = mid.size();
|
|
|
|
this->originalMessage_.replace(from, len, mid);
|
|
|
|
int pos1 = from;
|
|
|
|
while (pos1 > 0)
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos1 - 1] == ' ')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--pos1;
|
|
|
|
}
|
|
|
|
int pos2 = from + midsize;
|
|
|
|
while (pos2 < this->originalMessage_.length())
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos2] == ' ')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++pos2;
|
|
|
|
}
|
|
|
|
|
|
|
|
shiftIndicesAfter(from + len, midsize - len);
|
|
|
|
|
|
|
|
auto midExtendedRef =
|
|
|
|
this->originalMessage_.midRef(pos1, pos2 - pos1);
|
|
|
|
|
|
|
|
for (auto &tup : vret)
|
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
if (tup.ptr == nullptr)
|
2019-08-04 14:31:57 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
qDebug() << "v nullptr" << tup.name.string;
|
2019-08-04 14:31:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QRegularExpression emoteregex(
|
2020-09-26 14:21:46 +02:00
|
|
|
"\\b" + tup.name.string + "\\b",
|
2019-08-04 14:31:57 +02:00
|
|
|
QRegularExpression::UseUnicodePropertiesOption);
|
|
|
|
auto _match = emoteregex.match(midExtendedRef);
|
|
|
|
if (_match.hasMatch())
|
|
|
|
{
|
|
|
|
int last = _match.lastCapturedIndex();
|
|
|
|
for (int i = 0; i <= last; ++i)
|
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
tup.start = from + _match.capturedStart();
|
2019-08-04 14:31:57 +02:00
|
|
|
twitchEmotes.push_back(std::move(tup));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addReplEmotes(phrase, midExtendedRef, pos1);
|
|
|
|
|
|
|
|
from += midsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int from = 0;
|
|
|
|
while ((from = this->originalMessage_.indexOf(
|
|
|
|
pattern, from, phrase.caseSensitivity())) != -1)
|
|
|
|
{
|
|
|
|
int len = pattern.size();
|
|
|
|
auto vret = removeEmotesInRange(from, len, twitchEmotes);
|
|
|
|
auto replace = phrase.getReplace();
|
|
|
|
|
|
|
|
int replacesize = replace.size();
|
|
|
|
this->originalMessage_.replace(from, len, replace);
|
|
|
|
|
|
|
|
int pos1 = from;
|
|
|
|
while (pos1 > 0)
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos1 - 1] == ' ')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--pos1;
|
|
|
|
}
|
|
|
|
int pos2 = from + replacesize;
|
|
|
|
while (pos2 < this->originalMessage_.length())
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos2] == ' ')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++pos2;
|
|
|
|
}
|
|
|
|
|
|
|
|
shiftIndicesAfter(from + len, replacesize - len);
|
|
|
|
|
|
|
|
auto midExtendedRef =
|
|
|
|
this->originalMessage_.midRef(pos1, pos2 - pos1);
|
|
|
|
|
|
|
|
for (auto &tup : vret)
|
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
if (tup.ptr == nullptr)
|
2019-08-04 14:31:57 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
qDebug() << "v nullptr" << tup.name.string;
|
2019-08-04 14:31:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QRegularExpression emoteregex(
|
2020-09-26 14:21:46 +02:00
|
|
|
"\\b" + tup.name.string + "\\b",
|
2019-08-04 14:31:57 +02:00
|
|
|
QRegularExpression::UseUnicodePropertiesOption);
|
|
|
|
auto match = emoteregex.match(midExtendedRef);
|
|
|
|
if (match.hasMatch())
|
|
|
|
{
|
|
|
|
int last = match.lastCapturedIndex();
|
|
|
|
for (int i = 0; i <= last; ++i)
|
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
tup.start = from + match.capturedStart();
|
2019-08-04 14:31:57 +02:00
|
|
|
twitchEmotes.push_back(std::move(tup));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addReplEmotes(phrase, midExtendedRef, pos1);
|
|
|
|
|
|
|
|
from += replacesize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
void TwitchMessageBuilder::appendTwitchEmote(
|
2020-09-26 14:21:46 +02:00
|
|
|
const QString &emote, std::vector<TwitchEmoteOccurence> &vec,
|
2018-11-17 11:09:31 +01:00
|
|
|
std::vector<int> &correctPositions)
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!emote.contains(':'))
|
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
auto parameters = emote.split(':');
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (parameters.length() < 2)
|
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
auto id = EmoteId{parameters.at(0)};
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
auto occurences = parameters.at(1).split(',');
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (QString occurence : occurences)
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
auto coords = occurence.split('-');
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (coords.length() < 2)
|
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-27 12:48:55 +02:00
|
|
|
auto start = correctPositions[coords.at(0).toUInt()];
|
|
|
|
auto end = correctPositions[coords.at(1).toUInt()];
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (start >= end || start < 0 || end > this->originalMessage_.length())
|
|
|
|
{
|
2017-06-13 21:13:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
auto name =
|
|
|
|
EmoteName{this->originalMessage_.mid(start, end - start + 1)};
|
2020-09-26 14:21:46 +02:00
|
|
|
TwitchEmoteOccurence emoteOccurence{
|
|
|
|
start, end, app->emotes->twitch.getOrCreateEmote(id, name), name};
|
|
|
|
if (emoteOccurence.ptr == nullptr)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-09-26 14:21:46 +02:00
|
|
|
qDebug() << "nullptr" << emoteOccurence.name.string;
|
2018-09-23 20:21:50 +02:00
|
|
|
}
|
2020-09-26 14:21:46 +02:00
|
|
|
vec.push_back(std::move(emoteOccurence));
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
|
2017-07-23 09:53:50 +02:00
|
|
|
{
|
2019-06-22 14:16:21 +02:00
|
|
|
auto *app = getApp();
|
|
|
|
|
|
|
|
const auto &globalBttvEmotes = app->twitch.server->getBttvEmotes();
|
|
|
|
const auto &globalFfzEmotes = app->twitch.server->getFfzEmotes();
|
2018-08-25 12:23:58 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
auto flags = MessageElementFlags();
|
2018-08-02 14:23:27 +02:00
|
|
|
auto emote = boost::optional<EmotePtr>{};
|
|
|
|
|
2019-06-22 14:16:21 +02:00
|
|
|
// Emote order:
|
|
|
|
// - FrankerFaceZ Channel
|
|
|
|
// - BetterTTV Channel
|
|
|
|
// - FrankerFaceZ Global
|
|
|
|
// - BetterTTV Global
|
|
|
|
if (this->twitchChannel && (emote = this->twitchChannel->ffzEmote(name)))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-05-20 20:06:32 +02:00
|
|
|
flags = MessageElementFlag::FfzEmote;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2019-06-22 14:16:21 +02:00
|
|
|
else if (this->twitchChannel &&
|
|
|
|
(emote = this->twitchChannel->bttvEmote(name)))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
flags = MessageElementFlag::BttvEmote;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2019-06-22 14:16:21 +02:00
|
|
|
else if ((emote = globalFfzEmotes.emote(name)))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
flags = MessageElementFlag::FfzEmote;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2019-06-22 14:16:21 +02:00
|
|
|
else if ((emote = globalBttvEmotes.emote(name)))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-05-20 20:06:32 +02:00
|
|
|
flags = MessageElementFlag::BttvEmote;
|
2019-12-06 05:10:56 +01:00
|
|
|
|
|
|
|
if (zeroWidthEmotes.contains(name.string))
|
|
|
|
{
|
|
|
|
flags.set(MessageElementFlag::ZeroWidthEmote);
|
|
|
|
}
|
2017-07-23 09:53:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (emote)
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
this->emplace<EmoteElement>(emote.get(), flags);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Failure;
|
2017-07-23 09:53:50 +02:00
|
|
|
}
|
|
|
|
|
2019-12-01 13:32:41 +01:00
|
|
|
boost::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
|
|
|
|
const Badge &badge)
|
|
|
|
{
|
|
|
|
if (auto channelBadge =
|
|
|
|
this->twitchChannel->twitchBadge(badge.key_, badge.value_))
|
|
|
|
{
|
|
|
|
return channelBadge;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto globalBadge = this->twitchChannel->globalTwitchBadges().badge(
|
|
|
|
badge.key_, badge.value_))
|
|
|
|
{
|
|
|
|
return globalBadge;
|
|
|
|
}
|
|
|
|
|
|
|
|
return boost::none;
|
|
|
|
}
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
void TwitchMessageBuilder::appendTwitchBadges()
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->twitchChannel == nullptr)
|
|
|
|
{
|
2018-10-02 19:27:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-01 13:32:41 +01:00
|
|
|
auto badgeInfos = parseBadgeInfos(this->tags);
|
|
|
|
auto badges = parseBadges(this->tags);
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2019-12-01 13:32:41 +01:00
|
|
|
for (const auto &badge : badges)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-12-01 13:32:41 +01:00
|
|
|
auto badgeEmote = this->getTwitchBadge(badge);
|
|
|
|
if (!badgeEmote)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-12-01 13:32:41 +01:00
|
|
|
continue;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2019-12-01 13:32:41 +01:00
|
|
|
auto tooltip = (*badgeEmote)->tooltip.string;
|
|
|
|
|
|
|
|
if (badge.key_ == "bits")
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-12-01 13:32:41 +01:00
|
|
|
const auto &cheerAmount = badge.value_;
|
|
|
|
tooltip = QString("Twitch cheer %0").arg(cheerAmount);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2019-12-01 13:32:41 +01:00
|
|
|
else if (badge.key_ == "moderator")
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-10-25 21:53:03 +02:00
|
|
|
if (auto customModBadge = this->twitchChannel->ffzCustomModBadge())
|
|
|
|
{
|
2019-09-08 11:30:06 +02:00
|
|
|
this->emplace<ModBadgeElement>(
|
2018-10-25 21:53:03 +02:00
|
|
|
customModBadge.get(),
|
|
|
|
MessageElementFlag::BadgeChannelAuthority)
|
|
|
|
->setTooltip((*customModBadge)->tooltip.string);
|
2019-12-01 13:32:41 +01:00
|
|
|
// early out, since we have to add a custom badge element here
|
2018-10-25 21:53:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-07-13 15:55:15 +02:00
|
|
|
}
|
2019-12-01 13:32:41 +01:00
|
|
|
else if (badge.flag_ == MessageElementFlag::BadgeSubscription)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-12-01 13:32:41 +01:00
|
|
|
auto badgeInfoIt = badgeInfos.find(badge.key_);
|
|
|
|
if (badgeInfoIt != badgeInfos.end())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-07-05 14:08:28 +02:00
|
|
|
// badge.value_ is 4 chars long if user is subbed on higher tier
|
|
|
|
// (tier + amount of months with leading zero if less than 100)
|
|
|
|
// e.g. 3054 - tier 3 4,5-year sub. 2108 - tier 2 9-year sub
|
|
|
|
const auto &subTier =
|
|
|
|
badge.value_.length() > 3 ? badge.value_.front() : '1';
|
2019-12-01 13:32:41 +01:00
|
|
|
const auto &subMonths = badgeInfoIt->second;
|
2020-07-05 14:08:28 +02:00
|
|
|
tooltip +=
|
|
|
|
QString(" (%1%2 months)")
|
|
|
|
.arg(subTier != '1' ? QString("Tier %1, ").arg(subTier)
|
|
|
|
: "")
|
|
|
|
.arg(subMonths);
|
2017-06-13 22:03:29 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
2018-08-14 17:45:17 +02:00
|
|
|
|
2019-12-01 13:32:41 +01:00
|
|
|
this->emplace<BadgeElement>(badgeEmote.get(), badge.flag_)
|
|
|
|
->setTooltip(tooltip);
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
2020-10-18 15:16:56 +02:00
|
|
|
|
|
|
|
this->message().badges = badges;
|
|
|
|
this->message().badgeInfos = badgeInfos;
|
2019-12-01 13:32:41 +01:00
|
|
|
}
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
void TwitchMessageBuilder::appendChatterinoBadges()
|
2017-08-12 13:20:52 +02:00
|
|
|
{
|
2019-08-23 16:52:04 +02:00
|
|
|
if (auto badge = getApp()->chatterinoBadges->getBadge({this->userId_}))
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-08-23 16:52:04 +02:00
|
|
|
this->emplace<BadgeElement>(*badge,
|
2018-09-30 13:37:39 +02:00
|
|
|
MessageElementFlag::BadgeChatterino);
|
2018-09-16 17:27:51 +02:00
|
|
|
}
|
2017-08-12 13:20:52 +02:00
|
|
|
}
|
|
|
|
|
2020-10-25 10:36:00 +01:00
|
|
|
void TwitchMessageBuilder::appendFfzBadges()
|
|
|
|
{
|
|
|
|
if (auto badge = getApp()->ffzBadges->getBadge({this->userId_}))
|
|
|
|
{
|
|
|
|
if (auto color = getApp()->ffzBadges->getBadgeColor({this->userId_}))
|
|
|
|
{
|
|
|
|
this->emplace<FfzBadgeElement>(*badge, MessageElementFlag::BadgeFfz,
|
|
|
|
color.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 12:45:25 +02:00
|
|
|
Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
|
2018-01-12 19:37:11 +01:00
|
|
|
{
|
2019-12-19 21:36:02 +01:00
|
|
|
if (this->bitsLeft == 0)
|
|
|
|
{
|
|
|
|
return Failure;
|
|
|
|
}
|
|
|
|
|
2019-09-08 12:45:25 +02:00
|
|
|
auto cheerOpt = this->twitchChannel->cheerEmote(string);
|
2019-12-19 21:36:02 +01:00
|
|
|
|
2019-09-08 12:45:25 +02:00
|
|
|
if (!cheerOpt)
|
|
|
|
{
|
|
|
|
return Failure;
|
|
|
|
}
|
2019-12-19 21:36:02 +01:00
|
|
|
|
2019-09-08 18:01:38 +02:00
|
|
|
auto &cheerEmote = *cheerOpt;
|
2019-12-19 21:36:02 +01:00
|
|
|
auto match = cheerEmote.regex.match(string);
|
|
|
|
|
|
|
|
if (!match.hasMatch())
|
|
|
|
{
|
|
|
|
return Failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cheerValue = match.captured(1).toInt();
|
|
|
|
|
2019-12-21 10:36:46 +01:00
|
|
|
if (getSettings()->stackBits)
|
|
|
|
{
|
|
|
|
if (this->bitsStacked)
|
|
|
|
{
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
if (cheerEmote.staticEmote)
|
|
|
|
{
|
|
|
|
this->emplace<EmoteElement>(cheerEmote.staticEmote,
|
|
|
|
MessageElementFlag::BitsStatic);
|
|
|
|
}
|
|
|
|
if (cheerEmote.animatedEmote)
|
|
|
|
{
|
|
|
|
this->emplace<EmoteElement>(cheerEmote.animatedEmote,
|
|
|
|
MessageElementFlag::BitsAnimated);
|
|
|
|
}
|
|
|
|
if (cheerEmote.color != QColor())
|
|
|
|
{
|
|
|
|
this->emplace<TextElement>(QString::number(this->bitsLeft),
|
|
|
|
MessageElementFlag::BitsAmount,
|
|
|
|
cheerEmote.color);
|
|
|
|
}
|
|
|
|
this->bitsStacked = true;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
2019-12-19 21:36:02 +01:00
|
|
|
if (this->bitsLeft >= cheerValue)
|
|
|
|
{
|
|
|
|
this->bitsLeft -= cheerValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString newString = string;
|
|
|
|
newString.chop(QString::number(cheerValue).length());
|
|
|
|
newString += QString::number(cheerValue - this->bitsLeft);
|
|
|
|
|
|
|
|
return tryParseCheermote(newString);
|
|
|
|
}
|
|
|
|
|
2019-09-08 18:01:38 +02:00
|
|
|
if (cheerEmote.staticEmote)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2019-09-08 18:01:38 +02:00
|
|
|
this->emplace<EmoteElement>(cheerEmote.staticEmote,
|
2019-09-08 12:45:25 +02:00
|
|
|
MessageElementFlag::BitsStatic);
|
|
|
|
}
|
2019-09-08 18:01:38 +02:00
|
|
|
if (cheerEmote.animatedEmote)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2019-09-08 18:01:38 +02:00
|
|
|
this->emplace<EmoteElement>(cheerEmote.animatedEmote,
|
2019-09-08 12:45:25 +02:00
|
|
|
MessageElementFlag::BitsAnimated);
|
|
|
|
}
|
2019-09-08 18:01:38 +02:00
|
|
|
if (cheerEmote.color != QColor())
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2019-12-19 21:36:02 +01:00
|
|
|
this->emplace<TextElement>(match.captured(1),
|
|
|
|
MessageElementFlag::BitsAmount,
|
2019-09-08 18:01:38 +02:00
|
|
|
cheerEmote.color);
|
2019-09-08 12:45:25 +02:00
|
|
|
}
|
2019-12-19 21:36:02 +01:00
|
|
|
|
2019-09-08 12:45:25 +02:00
|
|
|
return Success;
|
2018-01-12 19:37:11 +01:00
|
|
|
}
|
2019-12-01 13:32:41 +01:00
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
void TwitchMessageBuilder::appendChannelPointRewardMessage(
|
|
|
|
const ChannelPointReward &reward, MessageBuilder *builder)
|
|
|
|
{
|
2020-10-09 17:26:45 +02:00
|
|
|
builder->emplace<TimestampElement>();
|
2020-08-08 15:37:22 +02:00
|
|
|
QString redeemed = "Redeemed";
|
|
|
|
if (!reward.isUserInputRequired)
|
|
|
|
{
|
|
|
|
builder->emplace<TextElement>(
|
|
|
|
reward.user.login, MessageElementFlag::ChannelPointReward,
|
|
|
|
MessageColor::Text, FontStyle::ChatMediumBold);
|
|
|
|
redeemed = "redeemed";
|
|
|
|
}
|
|
|
|
builder->emplace<TextElement>(redeemed,
|
|
|
|
MessageElementFlag::ChannelPointReward);
|
|
|
|
builder->emplace<TextElement>(
|
|
|
|
reward.title, MessageElementFlag::ChannelPointReward,
|
|
|
|
MessageColor::Text, FontStyle::ChatMediumBold);
|
|
|
|
builder->emplace<ScalingImageElement>(
|
2020-08-09 11:50:53 +02:00
|
|
|
reward.image, MessageElementFlag::ChannelPointRewardImage);
|
2020-08-08 15:37:22 +02:00
|
|
|
builder->emplace<TextElement>(
|
|
|
|
QString::number(reward.cost), MessageElementFlag::ChannelPointReward,
|
|
|
|
MessageColor::Text, FontStyle::ChatMediumBold);
|
|
|
|
if (reward.isUserInputRequired)
|
|
|
|
{
|
|
|
|
builder->emplace<LinebreakElement>(
|
|
|
|
MessageElementFlag::ChannelPointReward);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder->message().flags.set(MessageFlag::RedeemedChannelPointReward);
|
|
|
|
}
|
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|