2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2018-04-28 15:48:40 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "Application.hpp"
|
2018-06-26 15:33:51 +02:00
|
|
|
#include "common/Common.hpp"
|
2019-05-26 21:44:13 +02:00
|
|
|
#include "common/Env.hpp"
|
2018-07-15 14:11:46 +02:00
|
|
|
#include "common/NetworkRequest.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2018-08-12 15:29:40 +02:00
|
|
|
#include "controllers/notifications/NotificationController.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "debug/Log.hpp"
|
|
|
|
#include "messages/Message.hpp"
|
2018-08-11 17:15:17 +02:00
|
|
|
#include "providers/bttv/BttvEmotes.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "providers/bttv/LoadBttvChannelEmote.hpp"
|
2019-04-13 19:14:58 +02:00
|
|
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
2018-07-06 19:23:47 +02:00
|
|
|
#include "providers/twitch/PubsubClient.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "providers/twitch/TwitchCommon.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "providers/twitch/TwitchParseCheerEmotes.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2018-08-12 15:29:40 +02:00
|
|
|
#include "singletons/Toasts.hpp"
|
2018-08-12 20:21:21 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/PostToThread.hpp"
|
2018-08-29 19:25:37 +02:00
|
|
|
#include "widgets/Window.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
#include <IrcConnection>
|
2018-07-08 11:42:48 +02:00
|
|
|
#include <QJsonArray>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
2017-11-04 14:57:29 +01:00
|
|
|
#include <QThread>
|
|
|
|
#include <QTimer>
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
2018-08-10 18:56:17 +02:00
|
|
|
namespace {
|
2019-05-01 22:10:51 +02:00
|
|
|
constexpr char MAGIC_MESSAGE_SUFFIX[] = u8" \U000E0000";
|
|
|
|
|
2019-04-13 19:14:58 +02:00
|
|
|
// parseRecentMessages takes a json object and returns a vector of
|
|
|
|
// Communi IrcMessages
|
2018-10-13 14:45:51 +02:00
|
|
|
auto parseRecentMessages(const QJsonObject &jsonRoot, ChannelPtr channel)
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
|
|
|
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
|
2019-04-13 19:14:58 +02:00
|
|
|
std::vector<Communi::IrcMessage *> messages;
|
2018-08-15 22:46:20 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (jsonMessages.empty())
|
|
|
|
return messages;
|
2018-08-15 22:46:20 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto jsonMessage : jsonMessages)
|
|
|
|
{
|
2018-08-15 22:46:20 +02:00
|
|
|
auto content = jsonMessage.toString().toUtf8();
|
2019-04-13 19:14:58 +02:00
|
|
|
messages.emplace_back(
|
|
|
|
Communi::IrcMessage::fromData(content, nullptr));
|
2018-08-10 18:56:17 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
return messages;
|
|
|
|
}
|
|
|
|
std::pair<Outcome, UsernameSet> parseChatters(const QJsonObject &jsonRoot)
|
|
|
|
{
|
2019-04-04 11:30:50 +02:00
|
|
|
static QStringList categories = {"broadcaster", "vips", "moderators",
|
|
|
|
"staff", "admins", "global_mods",
|
|
|
|
"viewers"};
|
2018-08-13 13:54:39 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
auto usernames = UsernameSet();
|
2018-08-13 13:54:39 +02:00
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
// parse json
|
|
|
|
QJsonObject jsonCategories = jsonRoot.value("chatters").toObject();
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &category : categories)
|
|
|
|
{
|
|
|
|
for (auto jsonCategory : jsonCategories.value(category).toArray())
|
|
|
|
{
|
2018-08-15 22:46:20 +02:00
|
|
|
usernames.insert(jsonCategory.toString());
|
|
|
|
}
|
2018-08-13 13:54:39 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
return {Success, std::move(usernames)};
|
|
|
|
}
|
2018-08-10 18:56:17 +02:00
|
|
|
} // namespace
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-08-14 17:45:17 +02:00
|
|
|
TwitchChannel::TwitchChannel(const QString &name,
|
|
|
|
TwitchBadges &globalTwitchBadges, BttvEmotes &bttv,
|
2018-08-12 00:01:37 +02:00
|
|
|
FfzEmotes &ffz)
|
2018-08-02 14:23:27 +02:00
|
|
|
: Channel(name, Channel::Type::Twitch)
|
2019-09-17 12:10:38 +02:00
|
|
|
, ChannelChatters(*static_cast<Channel *>(this))
|
2018-07-15 20:28:54 +02:00
|
|
|
, subscriptionUrl_("https://www.twitch.tv/subs/" + name)
|
|
|
|
, channelUrl_("https://twitch.tv/" + name)
|
|
|
|
, popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name)
|
2018-08-14 17:45:17 +02:00
|
|
|
, globalTwitchBadges_(globalTwitchBadges)
|
2018-08-12 00:01:37 +02:00
|
|
|
, globalBttv_(bttv)
|
|
|
|
, globalFfz_(ffz)
|
|
|
|
, bttvEmotes_(std::make_shared<EmoteMap>())
|
|
|
|
, ffzEmotes_(std::make_shared<EmoteMap>())
|
2018-07-06 19:23:47 +02:00
|
|
|
, mod_(false)
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:{}] Opened", name);
|
2018-06-11 11:51:46 +02:00
|
|
|
|
2018-08-19 15:09:00 +02:00
|
|
|
this->liveStatusChanged.connect([this]() {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->isLive() == 1)
|
|
|
|
{
|
2018-08-19 15:09:00 +02:00
|
|
|
}
|
|
|
|
});
|
2018-08-17 21:19:15 +02:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
|
|
|
|
[=] { this->setMod(false); });
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// pubsub
|
|
|
|
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
|
|
|
|
[=] { this->refreshPubsub(); });
|
|
|
|
this->refreshPubsub();
|
2018-08-13 13:54:39 +02:00
|
|
|
this->userStateChanged.connect([this] { this->refreshPubsub(); });
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// room id loaded -> refresh live status
|
2018-08-02 14:23:27 +02:00
|
|
|
this->roomIdChanged.connect([this]() {
|
|
|
|
this->refreshPubsub();
|
|
|
|
this->refreshLiveStatus();
|
2018-08-13 13:54:39 +02:00
|
|
|
this->refreshBadges();
|
|
|
|
this->refreshCheerEmotes();
|
2019-08-27 20:45:55 +02:00
|
|
|
this->refreshFFZChannelEmotes();
|
2019-09-03 11:27:30 +02:00
|
|
|
this->refreshBTTVChannelEmotes();
|
2018-08-02 14:23:27 +02:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// timers
|
|
|
|
QObject::connect(&this->chattersListTimer_, &QTimer::timeout,
|
2018-08-13 13:54:39 +02:00
|
|
|
[=] { this->refreshChatters(); });
|
2018-07-14 14:24:18 +02:00
|
|
|
this->chattersListTimer_.start(5 * 60 * 1000);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout,
|
|
|
|
[=] { this->refreshLiveStatus(); });
|
2018-07-14 14:24:18 +02:00
|
|
|
this->liveStatusTimer_.start(60 * 1000);
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// debugging
|
2018-06-19 20:34:50 +02:00
|
|
|
#if 0
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
2018-08-13 13:54:39 +02:00
|
|
|
this->addMessage(makeSystemMessage("asef"));
|
2018-06-19 20:34:50 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::initialize()
|
|
|
|
{
|
|
|
|
this->refreshChatters();
|
2018-10-26 00:34:48 +02:00
|
|
|
this->refreshBadges();
|
2018-08-13 13:54:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
bool TwitchChannel::isEmpty() const
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
return this->getName().isEmpty();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
bool TwitchChannel::canSendMessage() const
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
return !this->isEmpty();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 20:45:55 +02:00
|
|
|
void TwitchChannel::refreshBTTVChannelEmotes()
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
BttvEmotes::loadChannel(
|
2019-09-03 11:27:30 +02:00
|
|
|
this->roomId(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
2018-08-11 17:15:17 +02:00
|
|
|
if (auto shared = weak.lock())
|
|
|
|
this->bttvEmotes_.set(
|
|
|
|
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2019-08-27 20:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::refreshFFZChannelEmotes()
|
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
FfzEmotes::loadChannel(
|
2019-09-07 13:48:30 +02:00
|
|
|
this->roomId(),
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
2018-08-06 21:17:03 +02:00
|
|
|
if (auto shared = weak.lock())
|
2018-08-11 17:15:17 +02:00
|
|
|
this->ffzEmotes_.set(
|
|
|
|
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
2019-09-07 13:48:30 +02:00
|
|
|
},
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&modBadge) {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
2019-09-08 11:36:35 +02:00
|
|
|
this->ffzCustomModBadge_.set(std::move(modBadge));
|
2019-09-07 13:48:30 +02:00
|
|
|
}
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::sendMessage(const QString &message)
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2017-12-17 02:18:13 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!app->accounts->twitch.isLoggedIn())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
// XXX: It would be nice if we could add a link here somehow that opened
|
|
|
|
// the "account manager" dialog
|
2018-08-07 01:35:24 +02:00
|
|
|
this->addMessage(
|
|
|
|
makeSystemMessage("You need to log in to send messages. You can "
|
|
|
|
"link your Twitch account in the settings."));
|
2018-06-24 15:09:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:{}] Send message: {}", this->getName(), message);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
// Do last message processing
|
2018-06-05 18:53:49 +02:00
|
|
|
QString parsedMessage = app->emotes->emojis.replaceShortCodes(message);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
parsedMessage = parsedMessage.trimmed();
|
2018-01-22 15:24:39 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
2018-01-22 15:24:39 +01:00
|
|
|
return;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
2018-01-22 15:24:39 +01:00
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
if (!this->hasHighRateLimit())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
|
|
|
if (getSettings()->allowDuplicateMessages)
|
|
|
|
{
|
|
|
|
if (parsedMessage == this->lastSentMessage_)
|
|
|
|
{
|
2019-05-01 22:10:51 +02:00
|
|
|
parsedMessage.append(MAGIC_MESSAGE_SUFFIX);
|
2018-06-24 17:20:15 +02:00
|
|
|
}
|
2018-03-24 12:02:07 +01:00
|
|
|
}
|
2018-01-22 15:24:39 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 18:57:22 +02:00
|
|
|
bool messageSent = false;
|
2018-08-02 14:23:27 +02:00
|
|
|
this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent);
|
2018-02-11 21:13:23 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (messageSent)
|
|
|
|
{
|
2018-06-06 18:57:22 +02:00
|
|
|
qDebug() << "sent";
|
2018-07-06 19:23:47 +02:00
|
|
|
this->lastSentMessage_ = parsedMessage;
|
2018-06-06 18:57:22 +02:00
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2018-01-18 18:17:48 +01:00
|
|
|
bool TwitchChannel::isMod() const
|
2018-01-17 17:17:26 +01:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->mod_;
|
2018-01-17 17:17:26 +01:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:31:34 +02:00
|
|
|
bool TwitchChannel::isVip() const
|
2019-04-13 15:26:47 +02:00
|
|
|
{
|
|
|
|
return this->vip_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::isStaff() const
|
|
|
|
{
|
|
|
|
return this->staff_;
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:36:12 +01:00
|
|
|
void TwitchChannel::setMod(bool value)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->mod_ != value)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->mod_ = value;
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
this->userStateChanged.invoke();
|
2018-01-17 18:36:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
void TwitchChannel::setVIP(bool value)
|
|
|
|
{
|
|
|
|
if (this->vip_ != value)
|
|
|
|
{
|
|
|
|
this->vip_ = value;
|
|
|
|
|
|
|
|
this->userStateChanged.invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setStaff(bool value)
|
|
|
|
{
|
|
|
|
if (this->staff_ != value)
|
|
|
|
{
|
|
|
|
this->staff_ = value;
|
|
|
|
|
|
|
|
this->userStateChanged.invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:19:52 +02:00
|
|
|
bool TwitchChannel::isBroadcaster() const
|
2018-01-17 17:17:26 +01:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
return this->getName() == app->accounts->twitch.getCurrent()->getUserName();
|
2018-01-17 17:17:26 +01:00
|
|
|
}
|
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
bool TwitchChannel::hasHighRateLimit() const
|
|
|
|
{
|
2019-10-07 20:31:34 +02:00
|
|
|
return this->isMod() || this->isBroadcaster() || this->isVip();
|
2019-04-13 15:26:47 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 08:05:51 +02:00
|
|
|
bool TwitchChannel::canReconnect() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::reconnect()
|
|
|
|
{
|
|
|
|
getApp()->twitch.server->connect();
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
QString TwitchChannel::roomId() const
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2018-08-10 19:00:14 +02:00
|
|
|
return *this->roomID_.access();
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
void TwitchChannel::setRoomId(const QString &id)
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (*this->roomID_.accessConst() != id)
|
|
|
|
{
|
2018-09-29 21:53:54 +02:00
|
|
|
*this->roomID_.access() = id;
|
|
|
|
this->roomIdChanged.invoke();
|
|
|
|
this->loadRecentMessages();
|
|
|
|
}
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
AccessGuard<const TwitchChannel::RoomModes> TwitchChannel::accessRoomModes()
|
|
|
|
const
|
2018-05-24 08:58:34 +02:00
|
|
|
{
|
2018-08-06 18:25:47 +02:00
|
|
|
return this->roomModes_.accessConst();
|
2018-05-24 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setRoomModes(const RoomModes &_roomModes)
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
this->roomModes_ = _roomModes;
|
2018-05-24 08:58:34 +02:00
|
|
|
|
|
|
|
this->roomModesChanged.invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::isLive() const
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
return this->streamStatus_.access()->live;
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
AccessGuard<const TwitchChannel::StreamStatus>
|
2018-08-15 22:46:20 +02:00
|
|
|
TwitchChannel::accessStreamStatus() const
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-08-06 18:25:47 +02:00
|
|
|
return this->streamStatus_.accessConst();
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 17:45:17 +02:00
|
|
|
const TwitchBadges &TwitchChannel::globalTwitchBadges() const
|
|
|
|
{
|
|
|
|
return this->globalTwitchBadges_;
|
|
|
|
}
|
|
|
|
|
2018-08-12 00:01:37 +02:00
|
|
|
const BttvEmotes &TwitchChannel::globalBttv() const
|
|
|
|
{
|
|
|
|
return this->globalBttv_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FfzEmotes &TwitchChannel::globalFfz() const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2018-08-12 00:01:37 +02:00
|
|
|
return this->globalFfz_;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
auto emotes = this->bttvEmotes_.get();
|
2018-08-02 14:23:27 +02:00
|
|
|
auto it = emotes->find(name);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (it == emotes->end())
|
|
|
|
return boost::none;
|
2018-08-02 14:23:27 +02:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-08-13 13:54:39 +02:00
|
|
|
auto emotes = this->ffzEmotes_.get();
|
2018-08-02 14:23:27 +02:00
|
|
|
auto it = emotes->find(name);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (it == emotes->end())
|
|
|
|
return boost::none;
|
2018-08-02 14:23:27 +02:00
|
|
|
return it->second;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
std::shared_ptr<const EmoteMap> TwitchChannel::bttvEmotes() const
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
return this->bttvEmotes_.get();
|
2018-05-24 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
std::shared_ptr<const EmoteMap> TwitchChannel::ffzEmotes() const
|
2018-05-24 08:58:34 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
return this->ffzEmotes_.get();
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
const QString &TwitchChannel::subscriptionUrl()
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
return this->subscriptionUrl_;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
const QString &TwitchChannel::channelUrl()
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
return this->channelUrl_;
|
|
|
|
}
|
|
|
|
|
2018-08-11 17:15:17 +02:00
|
|
|
const QString &TwitchChannel::popoutPlayerUrl()
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
return this->popoutPlayerUrl_;
|
2018-05-24 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
void TwitchChannel::setLive(bool newLiveStatus)
|
|
|
|
{
|
2018-04-14 18:27:13 +02:00
|
|
|
bool gotNewLiveStatus = false;
|
2018-03-30 15:05:33 +02:00
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
auto guard = this->streamStatus_.access();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (guard->live != newLiveStatus)
|
|
|
|
{
|
2018-04-14 18:27:13 +02:00
|
|
|
gotNewLiveStatus = true;
|
2018-10-21 13:43:02 +02:00
|
|
|
if (newLiveStatus)
|
|
|
|
{
|
2018-08-29 22:22:32 +02:00
|
|
|
if (getApp()->notifications->isChannelNotified(
|
2018-10-21 13:43:02 +02:00
|
|
|
this->getName(), Platform::Twitch))
|
|
|
|
{
|
|
|
|
if (Toasts::isEnabled())
|
|
|
|
{
|
2018-08-29 22:22:32 +02:00
|
|
|
getApp()->toasts->sendChannelNotification(
|
|
|
|
this->getName(), Platform::Twitch);
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getSettings()->notificationPlaySound)
|
|
|
|
{
|
2018-08-29 22:22:32 +02:00
|
|
|
getApp()->notifications->playSound();
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getSettings()->notificationFlashTaskbar)
|
|
|
|
{
|
2018-10-07 12:55:44 +02:00
|
|
|
getApp()->windows->sendAlert();
|
2018-08-29 22:22:32 +02:00
|
|
|
}
|
2018-08-12 20:21:21 +02:00
|
|
|
}
|
2019-03-01 21:18:32 +01:00
|
|
|
auto live =
|
|
|
|
makeSystemMessage(this->getDisplayName() + " is live");
|
2018-08-29 22:22:32 +02:00
|
|
|
this->addMessage(live);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-29 22:22:32 +02:00
|
|
|
auto offline =
|
2019-05-05 19:25:11 +02:00
|
|
|
makeSystemMessage(this->getDisplayName() + " is offline");
|
2018-08-29 22:22:32 +02:00
|
|
|
this->addMessage(offline);
|
2018-08-12 18:54:32 +02:00
|
|
|
}
|
2018-07-15 20:28:54 +02:00
|
|
|
guard->live = newLiveStatus;
|
2018-03-30 15:05:33 +02:00
|
|
|
}
|
2017-11-04 14:57:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (gotNewLiveStatus)
|
|
|
|
{
|
2018-07-14 14:24:18 +02:00
|
|
|
this->liveStatusChanged.invoke();
|
2018-04-08 14:45:47 +02:00
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
2017-11-04 14:57:29 +01:00
|
|
|
|
|
|
|
void TwitchChannel::refreshLiveStatus()
|
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
auto roomID = this->roomId();
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (roomID.isEmpty())
|
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:{}] Refreshing live status (Missing ID)",
|
2018-08-06 21:17:03 +02:00
|
|
|
this->getName());
|
2017-11-04 14:57:29 +01:00
|
|
|
this->setLive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2018-08-12 21:05:12 +02:00
|
|
|
// auto request = makeGetStreamRequest(roomID, QThread::currentThread());
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest::twitchRequest(url)
|
2019-08-20 23:30:39 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
.onSuccess(
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
|
|
|
ChannelPtr shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return Failure;
|
2018-01-05 00:58:25 +01:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
return this->parseLiveStatus(result.parseRapidJson());
|
|
|
|
})
|
|
|
|
.execute();
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2018-01-05 00:58:25 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!document.IsObject())
|
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:refreshLiveStatus] root is not an object");
|
2018-08-02 14:23:27 +02:00
|
|
|
return Failure;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2018-01-05 00:58:25 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!document.HasMember("stream"))
|
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
|
2018-08-02 14:23:27 +02:00
|
|
|
return Failure;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
const auto &stream = document["stream"];
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!stream.IsObject())
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
// Stream is offline (stream is most likely null)
|
|
|
|
this->setLive(false);
|
2018-08-02 14:23:27 +02:00
|
|
|
return Failure;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
if (!stream.HasMember("viewers") || !stream.HasMember("game") ||
|
2018-10-21 13:43:02 +02:00
|
|
|
!stream.HasMember("channel") || !stream.HasMember("created_at"))
|
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:refreshLiveStatus] Missing members in stream");
|
2018-07-15 20:28:54 +02:00
|
|
|
this->setLive(false);
|
2018-08-02 14:23:27 +02:00
|
|
|
return Failure;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
const rapidjson::Value &streamChannel = stream["channel"];
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!streamChannel.IsObject() || !streamChannel.HasMember("status"))
|
|
|
|
{
|
2018-08-11 14:20:53 +02:00
|
|
|
log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in "
|
2018-08-06 21:17:03 +02:00
|
|
|
"channel");
|
2018-08-02 14:23:27 +02:00
|
|
|
return Failure;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
// Stream is live
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
|
|
|
auto status = this->streamStatus_.access();
|
|
|
|
status->viewerCount = stream["viewers"].GetUint();
|
|
|
|
status->game = stream["game"].GetString();
|
|
|
|
status->title = streamChannel["status"].GetString();
|
2018-08-06 21:17:03 +02:00
|
|
|
QDateTime since = QDateTime::fromString(
|
|
|
|
stream["created_at"].GetString(), Qt::ISODate);
|
2018-07-15 20:28:54 +02:00
|
|
|
auto diff = since.secsTo(QDateTime::currentDateTime());
|
2018-08-06 21:17:03 +02:00
|
|
|
status->uptime = QString::number(diff / 3600) + "h " +
|
|
|
|
QString::number(diff % 3600 / 60) + "m";
|
2018-07-15 20:28:54 +02:00
|
|
|
|
|
|
|
status->rerun = false;
|
2018-10-21 13:43:02 +02:00
|
|
|
if (stream.HasMember("stream_type"))
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
status->streamType = stream["stream_type"].GetString();
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
status->streamType = QString();
|
|
|
|
}
|
2018-04-08 15:14:14 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (stream.HasMember("broadcast_platform"))
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
const auto &broadcastPlatformValue = stream["broadcast_platform"];
|
2018-04-08 15:14:14 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (broadcastPlatformValue.IsString())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
const char *broadcastPlatform =
|
|
|
|
stream["broadcast_platform"].GetString();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (strcmp(broadcastPlatform, "rerun") == 0)
|
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
status->rerun = true;
|
2018-04-08 15:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-30 15:05:33 +02:00
|
|
|
}
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2018-08-12 18:54:32 +02:00
|
|
|
setLive(true);
|
2018-07-15 20:28:54 +02:00
|
|
|
// Signal all listeners that the stream status has been updated
|
|
|
|
this->liveStatusChanged.invoke();
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
return Success;
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
void TwitchChannel::loadRecentMessages()
|
2017-12-28 00:03:52 +01:00
|
|
|
{
|
2019-05-25 11:24:10 +02:00
|
|
|
if (!getSettings()->loadTwitchMessageHistoryOnConnect)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest(Env::get().recentMessagesApiUrl.arg(this->getName()))
|
|
|
|
.concurrent()
|
|
|
|
.onSuccess([weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return Failure;
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
auto messages = parseRecentMessages(result.parseJson(), shared);
|
2018-10-13 14:45:51 +02:00
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
auto &handler = IrcMessageHandler::instance();
|
2019-04-13 19:14:58 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
std::vector<MessagePtr> allBuiltMessages;
|
2019-04-13 19:14:58 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
for (auto message : messages)
|
2019-04-13 19:14:58 +02:00
|
|
|
{
|
2019-08-20 21:50:36 +02:00
|
|
|
for (auto builtMessage :
|
|
|
|
handler.parseMessage(shared.get(), message))
|
|
|
|
{
|
|
|
|
builtMessage->flags.set(MessageFlag::RecentMessage);
|
|
|
|
allBuiltMessages.emplace_back(builtMessage);
|
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
}
|
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
postToThread(
|
|
|
|
[shared, messages = std::move(allBuiltMessages)]() mutable {
|
|
|
|
shared->addMessagesAtStart(messages);
|
|
|
|
});
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
return Success;
|
|
|
|
})
|
|
|
|
.execute();
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
void TwitchChannel::refreshPubsub()
|
|
|
|
{
|
|
|
|
// listen to moderation actions
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!this->hasModRights())
|
|
|
|
return;
|
2018-08-11 17:15:17 +02:00
|
|
|
auto roomId = this->roomId();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (roomId.isEmpty())
|
|
|
|
return;
|
2018-07-14 14:24:18 +02:00
|
|
|
|
|
|
|
auto account = getApp()->accounts->twitch.getCurrent();
|
2018-08-06 21:17:03 +02:00
|
|
|
getApp()->twitch2->pubsub->listenToChannelModerationActions(roomId,
|
|
|
|
account);
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::refreshChatters()
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
|
|
|
// setting?
|
2018-07-15 20:28:54 +02:00
|
|
|
const auto streamStatus = this->accessStreamStatus();
|
2019-05-08 08:51:14 +02:00
|
|
|
const auto viewerCount = static_cast<int>(streamStatus->viewerCount);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getSettings()->onlyFetchChattersForSmallerStreamers)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
if (streamStatus->live &&
|
2019-05-08 08:51:14 +02:00
|
|
|
viewerCount > getSettings()->smallStreamerLimit)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-07-14 14:24:18 +02:00
|
|
|
return;
|
2018-01-01 22:29:21 +01:00
|
|
|
}
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// get viewer list
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest("https://tmi.twitch.tv/group/user/" + this->getName() +
|
|
|
|
"/chatters")
|
2019-08-20 23:30:39 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
.onSuccess(
|
|
|
|
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
|
|
|
// channel still exists?
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return Failure;
|
|
|
|
|
|
|
|
auto pair = parseChatters(result.parseJson());
|
|
|
|
if (pair.first)
|
|
|
|
{
|
2019-09-17 12:10:38 +02:00
|
|
|
this->setChatters(std::move(pair.second));
|
2019-08-20 21:50:36 +02:00
|
|
|
}
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
return pair.first;
|
|
|
|
})
|
|
|
|
.execute();
|
2017-12-28 00:03:52 +01:00
|
|
|
}
|
2018-02-05 21:20:38 +01:00
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::refreshBadges()
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" +
|
2018-08-11 17:15:17 +02:00
|
|
|
this->roomId() + "/display?language=en"};
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest(url.string)
|
2019-08-20 23:30:39 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
.onSuccess([this,
|
|
|
|
weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return Failure;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
auto badgeSets = this->badgeSets_.access();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
auto jsonRoot = result.parseJson();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
auto _ = jsonRoot["badge_sets"].toObject();
|
|
|
|
for (auto jsonBadgeSet = _.begin(); jsonBadgeSet != _.end();
|
|
|
|
jsonBadgeSet++)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2019-08-20 21:50:36 +02:00
|
|
|
auto &versions = (*badgeSets)[jsonBadgeSet.key()];
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
auto _set = jsonBadgeSet->toObject()["versions"].toObject();
|
|
|
|
for (auto jsonVersion_ = _set.begin();
|
|
|
|
jsonVersion_ != _set.end(); jsonVersion_++)
|
|
|
|
{
|
|
|
|
auto jsonVersion = jsonVersion_->toObject();
|
|
|
|
auto emote = std::make_shared<Emote>(Emote{
|
|
|
|
EmoteName{},
|
|
|
|
ImageSet{
|
|
|
|
Image::fromUrl(
|
|
|
|
{jsonVersion["image_url_1x"].toString()}, 1),
|
|
|
|
Image::fromUrl(
|
|
|
|
{jsonVersion["image_url_2x"].toString()}, .5),
|
|
|
|
Image::fromUrl(
|
|
|
|
{jsonVersion["image_url_4x"].toString()}, .25)},
|
|
|
|
Tooltip{jsonVersion["description"].toString()},
|
|
|
|
Url{jsonVersion["clickURL"].toString()}});
|
|
|
|
|
|
|
|
versions.emplace(jsonVersion_.key(), emote);
|
|
|
|
};
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
return Success;
|
|
|
|
})
|
|
|
|
.execute();
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
void TwitchChannel::refreshCheerEmotes()
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2019-09-08 12:45:25 +02:00
|
|
|
QString url("https://api.twitch.tv/kraken/bits/actions?channel_id=" +
|
|
|
|
this->roomId());
|
|
|
|
NetworkRequest::twitchRequest(url)
|
|
|
|
.onSuccess([this,
|
|
|
|
weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
2018-08-06 21:17:03 +02:00
|
|
|
auto cheerEmoteSets = ParseCheermoteSets(result.parseRapidJson());
|
2018-08-10 18:56:17 +02:00
|
|
|
std::vector<CheerEmoteSet> emoteSets;
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2019-09-08 12:45:25 +02:00
|
|
|
for (auto &set : cheerEmoteSets)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto cheerEmoteSet = CheerEmoteSet();
|
|
|
|
cheerEmoteSet.regex = QRegularExpression(
|
2019-09-08 18:01:38 +02:00
|
|
|
"^" + set.prefix + "([1-9][0-9]*)$",
|
|
|
|
QRegularExpression::CaseInsensitiveOption);
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2019-09-08 12:45:25 +02:00
|
|
|
for (auto &tier : set.tiers)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
CheerEmote cheerEmote;
|
|
|
|
|
|
|
|
cheerEmote.color = QColor(tier.color);
|
|
|
|
cheerEmote.minBits = tier.minBits;
|
|
|
|
|
|
|
|
// TODO(pajlada): We currently hardcode dark here :|
|
|
|
|
// We will continue to do so for now since we haven't had to
|
|
|
|
// solve that anywhere else
|
|
|
|
|
|
|
|
cheerEmote.animatedEmote = std::make_shared<Emote>(
|
|
|
|
Emote{EmoteName{"cheer emote"},
|
|
|
|
ImageSet{
|
|
|
|
tier.images["dark"]["animated"]["1"],
|
|
|
|
tier.images["dark"]["animated"]["2"],
|
|
|
|
tier.images["dark"]["animated"]["4"],
|
|
|
|
},
|
|
|
|
Tooltip{}, Url{}});
|
|
|
|
cheerEmote.staticEmote = std::make_shared<Emote>(
|
|
|
|
Emote{EmoteName{"cheer emote"},
|
|
|
|
ImageSet{
|
|
|
|
tier.images["dark"]["static"]["1"],
|
|
|
|
tier.images["dark"]["static"]["2"],
|
|
|
|
tier.images["dark"]["static"]["4"],
|
|
|
|
},
|
|
|
|
Tooltip{}, Url{}});
|
|
|
|
|
|
|
|
cheerEmoteSet.cheerEmotes.emplace_back(cheerEmote);
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
std::sort(cheerEmoteSet.cheerEmotes.begin(),
|
|
|
|
cheerEmoteSet.cheerEmotes.end(),
|
|
|
|
[](const auto &lhs, const auto &rhs) {
|
2019-09-08 13:40:11 +02:00
|
|
|
return lhs.minBits > rhs.minBits;
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-10 18:56:17 +02:00
|
|
|
emoteSets.emplace_back(cheerEmoteSet);
|
2018-08-06 21:17:03 +02:00
|
|
|
}
|
2018-08-10 18:56:17 +02:00
|
|
|
*this->cheerEmoteSets_.access() = std::move(emoteSets);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
return Success;
|
2019-09-08 12:45:25 +02:00
|
|
|
})
|
|
|
|
.execute();
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:54:39 +02:00
|
|
|
boost::optional<EmotePtr> TwitchChannel::twitchBadge(
|
2018-08-06 21:17:03 +02:00
|
|
|
const QString &set, const QString &version) const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
|
|
|
auto badgeSets = this->badgeSets_.access();
|
|
|
|
auto it = badgeSets->find(set);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (it != badgeSets->end())
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
auto it2 = it->second.find(version);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (it2 != it->second.end())
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
return it2->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return boost::none;
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 21:53:03 +02:00
|
|
|
boost::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
|
|
|
|
{
|
2019-09-08 11:36:35 +02:00
|
|
|
return this->ffzCustomModBadge_.get();
|
2018-10-25 21:53:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 18:01:38 +02:00
|
|
|
boost::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
|
|
|
auto sets = this->cheerEmoteSets_.access();
|
|
|
|
for (const auto &set : *sets)
|
|
|
|
{
|
2019-09-08 18:01:38 +02:00
|
|
|
auto match = set.regex.match(string);
|
2019-09-08 12:45:25 +02:00
|
|
|
if (!match.hasMatch())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString amount = match.captured(1);
|
|
|
|
bool ok = false;
|
|
|
|
int bitAmount = amount.toInt(&ok);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
log("Error parsing bit amount in cheerEmote");
|
|
|
|
}
|
|
|
|
for (const auto &emote : set.cheerEmotes)
|
|
|
|
{
|
2019-09-08 13:40:11 +02:00
|
|
|
if (bitAmount >= emote.minBits)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2019-09-08 18:01:38 +02:00
|
|
|
return emote;
|
2019-09-08 12:45:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 21:53:03 +02:00
|
|
|
return boost::none;
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
} // namespace chatterino
|