feat: Add 7TV Emotes and Badges (#4002)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2022-10-16 13:22:17 +02:00
committed by GitHub
parent e8fd49aadb
commit 3e41b84ed7
29 changed files with 780 additions and 7 deletions
+41
View File
@@ -10,6 +10,7 @@
#include "providers/RecentMessagesApi.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/bttv/LoadBttvChannelEmote.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"
#include "providers/twitch/PubSubManager.hpp"
#include "providers/twitch/TwitchCommon.hpp"
@@ -83,6 +84,7 @@ TwitchChannel::TwitchChannel(const QString &name)
name)
, bttvEmotes_(std::make_shared<EmoteMap>())
, ffzEmotes_(std::make_shared<EmoteMap>())
, seventvEmotes_(std::make_shared<EmoteMap>())
, mod_(false)
{
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
@@ -107,6 +109,7 @@ TwitchChannel::TwitchChannel(const QString &name)
this->refreshCheerEmotes();
this->refreshFFZChannelEmotes(false);
this->refreshBTTVChannelEmotes(false);
this->refreshSevenTVChannelEmotes(false);
});
this->connected.connect([this]() {
@@ -243,6 +246,26 @@ void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh)
manualRefresh);
}
void TwitchChannel::refreshSevenTVChannelEmotes(bool manualRefresh)
{
if (!Settings::instance().enableSevenTVChannelEmotes)
{
this->seventvEmotes_.set(EMPTY_EMOTE_MAP);
return;
}
SeventvEmotes::loadChannelEmotes(
weakOf<Channel>(this), this->roomId(),
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
if (auto shared = weak.lock())
{
this->seventvEmotes_.set(std::make_shared<EmoteMap>(
std::forward<decltype(emoteMap)>(emoteMap)));
}
},
manualRefresh);
}
void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
{
assertInGuiThread();
@@ -553,6 +576,19 @@ boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
return it->second;
}
boost::optional<EmotePtr> TwitchChannel::seventvEmote(
const EmoteName &name) const
{
auto emotes = this->seventvEmotes_.get();
auto it = emotes->find(name);
if (it == emotes->end())
{
return boost::none;
}
return it->second;
}
std::shared_ptr<const EmoteMap> TwitchChannel::bttvEmotes() const
{
return this->bttvEmotes_.get();
@@ -563,6 +599,11 @@ std::shared_ptr<const EmoteMap> TwitchChannel::ffzEmotes() const
return this->ffzEmotes_.get();
}
std::shared_ptr<const EmoteMap> TwitchChannel::seventvEmotes() const
{
return this->seventvEmotes_.get();
}
const QString &TwitchChannel::subscriptionUrl()
{
return this->subscriptionUrl_;
+5
View File
@@ -52,6 +52,7 @@ class EmoteMap;
class TwitchBadges;
class FfzEmotes;
class BttvEmotes;
class SeventvEmotes;
class TwitchIrcServer;
@@ -109,11 +110,14 @@ public:
// Emotes
boost::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
boost::optional<EmotePtr> seventvEmote(const EmoteName &name) const;
std::shared_ptr<const EmoteMap> bttvEmotes() const;
std::shared_ptr<const EmoteMap> ffzEmotes() const;
std::shared_ptr<const EmoteMap> seventvEmotes() const;
virtual void refreshBTTVChannelEmotes(bool manualRefresh);
virtual void refreshFFZChannelEmotes(bool manualRefresh);
virtual void refreshSevenTVChannelEmotes(bool manualRefresh);
// Badges
boost::optional<EmotePtr> ffzCustomModBadge() const;
@@ -196,6 +200,7 @@ private:
protected:
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> seventvEmotes_;
Atomic<boost::optional<EmotePtr>> ffzCustomModBadge_;
Atomic<boost::optional<EmotePtr>> ffzCustomVipBadge_;
+20
View File
@@ -54,6 +54,7 @@ void TwitchIrcServer::initialize(Settings &settings, Paths &paths)
this->reloadBTTVGlobalEmotes();
this->reloadFFZGlobalEmotes();
this->reloadSevenTVGlobalEmotes();
/* Refresh all twitch channel's live status in bulk every 30 seconds after starting chatterino */
QObject::connect(&this->bulkLiveStatusTimer_, &QTimer::timeout, [=] {
@@ -467,6 +468,10 @@ const FfzEmotes &TwitchIrcServer::getFfzEmotes() const
{
return this->ffz;
}
const SeventvEmotes &TwitchIrcServer::getSeventvEmotes() const
{
return this->seventv_;
}
void TwitchIrcServer::reloadBTTVGlobalEmotes()
{
@@ -497,4 +502,19 @@ void TwitchIrcServer::reloadAllFFZChannelEmotes()
}
});
}
void TwitchIrcServer::reloadSevenTVGlobalEmotes()
{
this->seventv_.loadGlobalEmotes();
}
void TwitchIrcServer::reloadAllSevenTVChannelEmotes()
{
this->forEachChannel([](const auto &chan) {
if (auto *channel = dynamic_cast<TwitchChannel *>(chan.get()))
{
channel->refreshSevenTVChannelEmotes(false);
}
});
}
} // namespace chatterino
+5
View File
@@ -7,6 +7,7 @@
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/irc/AbstractIrcServer.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include <chrono>
#include <memory>
@@ -37,6 +38,8 @@ public:
void reloadAllBTTVChannelEmotes();
void reloadFFZGlobalEmotes();
void reloadAllFFZChannelEmotes();
void reloadSevenTVGlobalEmotes();
void reloadAllSevenTVChannelEmotes();
Atomic<QString> lastUserThatWhisperedMe;
@@ -49,6 +52,7 @@ public:
const BttvEmotes &getBttvEmotes() const;
const FfzEmotes &getFfzEmotes() const;
const SeventvEmotes &getSeventvEmotes() const;
protected:
virtual void initializeConnection(IrcConnection *connection,
@@ -85,6 +89,7 @@ private:
BttvEmotes bttv;
FfzEmotes ffz;
SeventvEmotes seventv_;
QTimer bulkLiveStatusTimer_;
pajlada::Signals::SignalHolder signalHolder_;
@@ -7,6 +7,7 @@
#include "messages/Message.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/ffz/FfzBadges.hpp"
#include "providers/seventv/SeventvBadges.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "providers/twitch/TwitchBadges.hpp"
#include "providers/twitch/TwitchChannel.hpp"
@@ -280,6 +281,7 @@ MessagePtr TwitchMessageBuilder::build()
this->appendChatterinoBadges();
this->appendFfzBadges();
this->appendSeventvBadges();
this->appendUsername();
@@ -1028,6 +1030,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
const auto &globalBttvEmotes = app->twitch->getBttvEmotes();
const auto &globalFfzEmotes = app->twitch->getFfzEmotes();
const auto &globalSeventvEmotes = app->twitch->getSeventvEmotes();
auto flags = MessageElementFlags();
auto emote = boost::optional<EmotePtr>{};
@@ -1035,8 +1038,10 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
// Emote order:
// - FrankerFaceZ Channel
// - BetterTTV Channel
// - 7TV Channel
// - FrankerFaceZ Global
// - BetterTTV Global
// - 7TV Global
if (this->twitchChannel && (emote = this->twitchChannel->ffzEmote(name)))
{
flags = MessageElementFlag::FfzEmote;
@@ -1046,6 +1051,15 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
{
flags = MessageElementFlag::BttvEmote;
}
else if (this->twitchChannel != nullptr &&
(emote = this->twitchChannel->seventvEmote(name)))
{
flags = MessageElementFlag::SevenTVEmote;
if (emote.value()->zeroWidth)
{
flags.set(MessageElementFlag::ZeroWidthEmote);
}
}
else if ((emote = globalFfzEmotes.emote(name)))
{
flags = MessageElementFlag::FfzEmote;
@@ -1059,6 +1073,14 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
flags.set(MessageElementFlag::ZeroWidthEmote);
}
}
else if ((emote = globalSeventvEmotes.globalEmote(name)))
{
flags = MessageElementFlag::SevenTVEmote;
if (emote.value()->zeroWidth)
{
flags.set(MessageElementFlag::ZeroWidthEmote);
}
}
if (emote)
{
@@ -1217,6 +1239,14 @@ void TwitchMessageBuilder::appendFfzBadges()
}
}
void TwitchMessageBuilder::appendSeventvBadges()
{
if (auto badge = getApp()->seventvBadges->getBadge({this->userId_}))
{
this->emplace<BadgeElement>(*badge, MessageElementFlag::BadgeSevenTV);
}
}
Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
{
if (this->bitsLeft == 0)
@@ -99,6 +99,7 @@ private:
void appendTwitchBadges();
void appendChatterinoBadges();
void appendFfzBadges();
void appendSeventvBadges();
Outcome tryParseCheermote(const QString &string);
bool shouldAddModerationElements() const;