2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/twitchmessagebuilder.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
|
|
|
#include "application.hpp"
|
2018-05-26 20:25:00 +02:00
|
|
|
#include "controllers/accounts/accountcontroller.hpp"
|
2018-05-06 00:32:45 +02:00
|
|
|
#include "controllers/highlights/highlightcontroller.hpp"
|
2018-05-13 19:24:32 +02:00
|
|
|
#include "controllers/ignores/ignorecontroller.hpp"
|
2017-09-24 19:23:07 +02:00
|
|
|
#include "debug/log.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/twitchchannel.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/emotemanager.hpp"
|
|
|
|
#include "singletons/ircmanager.hpp"
|
2018-01-01 22:29:21 +01:00
|
|
|
#include "singletons/resourcemanager.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/settingsmanager.hpp"
|
|
|
|
#include "singletons/thememanager.hpp"
|
|
|
|
#include "singletons/windowmanager.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-31 00:37:22 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMediaPlayer>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
using namespace chatterino::messages;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2018-02-05 15:11:50 +01:00
|
|
|
namespace providers {
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace twitch {
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
2017-07-02 18:12:11 +02:00
|
|
|
const Communi::IrcPrivateMessage *_ircMessage,
|
|
|
|
const messages::MessageParseArgs &_args)
|
|
|
|
: 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-02-04 16:33:46 +01:00
|
|
|
, originalMessage(_ircMessage->content())
|
|
|
|
, action(_ircMessage->isAction())
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
this->usernameColor = app->themes->messages.textColors.system;
|
2018-02-04 16:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel,
|
|
|
|
const Communi::IrcMessage *_ircMessage, QString content,
|
|
|
|
const messages::MessageParseArgs &_args)
|
|
|
|
: channel(_channel)
|
|
|
|
, twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
|
|
|
|
, ircMessage(_ircMessage)
|
|
|
|
, args(_args)
|
|
|
|
, tags(this->ircMessage->tags())
|
|
|
|
, originalMessage(content)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
this->usernameColor = app->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?
|
|
|
|
for (const auto &phrase : app->ignores->phrases.getVector()) {
|
|
|
|
if (phrase.isMatch(this->originalMessage)) {
|
|
|
|
debug::Log("Blocking message because it contains ignored phrase {}",
|
|
|
|
phrase.getPattern());
|
2018-01-23 21:33:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 23:34:22 +02:00
|
|
|
if (app->settings->enableTwitchIgnoredUsers && this->tags.contains("user-id")) {
|
2018-05-12 23:27:34 +02:00
|
|
|
auto sourceUserID = this->tags.value("user-id").toString();
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
for (const auto &user : app->accounts->twitch.getCurrent()->getIgnores()) {
|
2018-05-12 23:27:34 +02:00
|
|
|
if (sourceUserID == user.id) {
|
|
|
|
debug::Log("Blocking message because it's from blocked user {}", user.name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 23:34:22 +02:00
|
|
|
if (app->settings->enableTwitchIgnoredUsers && this->tags.contains("user-id")) {
|
2018-05-12 23:27:34 +02:00
|
|
|
auto sourceUserID = this->tags.value("user-id").toString();
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
for (const auto &user : app->accounts->twitch.getCurrent()->getIgnores()) {
|
2018-05-12 23:27:34 +02:00
|
|
|
if (sourceUserID == user.id) {
|
|
|
|
debug::Log("Blocking message because it's from blocked user {}", user.name);
|
|
|
|
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-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// PARSING
|
2017-08-12 13:18:48 +02:00
|
|
|
this->parseUsername();
|
|
|
|
|
2018-05-24 11:35:50 +02:00
|
|
|
//#ifdef XD
|
|
|
|
// if (this->originalMessage.length() > 100) {
|
|
|
|
// this->message->flags |= Message::Collapsed;
|
|
|
|
// this->emplace<EmoteElement>(getApp()->resources->badgeCollapsed,
|
|
|
|
// MessageElement::Collapsed);
|
|
|
|
// }
|
|
|
|
//#endif
|
|
|
|
this->message->flags |= Message::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");
|
2017-12-28 17:56:00 +01: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());
|
2017-12-27 01:22:12 +01: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-01-22 14:39:24 +01: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-04-28 13:48:49 +02:00
|
|
|
if (/*app->settings->enableHighlights &&*/ !isPastMsg) {
|
2017-07-31 01:19:25 +02:00
|
|
|
this->parseHighlights();
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-12 19:37:11 +01:00
|
|
|
QString bits;
|
2017-07-02 18:12:11 +02:00
|
|
|
auto iterator = this->tags.find("bits");
|
|
|
|
if (iterator != this->tags.end()) {
|
2017-04-12 17:46:44 +02:00
|
|
|
bits = iterator.value().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// twitch emotes
|
2017-12-31 22:58:35 +01:00
|
|
|
std::vector<std::pair<long, util::EmoteData>> twitchEmotes;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
iterator = this->tags.find("emotes");
|
|
|
|
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
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
for (QString emote : emoteString) {
|
2017-12-17 02:18:13 +01:00
|
|
|
this->appendTwitchEmote(ircMessage, emote, twitchEmotes);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-05-24 15:42:06 +02:00
|
|
|
std::sort(twitchEmotes.begin(), twitchEmotes.end(),
|
|
|
|
[](const auto &a, const auto &b) { return a.first < b.first; });
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto currentTwitchEmote = twitchEmotes.begin();
|
|
|
|
|
|
|
|
// words
|
|
|
|
|
2017-07-31 01:19:25 +02:00
|
|
|
QStringList splits = this->originalMessage.split(' ');
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
long int i = 0;
|
|
|
|
|
|
|
|
for (QString split : splits) {
|
2018-02-04 16:33:46 +01:00
|
|
|
MessageColor textColor =
|
|
|
|
this->action ? MessageColor(this->usernameColor) : MessageColor(MessageColor::Text);
|
2017-08-12 12:07:53 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// twitch emote
|
|
|
|
if (currentTwitchEmote != twitchEmotes.end() && currentTwitchEmote->first == i) {
|
2018-01-11 20:16:25 +01:00
|
|
|
auto emoteImage = currentTwitchEmote->second;
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<EmoteElement>(emoteImage, MessageElement::TwitchEmote);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
i += split.length() + 1;
|
|
|
|
currentTwitchEmote = std::next(currentTwitchEmote);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split words
|
2017-12-31 22:58:35 +01:00
|
|
|
std::vector<std::tuple<util::EmoteData, QString>> parsed;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-02 17:37:17 +02:00
|
|
|
// Parse emojis and take all non-emojis and put them in parsed as full text-words
|
2018-04-27 22:11:19 +02:00
|
|
|
app->emotes->parseEmojis(parsed, split);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-07-09 17:58:59 +02:00
|
|
|
for (const auto &tuple : parsed) {
|
2017-12-31 22:58:35 +01:00
|
|
|
const util::EmoteData &emoteData = std::get<0>(tuple);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-07 02:56:45 +01:00
|
|
|
if (!emoteData.isValid()) { // is text
|
2017-04-12 17:46:44 +02:00
|
|
|
QString string = std::get<1>(tuple);
|
|
|
|
|
2018-01-12 19:37:11 +01:00
|
|
|
if (!bits.isEmpty() && this->tryParseCheermote(string)) {
|
|
|
|
// This string was parsed as a cheermote
|
2017-04-12 17:46:44 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-26 16:41:20 +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"
|
2017-07-23 09:53:50 +02:00
|
|
|
if (this->tryAppendEmote(string)) {
|
|
|
|
// Successfully appended an emote
|
2017-04-12 17:46:44 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-07-23 09:53:50 +02:00
|
|
|
// Actually just text
|
2017-08-05 18:44:14 +02:00
|
|
|
QString linkString = this->matchLink(string);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-08-12 12:09:26 +02:00
|
|
|
Link link;
|
|
|
|
|
|
|
|
if (linkString.isEmpty()) {
|
|
|
|
link = Link();
|
|
|
|
} else {
|
|
|
|
link = Link(Link::Url, linkString);
|
2017-09-21 00:54:10 +02:00
|
|
|
textColor = MessageColor(MessageColor::Link);
|
2017-08-12 12:09:26 +02:00
|
|
|
}
|
2017-08-05 18:44:14 +02:00
|
|
|
|
2018-01-22 20:14:43 +01:00
|
|
|
this->emplace<TextElement>(string, MessageElement::Text, textColor) //
|
2018-01-11 20:16:25 +01:00
|
|
|
->setLink(link);
|
2017-04-12 17:46:44 +02:00
|
|
|
} else { // is emoji
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<EmoteElement>(emoteData, EmoteElement::EmojiAll);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 22:46:16 +02:00
|
|
|
for (int j = 0; j < split.size(); j++) {
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (split.at(j).isHighSurrogate()) {
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-28 03:29:42 +01:00
|
|
|
this->message->searchText = this->userName + ": " + this->originalMessage;
|
2018-01-17 14:25:03 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
return this->getMessage();
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchMessageBuilder::parseMessageID()
|
|
|
|
{
|
|
|
|
auto iterator = this->tags.find("id");
|
|
|
|
|
|
|
|
if (iterator != this->tags.end()) {
|
|
|
|
this->messageID = iterator.value().toString();
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
void TwitchMessageBuilder::parseRoomID()
|
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
if (this->twitchChannel == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
auto iterator = this->tags.find("room-id");
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
if (iterator != std::end(this->tags)) {
|
2017-11-04 14:57:29 +01:00
|
|
|
this->roomID = iterator.value().toString();
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
if (this->twitchChannel->roomID.isEmpty()) {
|
2017-09-16 00:05:06 +02:00
|
|
|
this->twitchChannel->roomID = 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
|
|
|
{
|
2017-07-23 09:53:50 +02:00
|
|
|
QString channelName("#" + this->channel->name);
|
2018-01-11 20:16:25 +01:00
|
|
|
Link link(Link::Url, this->channel->name + "\n" + this->messageID);
|
|
|
|
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<TextElement>(channelName, MessageElement::ChannelName, 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");
|
|
|
|
if (iterator != this->tags.end()) {
|
|
|
|
this->usernameColor = QColor(iterator.value().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
// username
|
2018-02-04 16:33:46 +01:00
|
|
|
this->userName = this->ircMessage->nick();
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-06-05 14:14:00 +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()) {
|
|
|
|
// this->userName = displayNameVariant.toString() + " (" + this->userName + ")";
|
|
|
|
// }
|
|
|
|
|
2017-12-17 21:05:25 +01: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-01-17 02:46:50 +01: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");
|
2017-07-23 11:59:05 +02:00
|
|
|
if (iterator != this->tags.end()) {
|
|
|
|
QString displayName = iterator.value().toString();
|
|
|
|
|
|
|
|
if (QString::compare(displayName, this->userName, Qt::CaseInsensitive) == 0) {
|
|
|
|
username = displayName;
|
2017-12-17 21:05:25 +01:00
|
|
|
|
|
|
|
this->message->displayName = displayName;
|
2017-07-23 11:59:05 +02:00
|
|
|
} else {
|
|
|
|
localizedName = displayName;
|
2017-12-17 21:05:25 +01: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(
|
|
|
|
"/appearance/messages/usernameDisplayMode", UsernameDisplayMode::UsernameAndLocalizedName);
|
|
|
|
|
|
|
|
switch (usernameDisplayMode.getValue()) {
|
|
|
|
case UsernameDisplayMode::Username: {
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username;
|
2017-07-23 11:59:05 +02:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case UsernameDisplayMode::LocalizedName: {
|
|
|
|
if (hasLocalizedName) {
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = localizedName;
|
2017-07-23 11:59:05 +02:00
|
|
|
} else {
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username;
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case UsernameDisplayMode::UsernameAndLocalizedName: {
|
|
|
|
if (hasLocalizedName) {
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username + "(" + localizedName + ")";
|
2017-07-23 11:59:05 +02:00
|
|
|
} else {
|
2018-01-11 20:16:25 +01:00
|
|
|
usernameText = username;
|
2017-07-23 11:59:05 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
|
|
|
if (this->args.isSentWhisper) {
|
|
|
|
// TODO(pajlada): Re-implement
|
|
|
|
// userDisplayString += IrcManager::getInstance().getUser().getUserName();
|
2018-02-04 16:33:46 +01:00
|
|
|
} else if (this->args.isReceivedWhisper) {
|
|
|
|
// Sender username
|
|
|
|
this->emplace<TextElement>(usernameText, MessageElement::Text, this->usernameColor,
|
2018-05-23 04:22:17 +02:00
|
|
|
FontStyle::ChatMediumBold)
|
2018-02-04 16:33:46 +01:00
|
|
|
->setLink({Link::UserInfo, this->userName});
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
auto currentUser = app->accounts->twitch.getCurrent();
|
2018-02-04 16:33:46 +01:00
|
|
|
|
|
|
|
// Separator
|
2018-04-27 22:11:19 +02:00
|
|
|
this->emplace<TextElement>("->", MessageElement::Text,
|
2018-05-23 04:22:17 +02:00
|
|
|
app->themes->messages.textColors.system, FontStyle::ChatMedium);
|
2018-02-04 16:33:46 +01:00
|
|
|
|
|
|
|
QColor selfColor = currentUser->color;
|
|
|
|
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
|
|
|
|
this->emplace<TextElement>(currentUser->getUserName() + ":", MessageElement::Text,
|
2018-05-23 04:22:17 +02:00
|
|
|
selfColor, FontStyle::ChatMediumBold);
|
2018-02-04 16:33:46 +01:00
|
|
|
} else {
|
|
|
|
if (!this->action) {
|
|
|
|
usernameText += ":";
|
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
this->emplace<TextElement>(usernameText, MessageElement::Text, this->usernameColor,
|
2018-05-23 04:22:17 +02:00
|
|
|
FontStyle::ChatMediumBold)
|
2018-02-04 16:33:46 +01:00
|
|
|
->setLink({Link::UserInfo, this->userName});
|
2017-07-02 18:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 01:19:25 +02:00
|
|
|
void TwitchMessageBuilder::parseHighlights()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
if (this->ircMessage->nick() == currentUsername) {
|
2018-02-04 16:33:46 +01:00
|
|
|
currentUser->color = 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-04-27 22:11:19 +02:00
|
|
|
if (app->settings->customHighlightSound) {
|
|
|
|
highlightSoundUrl = QUrl(app->settings->pathHighlightSound.getValue());
|
2017-07-31 01:19:25 +02:00
|
|
|
} else {
|
2017-12-18 17:57:56 +01:00
|
|
|
highlightSoundUrl = QUrl("qrc:/sounds/ping2.wav");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentPlayerUrl != highlightSoundUrl) {
|
|
|
|
player->setMedia(highlightSoundUrl);
|
|
|
|
|
|
|
|
currentPlayerUrl = highlightSoundUrl;
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
|
2017-09-24 18:43:24 +02:00
|
|
|
QStringList blackList =
|
2018-04-27 22:11:19 +02:00
|
|
|
app->settings->highlightUserBlacklist.getValue().split("\n", QString::SkipEmptyParts);
|
2017-09-23 19:23:10 +02:00
|
|
|
|
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
|
|
|
|
std::vector<controllers::highlights::HighlightPhrase> activeHighlights =
|
|
|
|
app->highlights->phrases.getVector();
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) {
|
2018-05-06 12:52:47 +02:00
|
|
|
controllers::highlights::HighlightPhrase selfHighlight(
|
|
|
|
currentUsername, app->settings->enableHighlightTaskbar,
|
|
|
|
app->settings->enableHighlightSound, 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);
|
|
|
|
|
2017-09-24 18:43:24 +02:00
|
|
|
if (!blackList.contains(this->ircMessage->nick(), Qt::CaseInsensitive)) {
|
2018-05-06 00:32:45 +02:00
|
|
|
for (const controllers::highlights::HighlightPhrase &highlight : activeHighlights) {
|
2018-05-06 12:52:47 +02:00
|
|
|
if (highlight.isMatch(this->originalMessage)) {
|
|
|
|
debug::Log("Highlight because {} matches {}", this->originalMessage,
|
|
|
|
highlight.getPattern());
|
2017-09-23 19:23:10 +02:00
|
|
|
doHighlight = true;
|
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
if (highlight.getAlert()) {
|
|
|
|
doAlert = true;
|
2017-09-23 19:23:10 +02:00
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
if (highlight.getSound()) {
|
|
|
|
playSound = true;
|
2017-09-23 19:23:10 +02:00
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2017-09-23 19:23:10 +02:00
|
|
|
if (playSound && doAlert) {
|
|
|
|
// Break if no further action can be taken from other highlights
|
|
|
|
// This might change if highlights can have custom colors/sounds/actions
|
|
|
|
break;
|
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 19:23:10 +02:00
|
|
|
this->setHighlight(doHighlight);
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
if (playSound && (!hasFocus || app->settings->highlightAlwaysPlaySound)) {
|
2017-09-23 19:23:10 +02:00
|
|
|
player->play();
|
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
|
2017-09-23 19:23:10 +02:00
|
|
|
if (doAlert) {
|
2018-04-27 22:11:19 +02:00
|
|
|
QApplication::alert(getApp()->windows->getMainWindow().window(), 2500);
|
2017-09-23 19:23:10 +02:00
|
|
|
}
|
2018-01-06 03:48:56 +01:00
|
|
|
|
|
|
|
if (doHighlight) {
|
2018-04-18 09:12:29 +02:00
|
|
|
this->message->flags |= Message::Highlighted;
|
2018-01-06 03:48:56 +01:00
|
|
|
}
|
2017-07-31 01:19:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
void TwitchMessageBuilder::appendTwitchEmote(const Communi::IrcMessage *ircMessage,
|
2017-07-09 17:58:59 +02:00
|
|
|
const QString &emote,
|
2017-12-31 22:58:35 +01:00
|
|
|
std::vector<std::pair<long int, util::EmoteData>> &vec)
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-06-13 21:13:58 +02:00
|
|
|
if (!emote.contains(':')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList parameters = emote.split(':');
|
|
|
|
|
|
|
|
if (parameters.length() < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
long int id = std::stol(parameters.at(0).toStdString(), nullptr, 10);
|
|
|
|
|
|
|
|
QStringList occurences = parameters.at(1).split(',');
|
|
|
|
|
|
|
|
for (QString occurence : occurences) {
|
|
|
|
QStringList coords = occurence.split('-');
|
|
|
|
|
|
|
|
if (coords.length() < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
long int start = std::stol(coords.at(0).toStdString(), nullptr, 10);
|
|
|
|
long int end = std::stol(coords.at(1).toStdString(), nullptr, 10);
|
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
if (start >= end || start < 0 || end > this->originalMessage.length()) {
|
2017-06-13 21:13:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
QString name = this->originalMessage.mid(start, end - start + 1);
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-06-05 17:13:29 +02:00
|
|
|
vec.push_back(std::pair<long int, util::EmoteData>(
|
|
|
|
start, app->emotes->twitch.getEmoteById(id, name)));
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-23 09:53:50 +02:00
|
|
|
bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString)
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-12-31 22:58:35 +01:00
|
|
|
util::EmoteData emoteData;
|
2017-07-23 09:53:50 +02:00
|
|
|
|
2018-01-27 21:13:22 +01:00
|
|
|
auto appendEmote = [&](MessageElement::Flags flags) {
|
2018-01-22 22:38:44 +01:00
|
|
|
this->emplace<EmoteElement>(emoteData, flags);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-06-05 17:39:49 +02:00
|
|
|
if (app->emotes->bttv.globalEmotes.tryGet(emoteString, emoteData)) {
|
2017-07-23 09:53:50 +02:00
|
|
|
// BTTV Global Emote
|
2018-01-22 22:38:44 +01:00
|
|
|
return appendEmote(MessageElement::BttvEmote);
|
2017-12-31 00:50:07 +01:00
|
|
|
} else if (this->twitchChannel != nullptr &&
|
|
|
|
this->twitchChannel->bttvChannelEmotes->tryGet(emoteString, emoteData)) {
|
2017-07-23 09:53:50 +02:00
|
|
|
// BTTV Channel Emote
|
2018-01-22 22:38:44 +01:00
|
|
|
return appendEmote(MessageElement::BttvEmote);
|
2018-06-05 18:07:17 +02:00
|
|
|
} else if (app->emotes->ffz.globalEmotes.tryGet(emoteString, emoteData)) {
|
2017-07-23 09:53:50 +02:00
|
|
|
// FFZ Global Emote
|
2018-01-22 22:38:44 +01:00
|
|
|
return appendEmote(MessageElement::FfzEmote);
|
2017-12-31 00:50:07 +01:00
|
|
|
} else if (this->twitchChannel != nullptr &&
|
|
|
|
this->twitchChannel->ffzChannelEmotes->tryGet(emoteString, emoteData)) {
|
2017-07-23 09:53:50 +02:00
|
|
|
// FFZ Channel Emote
|
2018-01-22 22:38:44 +01:00
|
|
|
return appendEmote(MessageElement::FfzEmote);
|
2018-04-27 22:11:19 +02:00
|
|
|
} else if (app->emotes->getChatterinoEmotes().tryGet(emoteString, emoteData)) {
|
2017-07-23 09:53:50 +02:00
|
|
|
// Chatterino Emote
|
2018-01-22 22:38:44 +01:00
|
|
|
return appendEmote(MessageElement::Misc);
|
2017-07-23 09:53:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// fourtf: this is ugly
|
|
|
|
// maybe put the individual badges into a map instead of this mess
|
2018-01-23 23:28:06 +01:00
|
|
|
void TwitchMessageBuilder::appendTwitchBadges()
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
const auto &channelResources = app->resources->channels[this->roomID];
|
2017-07-02 18:12:11 +02:00
|
|
|
|
|
|
|
auto iterator = this->tags.find("badges");
|
|
|
|
|
|
|
|
if (iterator == this->tags.end()) {
|
|
|
|
// No badges in this message
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList badges = iterator.value().toString().split(',');
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
for (QString badge : badges) {
|
2017-06-13 22:03:29 +02:00
|
|
|
if (badge.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
if (badge.startsWith("bits/")) {
|
2018-04-28 15:20:18 +02:00
|
|
|
if (!app->resources->dynamicBadgesLoaded) {
|
2017-06-15 23:13:01 +02:00
|
|
|
// Do nothing
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString cheerAmountQS = badge.mid(5);
|
2017-06-16 10:01:21 +02:00
|
|
|
std::string versionKey = cheerAmountQS.toStdString();
|
2018-05-25 15:45:34 +02:00
|
|
|
QString tooltip = QString("Twitch cheer ") + cheerAmountQS;
|
2017-06-15 23:13:01 +02:00
|
|
|
|
2018-01-12 22:38:00 +01:00
|
|
|
// Try to fetch channel-specific bit badge
|
2017-06-16 08:03:13 +02:00
|
|
|
try {
|
2018-01-12 22:38:00 +01:00
|
|
|
const auto &badge = channelResources.badgeSets.at("bits").versions.at(versionKey);
|
2018-05-24 15:42:06 +02:00
|
|
|
this->emplace<ImageElement>(badge.badgeImage1x, MessageElement::BadgeVanity)
|
2018-05-24 16:06:34 +02:00
|
|
|
->setTooltip(tooltip);
|
2018-01-12 22:38:00 +01:00
|
|
|
continue;
|
|
|
|
} catch (const std::out_of_range &) {
|
|
|
|
// 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
|
|
|
|
try {
|
2018-04-28 15:20:18 +02:00
|
|
|
const auto &badge = app->resources->badgeSets.at("bits").versions.at(versionKey);
|
2018-05-24 16:06:34 +02:00
|
|
|
this->emplace<ImageElement>(badge.badgeImage1x, MessageElement::BadgeVanity)
|
|
|
|
->setTooltip(tooltip);
|
2018-01-12 22:38:00 +01:00
|
|
|
} catch (const std::out_of_range &) {
|
|
|
|
debug::Log("No default bit badge for version {} found", versionKey);
|
|
|
|
continue;
|
2017-06-16 08:03:13 +02:00
|
|
|
}
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "staff/1") {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeStaff,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Staff");
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "admin/1") {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeAdmin,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Admin");
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "global_mod/1") {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeGlobalModerator,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Global Moderator");
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "moderator/1") {
|
2017-06-13 22:03:29 +02:00
|
|
|
// TODO: Implement custom FFZ moderator badge
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeModerator,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeChannelAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Channel Moderator");
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "turbo/1") {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeTurbo,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeGlobalAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Turbo Subscriber");
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "broadcaster/1") {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeBroadcaster,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeChannelAuthority)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Broadcaster");
|
2017-06-13 21:13:58 +02:00
|
|
|
} else if (badge == "premium/1") {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgePremium, MessageElement::BadgeVanity)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Prime Subscriber");
|
2017-06-13 22:03:29 +02:00
|
|
|
} else if (badge.startsWith("partner/")) {
|
|
|
|
int index = badge.midRef(8).toInt();
|
|
|
|
switch (index) {
|
|
|
|
case 1: {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeVerified,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeVanity)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Verified");
|
2017-06-13 22:03:29 +02:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
printf("[TwitchMessageBuilder] Unhandled partner badge index: %d\n", index);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} else if (badge.startsWith("subscriber/")) {
|
2017-07-02 15:11:33 +02:00
|
|
|
if (channelResources.loaded == false) {
|
2018-04-15 15:09:31 +02:00
|
|
|
// qDebug() << "Channel resources are not loaded, can't add the subscriber badge";
|
2017-07-02 15:11:33 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-11-04 17:22:53 +01:00
|
|
|
auto badgeSetIt = channelResources.badgeSets.find("subscriber");
|
|
|
|
if (badgeSetIt == channelResources.badgeSets.end()) {
|
|
|
|
// Fall back to default badge
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeSubscriber,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeSubscription)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Subscriber");
|
2017-11-04 17:22:53 +01:00
|
|
|
continue;
|
|
|
|
}
|
2017-07-02 15:11:33 +02:00
|
|
|
|
2017-11-04 17:22:53 +01:00
|
|
|
const auto &badgeSet = badgeSetIt->second;
|
2017-07-02 15:11:33 +02:00
|
|
|
|
2017-11-04 17:22:53 +01:00
|
|
|
std::string versionKey = badge.mid(11).toStdString();
|
2017-07-02 15:11:33 +02:00
|
|
|
|
2017-11-04 17:22:53 +01:00
|
|
|
auto badgeVersionIt = badgeSet.versions.find(versionKey);
|
|
|
|
|
|
|
|
if (badgeVersionIt == badgeSet.versions.end()) {
|
|
|
|
// Fall back to default badge
|
2018-04-28 15:20:18 +02:00
|
|
|
this->emplace<ImageElement>(app->resources->badgeSubscriber,
|
2018-01-22 14:39:24 +01:00
|
|
|
MessageElement::BadgeSubscription)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch Subscriber");
|
2017-11-04 17:22:53 +01:00
|
|
|
continue;
|
2017-06-13 22:03:29 +02:00
|
|
|
}
|
2017-07-02 15:11:33 +02:00
|
|
|
|
2017-11-04 17:22:53 +01:00
|
|
|
auto &badgeVersion = badgeVersionIt->second;
|
|
|
|
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<ImageElement>(badgeVersion.badgeImage1x,
|
|
|
|
MessageElement::BadgeSubscription)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch " + QString::fromStdString(badgeVersion.title));
|
2017-06-13 22:03:29 +02:00
|
|
|
} else {
|
2018-04-28 15:20:18 +02:00
|
|
|
if (!app->resources->dynamicBadgesLoaded) {
|
2017-06-16 10:01:21 +02:00
|
|
|
// Do nothing
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList parts = badge.split('/');
|
|
|
|
|
|
|
|
if (parts.length() != 2) {
|
|
|
|
qDebug() << "Bad number of parts: " << parts.length() << " in " << parts;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
MessageElement::Flags badgeType = MessageElement::Flags::BadgeVanity;
|
2017-06-16 10:01:21 +02:00
|
|
|
|
|
|
|
std::string badgeSetKey = parts[0].toStdString();
|
|
|
|
std::string versionKey = parts[1].toStdString();
|
|
|
|
|
|
|
|
try {
|
2018-04-28 15:20:18 +02:00
|
|
|
auto &badgeSet = app->resources->badgeSets.at(badgeSetKey);
|
2017-06-16 10:01:21 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
auto &badgeVersion = badgeSet.versions.at(versionKey);
|
|
|
|
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<ImageElement>(badgeVersion.badgeImage1x, badgeType)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip("Twitch " + QString::fromStdString(badgeVersion.title));
|
2017-06-16 10:01:21 +02:00
|
|
|
} catch (const std::exception &e) {
|
|
|
|
qDebug() << "Exception caught:" << e.what()
|
|
|
|
<< "when trying to fetch badge version " << versionKey.c_str();
|
|
|
|
}
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
qDebug() << "No badge set with key" << badgeSetKey.c_str()
|
|
|
|
<< ". Exception: " << e.what();
|
|
|
|
}
|
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-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
auto &badges = app->resources->chatterinoBadges;
|
2017-08-12 13:20:52 +02:00
|
|
|
auto it = badges.find(this->userName.toStdString());
|
|
|
|
|
|
|
|
if (it == badges.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto badge = it->second;
|
|
|
|
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<ImageElement>(badge->image, MessageElement::BadgeChatterino)
|
2018-01-11 20:16:25 +01:00
|
|
|
->setTooltip(QString::fromStdString(badge->tooltip));
|
2017-08-12 13:20:52 +02:00
|
|
|
}
|
|
|
|
|
2018-01-12 19:37:11 +01:00
|
|
|
bool TwitchMessageBuilder::tryParseCheermote(const QString &string)
|
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
2018-01-12 19:37:11 +01:00
|
|
|
// Try to parse custom cheermotes
|
2018-04-28 15:20:18 +02:00
|
|
|
const auto &channelResources = app->resources->channels[this->roomID];
|
2018-01-12 19:37:11 +01:00
|
|
|
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) {
|
|
|
|
debug::Log("Error parsing bit amount in tryParseCheermote");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto savedIt = cheermoteSet.cheermotes.end();
|
|
|
|
|
|
|
|
// Fetch cheermote that matches our numBits
|
|
|
|
for (auto it = cheermoteSet.cheermotes.begin(); it != cheermoteSet.cheermotes.end();
|
|
|
|
++it) {
|
|
|
|
if (numBits >= it->minBits) {
|
|
|
|
savedIt = it;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (savedIt == cheermoteSet.cheermotes.end()) {
|
|
|
|
debug::Log("Error getting a cheermote from a cheermote set for the bit amount {}",
|
|
|
|
numBits);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &cheermote = *savedIt;
|
|
|
|
|
2018-01-22 14:39:24 +01:00
|
|
|
this->emplace<EmoteElement>(cheermote.emoteDataAnimated, EmoteElement::BitsAnimated);
|
|
|
|
this->emplace<TextElement>(amount, EmoteElement::Text, cheermote.color);
|
2018-01-12 19:37:11 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace twitch
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace providers
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|