feat: Add Live Emote Updates for BTTV (#4147)
This feature is enabled by default and can be disabled in settings with the "Enable BTTV live emotes updates" setting. Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include "messages/MessageElement.hpp"
|
||||
#include "messages/MessageThread.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/bttv/BttvLiveUpdates.hpp"
|
||||
#include "providers/bttv/liveupdates/BttvLiveUpdateMessages.hpp"
|
||||
#include "providers/RecentMessagesApi.hpp"
|
||||
#include "providers/seventv/eventapi/SeventvEventAPIDispatch.hpp"
|
||||
#include "providers/seventv/SeventvEmotes.hpp"
|
||||
@@ -103,6 +105,7 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
this->refreshFFZChannelEmotes(false);
|
||||
this->refreshBTTVChannelEmotes(false);
|
||||
this->refreshSevenTVChannelEmotes(false);
|
||||
this->joinBttvChannel();
|
||||
});
|
||||
|
||||
this->connected.connect([this]() {
|
||||
@@ -121,6 +124,11 @@ TwitchChannel::TwitchChannel(const QString &name)
|
||||
this->destroyed.connect([this]() {
|
||||
getApp()->twitch->dropSeventvChannel(this->seventvUserID_,
|
||||
this->seventvEmoteSetID_);
|
||||
|
||||
if (getApp()->twitch->bttvLiveUpdates)
|
||||
{
|
||||
getApp()->twitch->bttvLiveUpdates->partChannel(this->roomId());
|
||||
}
|
||||
});
|
||||
|
||||
this->messageRemovedFromStart.connect([this](MessagePtr &msg) {
|
||||
@@ -622,6 +630,66 @@ const QString &TwitchChannel::seventvEmoteSetID() const
|
||||
return this->seventvEmoteSetID_;
|
||||
}
|
||||
|
||||
void TwitchChannel::joinBttvChannel() const
|
||||
{
|
||||
if (getApp()->twitch->bttvLiveUpdates)
|
||||
{
|
||||
const auto currentAccount = getApp()->accounts->twitch.getCurrent();
|
||||
QString userName;
|
||||
if (currentAccount && !currentAccount->isAnon())
|
||||
{
|
||||
userName = currentAccount->getUserName();
|
||||
}
|
||||
getApp()->twitch->bttvLiveUpdates->joinChannel(this->roomId(),
|
||||
userName);
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::addBttvEmote(
|
||||
const BttvLiveUpdateEmoteUpdateAddMessage &message)
|
||||
{
|
||||
auto emote = BttvEmotes::addEmote(this->getDisplayName(), this->bttvEmotes_,
|
||||
message);
|
||||
|
||||
this->addOrReplaceLiveUpdatesAddRemove(true, "BTTV", QString() /*actor*/,
|
||||
emote->name.string);
|
||||
}
|
||||
|
||||
void TwitchChannel::updateBttvEmote(
|
||||
const BttvLiveUpdateEmoteUpdateAddMessage &message)
|
||||
{
|
||||
auto updated = BttvEmotes::updateEmote(this->getDisplayName(),
|
||||
this->bttvEmotes_, message);
|
||||
if (!updated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto [oldEmote, newEmote] = *updated;
|
||||
if (oldEmote->name == newEmote->name)
|
||||
{
|
||||
return; // only the creator changed
|
||||
}
|
||||
|
||||
auto builder = MessageBuilder(liveUpdatesUpdateEmoteMessage, "BTTV",
|
||||
QString() /* actor */, newEmote->name.string,
|
||||
oldEmote->name.string);
|
||||
this->addMessage(builder.release());
|
||||
}
|
||||
|
||||
void TwitchChannel::removeBttvEmote(
|
||||
const BttvLiveUpdateEmoteRemoveMessage &message)
|
||||
{
|
||||
auto removed = BttvEmotes::removeEmote(this->bttvEmotes_, message);
|
||||
if (!removed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/,
|
||||
removed.get()->name.string);
|
||||
}
|
||||
|
||||
void TwitchChannel::addSeventvEmote(
|
||||
const SeventvEventAPIEmoteAddDispatch &dispatch)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,8 @@ class EmoteMap;
|
||||
class TwitchBadges;
|
||||
class FfzEmotes;
|
||||
class BttvEmotes;
|
||||
struct BttvLiveUpdateEmoteUpdateAddMessage;
|
||||
struct BttvLiveUpdateEmoteRemoveMessage;
|
||||
class SeventvEmotes;
|
||||
struct SeventvEventAPIEmoteAddDispatch;
|
||||
struct SeventvEventAPIEmoteUpdateDispatch;
|
||||
@@ -139,6 +141,13 @@ public:
|
||||
const QString &seventvUserID() const;
|
||||
const QString &seventvEmoteSetID() const;
|
||||
|
||||
/** Adds a BTTV channel emote to this channel. */
|
||||
void addBttvEmote(const BttvLiveUpdateEmoteUpdateAddMessage &message);
|
||||
/** Updates a BTTV channel emote in this channel. */
|
||||
void updateBttvEmote(const BttvLiveUpdateEmoteUpdateAddMessage &message);
|
||||
/** Removes a BTTV channel emote from this channel. */
|
||||
void removeBttvEmote(const BttvLiveUpdateEmoteRemoveMessage &message);
|
||||
|
||||
/** Adds a 7TV channel emote to this channel. */
|
||||
void addSeventvEmote(const SeventvEventAPIEmoteAddDispatch &dispatch);
|
||||
/** Updates a 7TV channel emote's name in this channel */
|
||||
@@ -206,6 +215,8 @@ private:
|
||||
void fetchDisplayName();
|
||||
void cleanUpReplyThreads();
|
||||
void showLoginMessage();
|
||||
/** Joins (subscribes to) a Twitch channel for updates on BTTV. */
|
||||
void joinBttvChannel() const;
|
||||
|
||||
void setLive(bool newLiveStatus);
|
||||
void setMod(bool value);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/bttv/BttvLiveUpdates.hpp"
|
||||
#include "providers/seventv/eventapi/SeventvEventAPISubscription.hpp"
|
||||
#include "providers/seventv/SeventvEventAPI.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
@@ -30,6 +31,7 @@ using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
const QString BTTV_LIVE_UPDATES_URL = "wss://sockets.betterttv.net/ws";
|
||||
const QString SEVENTV_EVENTAPI_URL = "wss://events.7tv.io/v3";
|
||||
|
||||
} // namespace
|
||||
@@ -45,6 +47,14 @@ TwitchIrcServer::TwitchIrcServer()
|
||||
this->initializeIrc();
|
||||
|
||||
this->pubsub = new PubSub(TWITCH_PUBSUB_URL);
|
||||
|
||||
if (getSettings()->enableBTTVLiveUpdates &&
|
||||
getSettings()->enableBTTVChannelEmotes)
|
||||
{
|
||||
this->bttvLiveUpdates =
|
||||
std::make_unique<BttvLiveUpdates>(BTTV_LIVE_UPDATES_URL);
|
||||
}
|
||||
|
||||
if (getSettings()->enableSevenTVEventAPI &&
|
||||
getSettings()->enableSevenTVChannelEmotes)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ class Settings;
|
||||
class Paths;
|
||||
class PubSub;
|
||||
class TwitchChannel;
|
||||
class BttvLiveUpdates;
|
||||
class SeventvEventAPI;
|
||||
|
||||
class TwitchIrcServer final : public AbstractIrcServer, public Singleton
|
||||
@@ -66,6 +67,7 @@ public:
|
||||
IndirectChannel watchingChannel;
|
||||
|
||||
PubSub *pubsub;
|
||||
std::unique_ptr<BttvLiveUpdates> bttvLiveUpdates;
|
||||
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
|
||||
|
||||
const BttvEmotes &getBttvEmotes() const;
|
||||
|
||||
Reference in New Issue
Block a user