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/highlights/HighlightController.hpp"
|
|
|
|
#include "controllers/ignores/IgnoreController.hpp"
|
|
|
|
#include "debug/Log.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "messages/Message.hpp"
|
2018-09-01 14:33:27 +02:00
|
|
|
#include "providers/LinkResolver.hpp"
|
2018-09-16 17:27:51 +02:00
|
|
|
#include "providers/chatterino/ChatterinoBadges.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"
|
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>
|
|
|
|
#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
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
TwitchMessageBuilder::TwitchMessageBuilder(
|
|
|
|
Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
|
|
|
|
const MessageParseArgs &_args)
|
2017-07-02 18:12:11 +02:00
|
|
|
: channel(_channel)
|
2017-12-31 00:50:07 +01:00
|
|
|
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
2017-07-02 18:12:11 +02:00
|
|
|
, ircMessage(_ircMessage)
|
|
|
|
, args(_args)
|
|
|
|
, tags(this->ircMessage->tags())
|
2018-07-06 19:23:47 +02:00
|
|
|
, originalMessage_(_ircMessage->content())
|
|
|
|
, action_(_ircMessage->isAction())
|
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)
|
2018-02-04 16:33:46 +01:00
|
|
|
: channel(_channel)
|
|
|
|
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
|
|
|
, ircMessage(_ircMessage)
|
|
|
|
, args(_args)
|
|
|
|
, tags(this->ircMessage->tags())
|
2018-07-06 19:23:47 +02:00
|
|
|
, originalMessage_(content)
|
|
|
|
, action_(isAction)
|
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
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-05-13 19:24:32 +02:00
|
|
|
// TODO(pajlada): Do we need to check if the phrase is valid first?
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &phrase : app->ignores->phrases.getVector())
|
|
|
|
{
|
|
|
|
if (phrase.isBlock() && phrase.isMatch(this->originalMessage_))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
log("Blocking message because it contains ignored phrase {}",
|
|
|
|
phrase.getPattern());
|
2018-01-23 21:33:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
log("Blocking message because it's from blocked user {}",
|
|
|
|
user.name);
|
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
|
|
|
}
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
MessagePtr TwitchMessageBuilder::build()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
// PARSING
|
2017-08-12 13:18:48 +02:00
|
|
|
this->parseUsername();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-09 18:31:38 +02:00
|
|
|
this->message().flags.set(MessageFlag::Collapsed);
|
2017-12-19 00:09:38 +01:00
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
// PARSING
|
|
|
|
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
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
this->appendChannelName();
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
// timestamp
|
2017-12-27 01:22:12 +01:00
|
|
|
bool isPastMsg = this->tags.contains("historical");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (isPastMsg)
|
|
|
|
{
|
2017-12-27 01:22:12 +01:00
|
|
|
// This may be architecture dependent(datatype)
|
|
|
|
qint64 ts = this->tags.value("tmi-sent-ts").toLongLong();
|
2018-01-11 20:16:25 +01:00
|
|
|
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(ts);
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<TimestampElement>(dateTime.time());
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<TimestampElement>();
|
2017-12-27 01:22:12 +01:00
|
|
|
}
|
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();
|
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
|
|
|
|
|
|
|
// highlights
|
2018-07-08 11:43:44 +02:00
|
|
|
this->parseHighlights(isPastMsg);
|
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;
|
|
|
|
// bits = iterator.value().toString();
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// twitch emotes
|
2018-09-23 20:21:50 +02:00
|
|
|
std::vector<std::tuple<int, EmotePtr, EmoteName>> 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('/');
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (QString emote : emoteString)
|
|
|
|
{
|
2018-09-19 13:34:20 +02:00
|
|
|
this->appendTwitchEmote(emote, twitchEmotes);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2018-09-23 20:21:50 +02:00
|
|
|
}
|
|
|
|
auto app = getApp();
|
|
|
|
const auto &phrases = app->ignores->phrases.getVector();
|
|
|
|
auto removeEmotesInRange =
|
|
|
|
[](int pos, int len,
|
2018-09-30 13:37:39 +02:00
|
|
|
std::vector<std::tuple<int, EmotePtr, EmoteName>>
|
|
|
|
&twitchEmotes) mutable {
|
|
|
|
auto it =
|
|
|
|
std::partition(twitchEmotes.begin(), twitchEmotes.end(),
|
|
|
|
[pos, len](const auto &item) {
|
|
|
|
return !((std::get<0>(item) >= pos) &&
|
|
|
|
std::get<0>(item) < (pos + len));
|
|
|
|
});
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto copy = it; copy != twitchEmotes.end(); ++copy)
|
|
|
|
{
|
|
|
|
if (std::get<1>(*copy) == nullptr)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
log("remem nullptr {}", std::get<2>(*copy).string);
|
|
|
|
}
|
|
|
|
}
|
2018-09-30 13:37:39 +02:00
|
|
|
std::vector<std::tuple<int, EmotePtr, EmoteName>> v(
|
|
|
|
it, twitchEmotes.end());
|
2018-09-23 20:21:50 +02:00
|
|
|
twitchEmotes.erase(it, twitchEmotes.end());
|
|
|
|
return v;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto shiftIndicesAfter = [&twitchEmotes](int pos, int by) mutable {
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &item : twitchEmotes)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
auto &index = std::get<0>(item);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (index >= pos)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
index += by;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase,
|
|
|
|
const QStringRef &midrepl,
|
2018-09-23 20:21:50 +02:00
|
|
|
int startIndex) mutable {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!phrase.containsEmote())
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QStringRef> words = midrepl.split(' ');
|
|
|
|
int pos = 0;
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &word : words)
|
|
|
|
{
|
|
|
|
for (const auto &emote : phrase.getEmotes())
|
|
|
|
{
|
|
|
|
if (word == emote.first.string)
|
|
|
|
{
|
|
|
|
if (emote.second == nullptr)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
log("emote null {}", emote.first.string);
|
|
|
|
}
|
|
|
|
twitchEmotes.push_back(std::tuple<int, EmotePtr, EmoteName>{
|
|
|
|
startIndex + pos, emote.second, emote.first});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos += word.length() + 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &phrase : phrases)
|
|
|
|
{
|
|
|
|
if (phrase.isBlock())
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (phrase.isRegex())
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
const auto ®ex = phrase.getRegex();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!regex.isValid())
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QRegularExpressionMatch match;
|
|
|
|
int from = 0;
|
2018-09-30 13:37:39 +02:00
|
|
|
while ((from = this->originalMessage_.indexOf(regex, from,
|
2018-10-21 13:43:02 +02:00
|
|
|
&match)) != -1)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
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;
|
2018-10-21 13:43:02 +02:00
|
|
|
while (pos1 > 0)
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos1 - 1] == ' ')
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
--pos1;
|
|
|
|
}
|
|
|
|
int pos2 = from + midsize;
|
2018-10-21 13:43:02 +02:00
|
|
|
while (pos2 < this->originalMessage_.length())
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos2] == ' ')
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++pos2;
|
|
|
|
}
|
|
|
|
|
|
|
|
shiftIndicesAfter(from + len, midsize - len);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
auto midExtendedRef =
|
|
|
|
this->originalMessage_.midRef(pos1, pos2 - pos1);
|
2018-09-23 20:21:50 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &tup : vret)
|
|
|
|
{
|
|
|
|
if (std::get<1>(tup) == nullptr)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
log("v nullptr {}", std::get<2>(tup).string);
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-07 13:18:45 +02:00
|
|
|
QRegularExpression emoteregex(
|
|
|
|
"\\b" + std::get<2>(tup).string + "\\b",
|
|
|
|
QRegularExpression::UseUnicodePropertiesOption);
|
|
|
|
auto match = emoteregex.match(midExtendedRef);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (match.hasMatch())
|
|
|
|
{
|
2018-10-07 13:18:45 +02:00
|
|
|
int last = match.lastCapturedIndex();
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i <= last; ++i)
|
|
|
|
{
|
2018-10-07 13:18:45 +02:00
|
|
|
std::get<0>(tup) = from + match.capturedStart();
|
|
|
|
twitchEmotes.push_back(std::move(tup));
|
|
|
|
}
|
2018-09-23 20:21:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addReplEmotes(phrase, midExtendedRef, pos1);
|
|
|
|
|
|
|
|
from += midsize;
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
const auto &pattern = phrase.getPattern();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (pattern.isEmpty())
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int from = 0;
|
2018-09-30 13:37:39 +02:00
|
|
|
while ((from = this->originalMessage_.indexOf(
|
2018-10-21 13:43:02 +02:00
|
|
|
pattern, from, phrase.caseSensitivity())) != -1)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
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;
|
2018-10-21 13:43:02 +02:00
|
|
|
while (pos1 > 0)
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos1 - 1] == ' ')
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
--pos1;
|
|
|
|
}
|
|
|
|
int pos2 = from + replacesize;
|
2018-10-21 13:43:02 +02:00
|
|
|
while (pos2 < this->originalMessage_.length())
|
|
|
|
{
|
|
|
|
if (this->originalMessage_[pos2] == ' ')
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++pos2;
|
|
|
|
}
|
|
|
|
|
|
|
|
shiftIndicesAfter(from + len, replacesize - len);
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
auto midExtendedRef =
|
|
|
|
this->originalMessage_.midRef(pos1, pos2 - pos1);
|
2018-09-23 20:21:50 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &tup : vret)
|
|
|
|
{
|
|
|
|
if (std::get<1>(tup) == nullptr)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
log("v nullptr {}", std::get<2>(tup).string);
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-07 13:18:45 +02:00
|
|
|
QRegularExpression emoteregex(
|
|
|
|
"\\b" + std::get<2>(tup).string + "\\b",
|
|
|
|
QRegularExpression::UseUnicodePropertiesOption);
|
|
|
|
auto match = emoteregex.match(midExtendedRef);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (match.hasMatch())
|
|
|
|
{
|
2018-10-07 13:18:45 +02:00
|
|
|
int last = match.lastCapturedIndex();
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i <= last; ++i)
|
|
|
|
{
|
2018-10-07 13:18:45 +02:00
|
|
|
std::get<0>(tup) = from + match.capturedStart();
|
|
|
|
twitchEmotes.push_back(std::move(tup));
|
|
|
|
}
|
2018-09-23 20:21:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addReplEmotes(phrase, midExtendedRef, pos1);
|
|
|
|
|
|
|
|
from += replacesize;
|
|
|
|
}
|
|
|
|
}
|
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) {
|
|
|
|
return std::get<0>(a) < std::get<0>(b);
|
|
|
|
});
|
2018-09-23 20:21:50 +02:00
|
|
|
twitchEmotes.erase(std::unique(twitchEmotes.begin(), twitchEmotes.end(),
|
|
|
|
[](const auto &first, const auto &second) {
|
2018-09-30 13:37:39 +02:00
|
|
|
return std::get<0>(first) ==
|
|
|
|
std::get<0>(second);
|
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
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
this->message().searchText = this->userName + ": " + this->originalMessage_;
|
2018-08-02 14:23:27 +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
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
void TwitchMessageBuilder::addWords(
|
2018-09-30 13:37:39 +02:00
|
|
|
const QStringList &words,
|
|
|
|
const std::vector<std::tuple<int, EmotePtr, EmoteName>> &twitchEmotes)
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
|
|
|
auto i = int();
|
|
|
|
auto currentTwitchEmote = twitchEmotes.begin();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &word : words)
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
// check if it's a twitch emote twitch emote
|
2018-09-30 13:37:39 +02:00
|
|
|
while (currentTwitchEmote != twitchEmotes.end() &&
|
2018-10-21 13:43:02 +02:00
|
|
|
std::get<0>(*currentTwitchEmote) < i)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
++currentTwitchEmote;
|
|
|
|
}
|
2018-09-30 13:37:39 +02:00
|
|
|
if (currentTwitchEmote != twitchEmotes.end() &&
|
2018-10-21 13:43:02 +02:00
|
|
|
std::get<0>(*currentTwitchEmote) == i)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
auto emoteImage = std::get<1>(*currentTwitchEmote);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (emoteImage == nullptr)
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
log("emoteImage nullptr {}",
|
|
|
|
std::get<2>(*currentTwitchEmote).string);
|
2018-09-23 20:21:50 +02:00
|
|
|
}
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<EmoteElement>(emoteImage,
|
|
|
|
MessageElementFlag::TwitchEmote);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
i += word.length() + 1;
|
|
|
|
currentTwitchEmote++;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split words
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &variant : getApp()->emotes->emojis.parse(word))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
boost::apply_visitor([&](auto &&arg) { this->addTextOrEmoji(arg); },
|
|
|
|
variant);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int j = 0; j < word.size(); j++)
|
|
|
|
{
|
2017-08-17 22:46:16 +02:00
|
|
|
i++;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (word.at(j).isHighSurrogate())
|
|
|
|
{
|
2017-08-17 22:46:16 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-08-17 22:46:16 +02:00
|
|
|
i++;
|
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)
|
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
this->emplace<EmoteElement>(emote, MessageElementFlag::EmojiAll);
|
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);
|
|
|
|
auto link = Link();
|
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
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (linkString.isEmpty())
|
|
|
|
{
|
|
|
|
if (string.startsWith('@'))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
|
|
|
|
textColor, FontStyle::ChatMediumBold);
|
|
|
|
this->emplace<TextElement>(
|
|
|
|
string, MessageElementFlag::NonBoldUsername, textColor);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(string, MessageElementFlag::Text,
|
|
|
|
textColor);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 18:41:30 +02:00
|
|
|
static QRegularExpression domainRegex(
|
2018-10-08 14:26:42 +02:00
|
|
|
R"(^(?:(?:ftp|http)s?:\/\/)?([^\/]+)(?:\/.*)?$)",
|
2018-08-06 18:41:30 +02:00
|
|
|
QRegularExpression::CaseInsensitiveOption);
|
|
|
|
|
|
|
|
QString lowercaseLinkString;
|
|
|
|
auto match = domainRegex.match(string);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (match.isValid())
|
|
|
|
{
|
2018-08-06 18:41:30 +02:00
|
|
|
lowercaseLinkString = string.mid(0, match.capturedStart(1)) +
|
2018-09-30 13:37:39 +02:00
|
|
|
match.captured(1).toLower() +
|
|
|
|
string.mid(match.capturedEnd(1));
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 18:41:30 +02:00
|
|
|
lowercaseLinkString = string;
|
2017-08-17 22:46:16 +02:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
link = Link(Link::Url, linkString);
|
2017-08-17 22:46:16 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
textColor = MessageColor(MessageColor::Link);
|
2018-09-01 14:33:27 +02:00
|
|
|
auto linkMELowercase =
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(lowercaseLinkString,
|
|
|
|
MessageElementFlag::LowercaseLink,
|
2018-09-01 14:33:27 +02:00
|
|
|
textColor)
|
|
|
|
->setLink(link);
|
|
|
|
auto linkMEOriginal =
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<TextElement>(string, MessageElementFlag::OriginalLink,
|
|
|
|
textColor)
|
2018-09-01 14:33:27 +02:00
|
|
|
->setLink(link);
|
2018-08-24 11:56:42 +02:00
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
LinkResolver::getLinkInfo(
|
2018-10-24 11:36:36 +02:00
|
|
|
linkString,
|
|
|
|
[weakMessage = this->weakOf(), linkMELowercase, linkMEOriginal,
|
|
|
|
linkString](QString tooltipText, Link originalLink) {
|
|
|
|
auto shared = weakMessage.lock();
|
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!tooltipText.isEmpty())
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
linkMELowercase->setTooltip(tooltipText);
|
|
|
|
linkMEOriginal->setTooltip(tooltipText);
|
|
|
|
}
|
|
|
|
if (originalLink.value != linkString &&
|
2018-10-21 13:43:02 +02:00
|
|
|
!originalLink.value.isEmpty())
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
linkMELowercase->setLink(originalLink)->updateLink();
|
|
|
|
linkMEOriginal->setLink(originalLink)->updateLink();
|
|
|
|
}
|
|
|
|
});
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 18:41:30 +02:00
|
|
|
// if (!linkString.isEmpty()) {
|
2018-08-12 12:56:28 +02:00
|
|
|
// if (getSettings()->lowercaseLink) {
|
2018-08-06 18:41:30 +02:00
|
|
|
// QRegularExpression httpRegex("\\bhttps?://",
|
2018-08-06 21:17:03 +02:00
|
|
|
// QRegularExpression::CaseInsensitiveOption); QRegularExpression
|
|
|
|
// ftpRegex("\\bftps?://",
|
2018-08-06 18:41:30 +02:00
|
|
|
// QRegularExpression::CaseInsensitiveOption); QRegularExpression
|
|
|
|
// getDomain("\\/\\/([^\\/]*)"); QString tempString = string;
|
|
|
|
|
|
|
|
// if (!string.contains(httpRegex)) {
|
|
|
|
// if (!string.contains(ftpRegex)) {
|
|
|
|
// tempString.insert(0, "http://");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// QString domain = getDomain.match(tempString).captured(1);
|
|
|
|
// string.replace(domain, domain.toLower());
|
|
|
|
// }
|
|
|
|
// link = Link(Link::Url, linkString);
|
|
|
|
// textColor = MessageColor(MessageColor::Link);
|
|
|
|
//}
|
|
|
|
// if (string.startsWith('@')) {
|
2018-08-07 07:55:31 +02:00
|
|
|
// this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
|
2018-08-06 21:17:03 +02:00
|
|
|
// textColor,
|
2018-08-06 18:41:30 +02:00
|
|
|
// FontStyle::ChatMediumBold) //
|
|
|
|
// ->setLink(link);
|
2018-08-07 07:55:31 +02:00
|
|
|
// this->emplace<TextElement>(string,
|
|
|
|
// MessageElementFlag::NonBoldUsername,
|
2018-08-06 18:41:30 +02:00
|
|
|
// textColor) //
|
|
|
|
// ->setLink(link);
|
|
|
|
//} else {
|
2018-08-07 07:55:31 +02:00
|
|
|
// this->emplace<TextElement>(string, MessageElementFlag::Text,
|
|
|
|
// textColor) //
|
2018-08-06 18:41:30 +02:00
|
|
|
// ->setLink(link);
|
|
|
|
//}
|
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())
|
|
|
|
{
|
2017-07-02 18:12:11 +02:00
|
|
|
this->messageID = iterator.value().toString();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 23:28:06 +01:00
|
|
|
void TwitchMessageBuilder::appendChannelName()
|
2017-07-02 18:12:11 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
QString channelName("#" + this->channel->getName());
|
|
|
|
Link link(Link::Url, this->channel->getName() + "\n" + this->messageID);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
this->emplace<TextElement>(channelName, MessageElementFlag::ChannelName,
|
2018-08-06 21:17:03 +02:00
|
|
|
MessageColor::System) //
|
2018-01-11 20:16:25 +01:00
|
|
|
->setLink(link);
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchMessageBuilder::parseUsername()
|
|
|
|
{
|
|
|
|
auto iterator = this->tags.find("color");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator != this->tags.end())
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->usernameColor_ = QColor(iterator.value().toString());
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// username
|
2018-02-04 16:33:46 +01:00
|
|
|
this->userName = this->ircMessage->nick();
|
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;
|
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())
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
case UsernameDisplayMode::LocalizedName:
|
|
|
|
{
|
|
|
|
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:
|
2018-10-21 13:43:02 +02:00
|
|
|
case UsernameDisplayMode::UsernameAndLocalizedName:
|
|
|
|
{
|
|
|
|
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 +=
|
|
|
|
// IrcManager::getInstance().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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-08 11:43:44 +02:00
|
|
|
void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
2017-07-31 01:19:25 +02:00
|
|
|
{
|
|
|
|
static auto player = new QMediaPlayer;
|
2017-12-18 17:57:56 +01:00
|
|
|
static QUrl currentPlayerUrl;
|
2018-04-27 22:11:19 +02:00
|
|
|
|
|
|
|
auto app = getApp();
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
auto currentUser = app->accounts->twitch.getCurrent();
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
QString currentUsername = currentUser->getUserName();
|
2017-08-19 15:37:56 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ircMessage->nick() == currentUsername)
|
|
|
|
{
|
2018-08-11 17:35:46 +02:00
|
|
|
currentUser->setColor(this->usernameColor_);
|
2017-07-31 01:19:25 +02:00
|
|
|
// Do nothing. Highlights cannot be triggered by yourself
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-18 17:57:56 +01:00
|
|
|
// update the media player url if necessary
|
|
|
|
QUrl highlightSoundUrl;
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getSettings()->customHighlightSound)
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
highlightSoundUrl =
|
|
|
|
QUrl::fromLocalFile(getSettings()->pathHighlightSound.getValue());
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-18 17:57:56 +01:00
|
|
|
highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav");
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (currentPlayerUrl != highlightSoundUrl)
|
|
|
|
{
|
2017-12-18 17:57:56 +01:00
|
|
|
player->setMedia(highlightSoundUrl);
|
|
|
|
|
|
|
|
currentPlayerUrl = highlightSoundUrl;
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This vector should only be rebuilt upon highlights being changed
|
2018-05-06 00:32:45 +02:00
|
|
|
// fourtf: should be implemented in the HighlightsController
|
2018-09-30 13:37:39 +02:00
|
|
|
std::vector<HighlightPhrase> activeHighlights =
|
|
|
|
app->highlights->phrases.getVector();
|
|
|
|
std::vector<HighlightPhrase> userHighlights =
|
|
|
|
app->highlights->highlightedUsers.getVector();
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getSettings()->enableSelfHighlight && currentUsername.size() > 0)
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
HighlightPhrase selfHighlight(
|
|
|
|
currentUsername, getSettings()->enableSelfHighlightTaskbar,
|
|
|
|
getSettings()->enableSelfHighlightSound, false);
|
2018-01-04 01:52:37 +01:00
|
|
|
activeHighlights.emplace_back(std::move(selfHighlight));
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
|
2017-07-31 11:08:32 +02:00
|
|
|
bool doHighlight = false;
|
2017-07-31 01:19:25 +02:00
|
|
|
bool playSound = false;
|
|
|
|
bool doAlert = false;
|
2017-10-08 15:58:28 +02:00
|
|
|
|
|
|
|
bool hasFocus = (QApplication::focusWidget() != nullptr);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!app->highlights->blacklistContains(this->ircMessage->nick()))
|
|
|
|
{
|
|
|
|
for (const HighlightPhrase &highlight : activeHighlights)
|
|
|
|
{
|
|
|
|
if (highlight.isMatch(this->originalMessage_))
|
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("Highlight because {} matches {}", this->originalMessage_,
|
2018-06-26 17:06:17 +02:00
|
|
|
highlight.getPattern());
|
2017-09-23 19:23:10 +02:00
|
|
|
doHighlight = true;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (highlight.getAlert())
|
|
|
|
{
|
2018-05-06 12:52:47 +02:00
|
|
|
doAlert = true;
|
2017-09-23 19:23:10 +02:00
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (highlight.getSound())
|
|
|
|
{
|
2018-05-06 12:52:47 +02:00
|
|
|
playSound = true;
|
2017-09-23 19:23:10 +02:00
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (playSound && doAlert)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
// Break if no further action can be taken from other
|
|
|
|
// highlights This might change if highlights can have
|
|
|
|
// custom colors/sounds/actions
|
2017-09-23 19:23:10 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const HighlightPhrase &userHighlight : userHighlights)
|
|
|
|
{
|
|
|
|
if (userHighlight.isMatch(this->ircMessage->nick()))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
log("Highlight because user {} sent a message",
|
|
|
|
this->ircMessage->nick());
|
2018-07-05 15:58:20 +02:00
|
|
|
doHighlight = true;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (userHighlight.getAlert())
|
|
|
|
{
|
2018-07-05 15:58:20 +02:00
|
|
|
doAlert = true;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (userHighlight.getSound())
|
|
|
|
{
|
2018-07-05 15:58:20 +02:00
|
|
|
playSound = true;
|
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (playSound && doAlert)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
// Break if no further action can be taken from other
|
|
|
|
// usernames Mostly used for regex stuff
|
2018-07-05 15:58:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-30 13:37:39 +02:00
|
|
|
if (this->args.isReceivedWhisper &&
|
2018-10-21 13:43:02 +02:00
|
|
|
getSettings()->enableWhisperHighlight)
|
|
|
|
{
|
|
|
|
if (getSettings()->enableWhisperHighlightTaskbar)
|
|
|
|
{
|
2018-08-29 01:21:36 +02:00
|
|
|
doAlert = true;
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getSettings()->enableWhisperHighlightSound)
|
|
|
|
{
|
2018-08-29 01:21:36 +02:00
|
|
|
playSound = true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
this->message().flags.set(MessageFlag::Highlighted, doHighlight);
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!isPastMsg)
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
if (playSound &&
|
2018-10-21 13:43:02 +02:00
|
|
|
(!hasFocus || getSettings()->highlightAlwaysPlaySound))
|
|
|
|
{
|
2018-07-08 11:43:44 +02:00
|
|
|
player->play();
|
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (doAlert)
|
|
|
|
{
|
2018-10-07 12:55:44 +02:00
|
|
|
getApp()->windows->sendAlert();
|
2018-07-08 11:43:44 +02:00
|
|
|
}
|
2017-09-23 19:23:10 +02:00
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
void TwitchMessageBuilder::appendTwitchEmote(
|
|
|
|
const QString &emote,
|
|
|
|
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec)
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
auto start = coords.at(0).toInt();
|
|
|
|
auto end = coords.at(1).toInt();
|
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)};
|
2018-09-23 20:21:50 +02:00
|
|
|
auto tup = std::tuple<int, EmotePtr, EmoteName>{
|
|
|
|
start, app->emotes->twitch.getOrCreateEmote(id, name), name};
|
2018-10-21 13:43:02 +02:00
|
|
|
if (std::get<1>(tup) == nullptr)
|
|
|
|
{
|
2018-09-23 20:21:50 +02:00
|
|
|
log("nullptr {}", std::get<2>(tup).string);
|
|
|
|
}
|
|
|
|
vec.push_back(std::move(tup));
|
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
|
|
|
{
|
2018-08-25 12:23:58 +02:00
|
|
|
// Special channels, like /whispers and /channels return here
|
|
|
|
// This means they will not render any BTTV or FFZ emotes
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->twitchChannel == nullptr)
|
|
|
|
{
|
2018-08-25 12:23:58 +02:00
|
|
|
return Failure;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
auto flags = MessageElementFlags();
|
2018-08-02 14:23:27 +02:00
|
|
|
auto emote = boost::optional<EmotePtr>{};
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if ((emote = this->twitchChannel->globalBttv().emote(name)))
|
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
flags = MessageElementFlag::BttvEmote;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if ((emote = this->twitchChannel->bttvEmote(name)))
|
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
flags = MessageElementFlag::BttvEmote;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if ((emote = this->twitchChannel->globalFfz().emote(name)))
|
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
flags = MessageElementFlag::FfzEmote;
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if ((emote = this->twitchChannel->ffzEmote(name)))
|
|
|
|
{
|
2018-08-07 07:55:31 +02:00
|
|
|
flags = MessageElementFlag::FfzEmote;
|
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
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// fourtf: this is ugly
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
auto iterator = this->tags.find("badges");
|
2018-10-21 13:43:02 +02:00
|
|
|
if (iterator == this->tags.end())
|
|
|
|
return;
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (QString badge : iterator.value().toString().split(','))
|
|
|
|
{
|
|
|
|
if (badge.startsWith("bits/"))
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
QString cheerAmount = badge.mid(5);
|
|
|
|
QString tooltip = QString("Twitch cheer ") + cheerAmount;
|
2017-06-15 23:13:01 +02:00
|
|
|
|
2018-01-12 22:38:00 +01:00
|
|
|
// Try to fetch channel-specific bit badge
|
2018-10-21 13:43:02 +02:00
|
|
|
try
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
if (twitchChannel)
|
2018-09-30 13:37:39 +02:00
|
|
|
if (const auto &badge = this->twitchChannel->twitchBadge(
|
2018-10-21 13:43:02 +02:00
|
|
|
"bits", cheerAmount))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<EmoteElement>(
|
|
|
|
badge.get(), MessageElementFlag::BadgeVanity)
|
2018-08-02 14:23:27 +02:00
|
|
|
->setTooltip(tooltip);
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
catch (const std::out_of_range &)
|
|
|
|
{
|
2018-01-12 22:38:00 +01:00
|
|
|
// Channel does not contain a special bit badge for this version
|
|
|
|
}
|
2017-06-16 08:03:13 +02:00
|
|
|
|
2018-01-12 22:38:00 +01:00
|
|
|
// Use default bit badge
|
2018-09-30 13:37:39 +02:00
|
|
|
if (auto badge = this->twitchChannel->globalTwitchBadges().badge(
|
2018-10-21 13:43:02 +02:00
|
|
|
"bits", cheerAmount))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<EmoteElement>(badge.get(),
|
|
|
|
MessageElementFlag::BadgeVanity)
|
2018-08-14 17:45:17 +02:00
|
|
|
->setTooltip(tooltip);
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "staff/1")
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.staff),
|
|
|
|
MessageElementFlag::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Staff");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "admin/1")
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.admin),
|
|
|
|
MessageElementFlag::BadgeGlobalAuthority)
|
2018-08-06 21:17:03 +02:00
|
|
|
->setTooltip("Twitch Admin");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "global_mod/1")
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.globalmod),
|
|
|
|
MessageElementFlag::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Global Moderator");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "moderator/1")
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
// TODO: Implement custom FFZ moderator badge
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.moderator),
|
|
|
|
MessageElementFlag::BadgeChannelAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Channel Moderator");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "turbo/1")
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.turbo),
|
|
|
|
MessageElementFlag::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Turbo Subscriber");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "broadcaster/1")
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.broadcaster),
|
|
|
|
MessageElementFlag::BadgeChannelAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Broadcaster");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge == "premium/1")
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.prime),
|
|
|
|
MessageElementFlag::BadgeVanity)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Prime Subscriber");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge.startsWith("partner/"))
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
int index = badge.midRef(8).toInt();
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
this->emplace<ImageElement>(
|
2018-09-30 13:37:39 +02:00
|
|
|
Image::fromPixmap(app->resources->twitch.verified,
|
|
|
|
0.25),
|
2018-08-07 07:55:31 +02:00
|
|
|
MessageElementFlag::BadgeVanity)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Verified");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
printf("[TwitchMessageBuilder] Unhandled partner badge "
|
|
|
|
"index: %d\n",
|
|
|
|
index);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-13 22:03:29 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else if (badge.startsWith("subscriber/"))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
if (auto badgeEmote = this->twitchChannel->twitchBadge(
|
2018-10-21 13:43:02 +02:00
|
|
|
"subscriber", badge.mid(11)))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<EmoteElement>(
|
|
|
|
badgeEmote.get(), MessageElementFlag::BadgeSubscription)
|
2018-08-14 17:45:17 +02:00
|
|
|
->setTooltip((*badgeEmote)->tooltip.string);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use default subscriber badge if custom one not found
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<ImageElement>(
|
|
|
|
Image::fromPixmap(app->resources->twitch.subscriber, 0.25),
|
|
|
|
MessageElementFlag::BadgeSubscription)
|
2018-08-14 17:45:17 +02:00
|
|
|
->setTooltip("Twitch Subscriber");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-14 17:45:17 +02:00
|
|
|
auto splits = badge.split('/');
|
2018-10-21 13:43:02 +02:00
|
|
|
if (splits.size() != 2)
|
|
|
|
continue;
|
2018-08-14 17:45:17 +02:00
|
|
|
|
2018-09-30 13:37:39 +02:00
|
|
|
if (auto badgeEmote =
|
2018-10-21 13:43:02 +02:00
|
|
|
this->twitchChannel->twitchBadge(splits[0], splits[1]))
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<EmoteElement>(badgeEmote.get(),
|
|
|
|
MessageElementFlag::BadgeVanity)
|
2018-08-14 17:45:17 +02:00
|
|
|
->setTooltip((*badgeEmote)->tooltip.string);
|
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
auto chatterinoBadgePtr =
|
|
|
|
getApp()->chatterinoBadges->getBadge({this->userName});
|
2018-10-21 13:43:02 +02:00
|
|
|
if (chatterinoBadgePtr)
|
|
|
|
{
|
2018-09-30 13:37:39 +02:00
|
|
|
this->emplace<EmoteElement>(*chatterinoBadgePtr,
|
|
|
|
MessageElementFlag::BadgeChatterino);
|
2018-09-16 17:27:51 +02:00
|
|
|
}
|
2017-08-12 13:20:52 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
|
2018-01-12 19:37:11 +01:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
// auto app = getApp();
|
|
|
|
//// Try to parse custom cheermotes
|
|
|
|
// const auto &channelResources = app->resources->channels[this->roomID_];
|
|
|
|
// if (channelResources.loaded) {
|
|
|
|
// for (const auto &cheermoteSet : channelResources.cheermoteSets) {
|
|
|
|
// auto match = cheermoteSet.regex.match(string);
|
|
|
|
// if (!match.hasMatch()) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// QString amount = match.captured(1);
|
|
|
|
// bool ok = false;
|
|
|
|
// int numBits = amount.toInt(&ok);
|
|
|
|
// if (!ok) {
|
|
|
|
// Log("Error parsing bit amount in tryParseCheermote");
|
|
|
|
// return Failure;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// auto savedIt = cheermoteSet.cheermotes.end();
|
|
|
|
|
|
|
|
// // Fetch cheermote that matches our numBits
|
2018-08-06 21:17:03 +02:00
|
|
|
// for (auto it = cheermoteSet.cheermotes.begin(); it !=
|
|
|
|
// cheermoteSet.cheermotes.end();
|
2018-08-02 14:23:27 +02:00
|
|
|
// ++it) {
|
|
|
|
// if (numBits >= it->minBits) {
|
|
|
|
// savedIt = it;
|
|
|
|
// } else {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (savedIt == cheermoteSet.cheermotes.end()) {
|
2018-08-06 21:17:03 +02:00
|
|
|
// Log("Error getting a cheermote from a cheermote set for the
|
|
|
|
// bit amount {}",
|
2018-08-02 14:23:27 +02:00
|
|
|
// numBits);
|
|
|
|
// return Failure;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const auto &cheermote = *savedIt;
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// this->emplace<EmoteElement>(cheermote.animatedEmote,
|
2018-08-07 07:55:31 +02:00
|
|
|
// MessageElementFlag::BitsAnimated);
|
|
|
|
// this->emplace<TextElement>(amount, MessageElementFlag::Text,
|
|
|
|
// cheermote.color);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
|
|
|
// return Success;
|
|
|
|
// }
|
|
|
|
//}
|
2018-01-12 19:37:11 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
return Failure;
|
2018-01-12 19:37:11 +01:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|