mirror-chatterino2/src/providers/twitch/TwitchChannel.cpp

628 lines
19 KiB
C++
Raw Normal View History

2018-06-26 14:09:39 +02:00
#include "providers/twitch/TwitchChannel.hpp"
2018-06-26 15:33:51 +02:00
#include "common/Common.hpp"
2018-07-15 14:11:46 +02:00
#include "common/NetworkRequest.hpp"
#include "controllers/accounts/AccountController.hpp"
2018-06-26 14:09:39 +02:00
#include "debug/Log.hpp"
#include "messages/Message.hpp"
2018-08-02 14:23:27 +02:00
#include "providers/bttv/LoadBttvChannelEmote.hpp"
2018-07-06 19:23:47 +02:00
#include "providers/twitch/PubsubClient.hpp"
#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-06-26 14:09:39 +02:00
#include "util/PostToThread.hpp"
2018-02-05 15:11:50 +01:00
#include <IrcConnection>
#include <QJsonArray>
2018-08-02 14:23:27 +02:00
#include <QJsonObject>
#include <QJsonValue>
#include <QThread>
#include <QTimer>
namespace chatterino {
2018-08-02 14:23:27 +02:00
TwitchChannel::TwitchChannel(const QString &name)
: Channel(name, Channel::Type::Twitch)
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-07-06 19:23:47 +02:00
, mod_(false)
{
2018-08-02 14:23:27 +02:00
Log("[TwitchChannel:{}] Opened", name);
2018-08-02 14:23:27 +02:00
// this->refreshChannelEmotes();
2018-07-15 20:28:54 +02:00
// this->refreshViewerList();
2018-07-14 14:24:18 +02:00
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
[=] { this->setMod(false); });
2018-07-14 14:24:18 +02:00
// pubsub
this->userStateChanged.connect([=] { this->refreshPubsub(); });
this->managedConnect(getApp()->accounts->twitch.currentUserChanged,
[=] { this->refreshPubsub(); });
this->refreshPubsub();
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();
this->loadBadges();
this->loadCheerEmotes();
});
2018-07-14 14:24:18 +02:00
// timers
QObject::connect(&this->chattersListTimer_, &QTimer::timeout,
[=] { this->refreshViewerList(); });
this->chattersListTimer_.start(5 * 60 * 1000);
2018-07-14 14:24:18 +02:00
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout, [=] { this->refreshLiveStatus(); });
this->liveStatusTimer_.start(60 * 1000);
2018-01-17 18:36:12 +01:00
2018-07-14 14:24:18 +02:00
// --
2018-07-06 19:23:47 +02:00
this->messageSuffix_.append(' ');
this->messageSuffix_.append(QChar(0x206D));
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++) {
this->addMessage(Message::createSystemMessage("asdf"));
2018-06-19 20:34:50 +02:00
}
#endif
}
bool TwitchChannel::isEmpty() const
{
2018-08-02 14:23:27 +02:00
return this->getName().isEmpty();
}
bool TwitchChannel::canSendMessage() const
{
2017-12-31 00:50:07 +01:00
return !this->isEmpty();
}
2018-07-14 14:24:18 +02:00
void TwitchChannel::refreshChannelEmotes()
{
2018-08-02 14:23:27 +02:00
loadBttvChannelEmotes(this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
if (auto shared = weak.lock()) //
*this->bttvEmotes_.access() = emoteMap;
});
getApp()->emotes->ffz.loadChannelEmotes(this->getName(),
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
if (auto shared = weak.lock())
*this->ffzEmotes_.access() = emoteMap;
});
}
void TwitchChannel::sendMessage(const QString &message)
{
auto app = getApp();
2017-12-17 02:18:13 +01:00
if (!app->accounts->twitch.isLoggedIn()) {
// XXX: It would be nice if we could add a link here somehow that opened the "account
// manager" dialog
this->addMessage(
Message::createSystemMessage("You need to log in to send messages. You can "
"link your Twitch account in the settings."));
return;
}
2018-08-02 14:23:27 +02:00
Log("[TwitchChannel:{}] Send message: {}", this->getName(), message);
// Do last message processing
2018-06-05 18:53:49 +02:00
QString parsedMessage = app->emotes->emojis.replaceShortCodes(message);
parsedMessage = parsedMessage.trimmed();
2018-02-05 15:11:50 +01:00
if (parsedMessage.isEmpty()) {
return;
2018-02-05 15:11:50 +01:00
}
if (!this->hasModRights()) {
2018-07-15 20:28:54 +02:00
if (getSettings()->allowDuplicateMessages) {
2018-07-06 19:23:47 +02:00
if (parsedMessage == this->lastSentMessage_) {
parsedMessage.append(this->messageSuffix_);
}
}
}
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-06-06 18:57:22 +02:00
if (messageSent) {
qDebug() << "sent";
2018-07-06 19:23:47 +02:00
this->lastSentMessage_ = parsedMessage;
2018-06-06 18:57:22 +02: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
}
2018-01-17 18:36:12 +01:00
void TwitchChannel::setMod(bool value)
{
2018-07-06 19:23:47 +02:00
if (this->mod_ != value) {
this->mod_ = value;
2018-01-17 18:36:12 +01:00
this->userStateChanged.invoke();
2018-01-17 18:36:12 +01:00
}
}
bool TwitchChannel::isBroadcaster() const
2018-01-17 17:17:26 +01: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
}
void TwitchChannel::addRecentChatter(const std::shared_ptr<Message> &message)
{
assert(!message->loginName.isEmpty());
this->completionModel.addUser(message->displayName);
}
void TwitchChannel::addJoinedUser(const QString &user)
{
2018-07-15 20:28:54 +02:00
auto app = getApp();
2018-05-26 20:26:25 +02:00
if (user == app->accounts->twitch.getCurrent()->getUserName() ||
2018-07-15 20:28:54 +02:00
!getSettings()->showJoins.getValue()) {
return;
}
2018-07-15 20:28:54 +02:00
auto joinedUsers = this->joinedUsers_.access();
joinedUsers->append(user);
2018-07-06 19:23:47 +02:00
if (!this->joinedUsersMergeQueued_) {
this->joinedUsersMergeQueued_ = true;
2018-07-15 20:28:54 +02:00
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
auto joinedUsers = this->joinedUsers_.access();
2018-07-15 20:28:54 +02:00
auto message = Message::createSystemMessage("Users joined: " + joinedUsers->join(", "));
message->flags |= Message::Collapsed;
2018-07-15 20:28:54 +02:00
joinedUsers->clear();
2018-05-31 16:02:20 +02:00
this->addMessage(message);
2018-07-06 19:23:47 +02:00
this->joinedUsersMergeQueued_ = false;
});
}
}
void TwitchChannel::addPartedUser(const QString &user)
{
2018-07-14 14:24:18 +02:00
auto app = getApp();
2018-05-26 20:26:25 +02:00
if (user == app->accounts->twitch.getCurrent()->getUserName() ||
2018-07-14 14:24:18 +02:00
!getSettings()->showJoins.getValue()) {
return;
}
2018-07-15 20:28:54 +02:00
auto partedUsers = this->partedUsers_.access();
partedUsers->append(user);
2018-07-06 19:23:47 +02:00
if (!this->partedUsersMergeQueued_) {
this->partedUsersMergeQueued_ = true;
2018-07-15 20:28:54 +02:00
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
auto partedUsers = this->partedUsers_.access();
2018-07-15 20:28:54 +02:00
auto message = Message::createSystemMessage("Users parted: " + partedUsers->join(", "));
message->flags |= Message::Collapsed;
2018-05-31 16:02:20 +02:00
this->addMessage(message);
2018-07-15 20:28:54 +02:00
partedUsers->clear();
2018-07-06 19:23:47 +02:00
this->partedUsersMergeQueued_ = false;
});
}
}
2018-07-15 20:28:54 +02:00
QString TwitchChannel::getRoomId() const
2018-07-14 14:24:18 +02:00
{
return this->roomID_.get();
}
2018-07-15 20:28:54 +02:00
void TwitchChannel::setRoomId(const QString &id)
2018-07-14 14:24:18 +02:00
{
this->roomID_.set(id);
2018-07-15 20:28:54 +02:00
this->roomIdChanged.invoke();
2018-07-14 14:24:18 +02:00
this->loadRecentMessages();
}
2018-07-15 20:28:54 +02:00
const AccessGuard<TwitchChannel::RoomModes> TwitchChannel::accessRoomModes() const
2018-05-24 08:58:34 +02:00
{
2018-07-15 20:28:54 +02:00
return this->roomModes_.access();
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;
}
const AccessGuard<TwitchChannel::StreamStatus> TwitchChannel::accessStreamStatus() const
{
return this->streamStatus_.access();
}
2018-08-02 14:23:27 +02:00
boost::optional<EmotePtr> TwitchChannel::getBttvEmote(const EmoteName &name) const
{
auto emotes = this->bttvEmotes_.access();
auto it = emotes->find(name);
if (it == emotes->end()) return boost::none;
return it->second;
}
boost::optional<EmotePtr> TwitchChannel::getFfzEmote(const EmoteName &name) const
{
auto emotes = this->bttvEmotes_.access();
auto it = emotes->find(name);
if (it == emotes->end()) return boost::none;
return it->second;
}
AccessGuard<const EmoteMap> TwitchChannel::accessBttvEmotes() const
2018-07-15 20:28:54 +02:00
{
2018-08-02 14:23:27 +02:00
return this->bttvEmotes_.accessConst();
2018-05-24 08:58:34 +02:00
}
2018-08-02 14:23:27 +02:00
AccessGuard<const EmoteMap> TwitchChannel::accessFfzEmotes() const
2018-05-24 08:58:34 +02:00
{
2018-08-02 14:23:27 +02:00
return this->ffzEmotes_.accessConst();
2018-07-15 20:28:54 +02:00
}
const QString &TwitchChannel::getSubscriptionUrl()
{
return this->subscriptionUrl_;
}
const QString &TwitchChannel::getChannelUrl()
{
return this->channelUrl_;
}
const QString &TwitchChannel::getPopoutPlayerUrl()
{
return this->popoutPlayerUrl_;
2018-05-24 08:58:34 +02:00
}
void TwitchChannel::setLive(bool newLiveStatus)
{
bool gotNewLiveStatus = false;
{
2018-07-15 20:28:54 +02:00
auto guard = this->streamStatus_.access();
if (guard->live != newLiveStatus) {
gotNewLiveStatus = true;
2018-07-15 20:28:54 +02:00
guard->live = newLiveStatus;
}
}
if (gotNewLiveStatus) {
2018-07-14 14:24:18 +02:00
this->liveStatusChanged.invoke();
}
}
void TwitchChannel::refreshLiveStatus()
{
2018-07-15 20:28:54 +02:00
auto roomID = this->getRoomId();
2018-07-14 14:24:18 +02:00
if (roomID.isEmpty()) {
2018-08-02 14:23:27 +02:00
Log("[TwitchChannel:{}] Refreshing live status (Missing ID)", this->getName());
this->setLive(false);
return;
}
2018-08-02 14:23:27 +02:00
Log("[TwitchChannel:{}] Refreshing live status", this->getName());
2018-07-14 14:24:18 +02:00
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
//<<<<<<< HEAD
// auto request = makeGetStreamRequest(roomID, QThread::currentThread());
//=======
// auto request = NetworkRequest::twitchRequest(url);
// request.setCaller(QThread::currentThread());
//>>>>>>> 9bfbdefd2f0972a738230d5b95a009f73b1dd933
// request.onSuccess([this, weak = this->weak_from_this()](auto result) {
// ChannelPtr shared = weak.lock();
// if (!shared) return false;
// return this->parseLiveStatus(result.parseRapidJson());
// });
2018-07-15 20:28:54 +02:00
// request.execute();
2018-07-15 20:28:54 +02:00
}
2018-08-02 14:23:27 +02:00
Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
2018-07-15 20:28:54 +02:00
{
if (!document.IsObject()) {
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-07-15 20:28:54 +02:00
if (!document.HasMember("stream")) {
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
}
2018-07-15 20:28:54 +02:00
const auto &stream = document["stream"];
2018-07-15 20:28:54 +02:00
if (!stream.IsObject()) {
// 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
}
2018-07-15 20:28:54 +02:00
if (!stream.HasMember("viewers") || !stream.HasMember("game") || !stream.HasMember("channel") ||
!stream.HasMember("created_at")) {
Log("[TwitchChannel:refreshLiveStatus] Missing members in stream");
this->setLive(false);
2018-08-02 14:23:27 +02:00
return Failure;
2018-07-15 20:28:54 +02:00
}
2018-07-15 20:28:54 +02:00
const rapidjson::Value &streamChannel = stream["channel"];
2018-07-15 20:28:54 +02:00
if (!streamChannel.IsObject() || !streamChannel.HasMember("status")) {
Log("[TwitchChannel:refreshLiveStatus] Missing member \"status\" in channel");
2018-08-02 14:23:27 +02:00
return Failure;
2018-07-15 20:28:54 +02:00
}
2018-07-15 20:28:54 +02:00
// Stream is live
2018-07-15 20:28:54 +02:00
{
auto status = this->streamStatus_.access();
status->live = true;
status->viewerCount = stream["viewers"].GetUint();
status->game = stream["game"].GetString();
status->title = streamChannel["status"].GetString();
QDateTime since = QDateTime::fromString(stream["created_at"].GetString(), Qt::ISODate);
auto diff = since.secsTo(QDateTime::currentDateTime());
status->uptime =
QString::number(diff / 3600) + "h " + QString::number(diff % 3600 / 60) + "m";
status->rerun = false;
if (stream.HasMember("stream_type")) {
status->streamType = stream["stream_type"].GetString();
} else {
status->streamType = QString();
}
2018-07-15 20:28:54 +02:00
if (stream.HasMember("broadcast_platform")) {
const auto &broadcastPlatformValue = stream["broadcast_platform"];
2018-07-15 20:28:54 +02:00
if (broadcastPlatformValue.IsString()) {
const char *broadcastPlatform = stream["broadcast_platform"].GetString();
if (strcmp(broadcastPlatform, "rerun") == 0) {
status->rerun = true;
}
}
}
2018-07-15 20:28:54 +02:00
}
2018-07-15 20:28:54 +02:00
// Signal all listeners that the stream status has been updated
this->liveStatusChanged.invoke();
2018-08-02 14:23:27 +02:00
return Success;
}
2018-07-14 14:24:18 +02:00
void TwitchChannel::loadRecentMessages()
{
static QString genericURL =
"https://tmi.twitch.tv/api/rooms/%1/recent_messages?client_id=" + getDefaultClientID();
2018-07-15 20:28:54 +02:00
NetworkRequest request(genericURL.arg(this->getRoomId()));
request.makeAuthorizedV5(getDefaultClientID());
request.setCaller(QThread::currentThread());
2018-08-02 14:23:27 +02:00
request.onSuccess([this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
ChannelPtr shared = weak.lock();
2018-08-02 14:23:27 +02:00
if (!shared) return Failure;
2018-07-14 14:24:18 +02:00
return this->parseRecentMessages(result.parseJson());
});
2018-07-14 14:24:18 +02:00
request.execute();
}
2018-03-30 12:37:00 +02:00
2018-08-02 14:23:27 +02:00
Outcome TwitchChannel::parseRecentMessages(const QJsonObject &jsonRoot)
2018-07-14 14:24:18 +02:00
{
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
2018-08-02 14:23:27 +02:00
if (jsonMessages.empty()) return Failure;
2018-07-14 14:24:18 +02:00
std::vector<MessagePtr> messages;
for (const auto jsonMessage : jsonMessages) {
auto content = jsonMessage.toString().toUtf8();
// passing nullptr as the channel makes the message invalid but we don't check for that
// anyways
auto message = Communi::IrcMessage::fromData(content, nullptr);
2018-07-14 14:24:18 +02:00
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
assert(privMsg);
MessageParseArgs args;
TwitchMessageBuilder builder(this, privMsg, args);
if (!builder.isIgnored()) {
messages.push_back(builder.build());
2018-03-30 12:37:00 +02:00
}
2018-07-14 14:24:18 +02:00
}
2018-03-30 12:37:00 +02:00
2018-07-14 14:24:18 +02:00
this->addMessagesAtStart(messages);
2018-08-02 14:23:27 +02:00
return Success;
2018-07-14 14:24:18 +02:00
}
2018-07-14 14:24:18 +02:00
void TwitchChannel::refreshPubsub()
{
// listen to moderation actions
if (!this->hasModRights()) return;
2018-07-15 20:28:54 +02:00
auto roomId = this->getRoomId();
2018-07-14 14:24:18 +02:00
if (roomId.isEmpty()) return;
auto account = getApp()->accounts->twitch.getCurrent();
getApp()->twitch2->pubsub->listenToChannelModerationActions(roomId, account);
}
void TwitchChannel::refreshViewerList()
{
// setting?
2018-07-15 20:28:54 +02:00
const auto streamStatus = this->accessStreamStatus();
2018-07-14 14:24:18 +02:00
if (getSettings()->onlyFetchChattersForSmallerStreamers) {
2018-07-15 20:28:54 +02:00
if (streamStatus->live && streamStatus->viewerCount > getSettings()->smallStreamerLimit) {
2018-07-14 14:24:18 +02:00
return;
}
2018-07-14 14:24:18 +02:00
}
2018-07-14 14:24:18 +02:00
// get viewer list
2018-08-02 14:23:27 +02:00
NetworkRequest request("https://tmi.twitch.tv/group/user/" + this->getName() + "/chatters");
2018-07-14 14:24:18 +02:00
request.setCaller(QThread::currentThread());
2018-08-02 14:23:27 +02:00
request.onSuccess([this, weak = this->weak_from_this()](auto result) -> Outcome {
2018-07-14 14:24:18 +02:00
// channel still exists?
auto shared = weak.lock();
2018-08-02 14:23:27 +02:00
if (!shared) return Failure;
2018-07-14 14:24:18 +02:00
return this->parseViewerList(result.parseJson());
});
request.execute();
}
2018-08-02 14:23:27 +02:00
Outcome TwitchChannel::parseViewerList(const QJsonObject &jsonRoot)
2018-07-14 14:24:18 +02:00
{
static QStringList categories = {"moderators", "staff", "admins", "global_mods", "viewers"};
// parse json
QJsonObject jsonCategories = jsonRoot.value("chatters").toObject();
for (const auto &category : categories) {
for (const auto jsonCategory : jsonCategories.value(category).toArray()) {
this->completionModel.addUser(jsonCategory.toString());
}
}
2018-08-02 14:23:27 +02:00
return Success;
}
void TwitchChannel::loadBadges()
{
auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" + this->getRoomId() +
"/display?language=en"};
NetworkRequest req(url.string);
req.setCaller(QThread::currentThread());
req.onSuccess([this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
auto shared = weak.lock();
if (!shared) return Failure;
auto badgeSets = this->badgeSets_.access();
auto jsonRoot = result.parseJson();
auto _ = jsonRoot["badge_sets"].toObject();
for (auto jsonBadgeSet = _.begin(); jsonBadgeSet != _.end(); jsonBadgeSet++) {
auto &versions = (*badgeSets)[jsonBadgeSet.key()];
auto _ = jsonBadgeSet->toObject()["versions"].toObject();
for (auto jsonVersion_ = _.begin(); jsonVersion_ != _.end(); jsonVersion_++) {
auto jsonVersion = jsonVersion_->toObject();
auto emote = std::make_shared<Emote>(
Emote{EmoteName{},
ImageSet{Image::fromUrl({jsonVersion["image_url_1x"].toString()}),
Image::fromUrl({jsonVersion["image_url_2x"].toString()}),
Image::fromUrl({jsonVersion["image_url_4x"].toString()})},
Tooltip{jsonRoot["description"].toString()},
Url{jsonVersion["clickURL"].toString()}});
versions.emplace(jsonVersion_.key(), emote);
};
}
return Success;
});
req.execute();
}
void TwitchChannel::loadCheerEmotes()
{
auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" + this->getRoomId()};
auto request = NetworkRequest::twitchRequest(url.string);
request.setCaller(QThread::currentThread());
request.onSuccess([this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
auto cheerEmoteSets = ParseCheermoteSets(result.parseRapidJson());
for (auto &set : cheerEmoteSets) {
auto cheerEmoteSet = CheerEmoteSet();
cheerEmoteSet.regex = QRegularExpression("^" + set.prefix.toLower() + "([1-9][0-9]*)$");
for (auto &tier : set.tiers) {
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);
}
std::sort(cheerEmoteSet.cheerEmotes.begin(), cheerEmoteSet.cheerEmotes.end(),
[](const auto &lhs, const auto &rhs) {
return lhs.minBits < rhs.minBits; //
});
this->cheerEmoteSets_.emplace_back(cheerEmoteSet);
}
return Success;
});
request.execute();
}
boost::optional<EmotePtr> TwitchChannel::getTwitchBadge(const QString &set,
const QString &version) const
{
auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set);
if (it != badgeSets->end()) {
auto it2 = it->second.find(version);
if (it2 != it->second.end()) {
return it2->second;
}
}
return boost::none;
2018-07-14 14:24:18 +02:00
}
} // namespace chatterino