2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "Application.hpp"
|
2021-05-14 13:14:43 +02:00
|
|
|
#include "common/Channel.hpp"
|
2019-05-26 21:44:13 +02:00
|
|
|
#include "common/Env.hpp"
|
2024-01-15 21:28:44 +01:00
|
|
|
#include "common/network/NetworkResult.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2021-02-14 14:01:13 +01:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2023-07-23 13:26:12 +02:00
|
|
|
#include "debug/AssertInGuiThread.hpp"
|
2021-05-14 13:14:43 +02:00
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "messages/MessageBuilder.hpp"
|
|
|
|
#include "providers/irc/IrcMessageBuilder.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "providers/IvrApi.hpp"
|
2023-07-29 11:49:44 +02:00
|
|
|
#include "providers/seventv/SeventvAPI.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "providers/twitch/api/Helix.hpp"
|
2018-06-26 17:25:24 +02:00
|
|
|
#include "providers/twitch/TwitchCommon.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
2023-07-23 13:26:12 +02:00
|
|
|
#include "util/CancellationToken.hpp"
|
2022-06-17 20:52:20 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2021-07-11 11:12:49 +02:00
|
|
|
#include "util/QStringHash.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <QThread>
|
|
|
|
|
2021-07-18 12:14:01 +02:00
|
|
|
namespace chatterino {
|
2021-07-17 17:18:17 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
TwitchAccount::TwitchAccount(const QString &username, const QString &oauthToken,
|
|
|
|
const QString &oauthClient, const QString &userID)
|
2018-06-26 17:06:17 +02:00
|
|
|
: Account(ProviderId::Twitch)
|
2018-07-06 19:23:47 +02:00
|
|
|
, oauthClient_(oauthClient)
|
|
|
|
, oauthToken_(oauthToken)
|
|
|
|
, userName_(username)
|
|
|
|
, userId_(userID)
|
|
|
|
, isAnon_(username == ANONYMOUS_USERNAME)
|
2018-02-05 15:11:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
QString TwitchAccount::toString() const
|
|
|
|
{
|
|
|
|
return this->getUserName();
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
const QString &TwitchAccount::getUserName() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->userName_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchAccount::getOAuthClient() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->oauthClient_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchAccount::getOAuthToken() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->oauthToken_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchAccount::getUserId() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->userId_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
2018-08-11 17:35:46 +02:00
|
|
|
QColor TwitchAccount::color()
|
|
|
|
{
|
|
|
|
return this->color_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchAccount::setColor(QColor color)
|
|
|
|
{
|
2021-04-10 14:34:40 +02:00
|
|
|
this->color_.set(std::move(color));
|
2018-08-11 17:35:46 +02:00
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
bool TwitchAccount::setOAuthClient(const QString &newClientID)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->oauthClient_.compare(newClientID) == 0)
|
|
|
|
{
|
2018-02-05 15:11:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->oauthClient_ = newClientID;
|
2018-02-05 15:11:50 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchAccount::setOAuthToken(const QString &newOAuthToken)
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->oauthToken_.compare(newOAuthToken) == 0)
|
|
|
|
{
|
2018-02-05 15:11:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->oauthToken_ = newOAuthToken;
|
2018-02-05 15:11:50 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchAccount::isAnon() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->isAnon_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
void TwitchAccount::loadBlocks()
|
2018-05-12 20:34:13 +02:00
|
|
|
{
|
2023-07-23 13:26:12 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
|
|
|
|
auto token = CancellationToken(false);
|
|
|
|
this->blockToken_ = token;
|
|
|
|
this->ignores_.clear();
|
|
|
|
this->ignoresUserIds_.clear();
|
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
getHelix()->loadBlocks(
|
2022-06-05 17:40:57 +02:00
|
|
|
getIApp()->getAccounts()->twitch.getCurrent()->userId_,
|
2023-07-23 13:26:12 +02:00
|
|
|
[this](const std::vector<HelixBlock> &blocks) {
|
|
|
|
assertInGuiThread();
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
for (const HelixBlock &block : blocks)
|
2018-05-12 20:34:13 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
TwitchUser blockedUser;
|
|
|
|
blockedUser.fromHelixBlock(block);
|
2023-07-23 13:26:12 +02:00
|
|
|
this->ignores_.insert(blockedUser);
|
|
|
|
this->ignoresUserIds_.insert(blockedUser.id);
|
2018-05-12 20:34:13 +02:00
|
|
|
}
|
2021-02-14 14:01:13 +01:00
|
|
|
},
|
2023-07-23 13:26:12 +02:00
|
|
|
[](auto error) {
|
|
|
|
qCWarning(chatterinoTwitch).noquote()
|
|
|
|
<< "Fetching blocks failed:" << error;
|
|
|
|
},
|
|
|
|
std::move(token));
|
2018-05-13 17:53:24 +02:00
|
|
|
}
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2023-07-23 13:26:12 +02:00
|
|
|
void TwitchAccount::blockUser(const QString &userId, const QObject *caller,
|
2023-07-01 14:01:47 +02:00
|
|
|
std::function<void()> onSuccess,
|
2021-02-14 14:01:13 +01:00
|
|
|
std::function<void()> onFailure)
|
2018-05-13 17:53:24 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
getHelix()->blockUser(
|
2023-07-01 14:01:47 +02:00
|
|
|
userId, caller,
|
2023-07-23 13:26:12 +02:00
|
|
|
[this, userId, onSuccess = std::move(onSuccess)] {
|
|
|
|
assertInGuiThread();
|
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
TwitchUser blockedUser;
|
|
|
|
blockedUser.id = userId;
|
2023-07-23 13:26:12 +02:00
|
|
|
this->ignores_.insert(blockedUser);
|
|
|
|
this->ignoresUserIds_.insert(blockedUser.id);
|
2021-02-14 14:01:13 +01:00
|
|
|
onSuccess();
|
|
|
|
},
|
2021-04-10 14:34:40 +02:00
|
|
|
std::move(onFailure));
|
2018-05-13 17:53:24 +02:00
|
|
|
}
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2023-07-23 13:26:12 +02:00
|
|
|
void TwitchAccount::unblockUser(const QString &userId, const QObject *caller,
|
2023-07-01 14:01:47 +02:00
|
|
|
std::function<void()> onSuccess,
|
2021-02-14 14:01:13 +01:00
|
|
|
std::function<void()> onFailure)
|
2018-05-13 17:53:24 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
getHelix()->unblockUser(
|
2023-07-01 14:01:47 +02:00
|
|
|
userId, caller,
|
2023-07-23 13:26:12 +02:00
|
|
|
[this, userId, onSuccess = std::move(onSuccess)] {
|
|
|
|
assertInGuiThread();
|
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
TwitchUser ignoredUser;
|
2021-02-14 14:01:13 +01:00
|
|
|
ignoredUser.id = userId;
|
2023-07-23 13:26:12 +02:00
|
|
|
this->ignores_.erase(ignoredUser);
|
|
|
|
this->ignoresUserIds_.erase(ignoredUser.id);
|
2021-02-14 14:01:13 +01:00
|
|
|
onSuccess();
|
|
|
|
},
|
2021-04-10 14:34:40 +02:00
|
|
|
std::move(onFailure));
|
2018-05-13 17:53:24 +02:00
|
|
|
}
|
|
|
|
|
2023-07-23 13:26:12 +02:00
|
|
|
const std::unordered_set<TwitchUser> &TwitchAccount::blocks() const
|
2018-05-12 20:34:13 +02:00
|
|
|
{
|
2023-07-23 13:26:12 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
return this->ignores_;
|
2021-05-01 13:38:58 +02:00
|
|
|
}
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2023-07-23 13:26:12 +02:00
|
|
|
const std::unordered_set<QString> &TwitchAccount::blockedUserIds() const
|
2021-05-01 13:38:58 +02:00
|
|
|
{
|
2023-07-23 13:26:12 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
return this->ignoresUserIds_;
|
2018-05-12 20:34:13 +02:00
|
|
|
}
|
|
|
|
|
2021-08-08 12:59:28 +02:00
|
|
|
void TwitchAccount::loadEmotes(std::weak_ptr<Channel> weakChannel)
|
2018-06-27 02:16:30 +02:00
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "Loading Twitch emotes for user" << this->getUserName();
|
2018-06-27 02:16:30 +02:00
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
if (this->getOAuthClient().isEmpty() || this->getOAuthToken().isEmpty())
|
2018-06-27 02:16:30 +02:00
|
|
|
{
|
2021-07-17 17:18:17 +02:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "Aborted loadEmotes due to missing Client ID and/or OAuth token";
|
2018-06-27 02:16:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
{
|
|
|
|
auto emoteData = this->emotes_.access();
|
|
|
|
emoteData->emoteSets.clear();
|
|
|
|
emoteData->emotes.clear();
|
|
|
|
qCDebug(chatterinoTwitch) << "Cleared emotes!";
|
|
|
|
}
|
2021-03-21 15:19:49 +01:00
|
|
|
|
2022-04-05 10:01:18 +02:00
|
|
|
this->loadUserstateEmotes(weakChannel);
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2021-03-21 15:42:45 +01:00
|
|
|
|
2021-06-20 00:11:06 +02:00
|
|
|
bool TwitchAccount::setUserstateEmoteSets(QStringList newEmoteSets)
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
2021-06-20 00:11:06 +02:00
|
|
|
newEmoteSets.sort();
|
|
|
|
|
|
|
|
if (this->userstateEmoteSets_ == newEmoteSets)
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
2021-06-20 00:11:06 +02:00
|
|
|
// Nothing has changed
|
|
|
|
return false;
|
2021-03-21 15:42:45 +01:00
|
|
|
}
|
2021-06-20 00:11:06 +02:00
|
|
|
|
|
|
|
this->userstateEmoteSets_ = newEmoteSets;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-05 10:01:18 +02:00
|
|
|
void TwitchAccount::loadUserstateEmotes(std::weak_ptr<Channel> weakChannel)
|
2021-06-20 00:11:06 +02:00
|
|
|
{
|
|
|
|
if (this->userstateEmoteSets_.isEmpty())
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-06-20 00:11:06 +02:00
|
|
|
|
2022-02-28 15:59:10 +01:00
|
|
|
QStringList newEmoteSetKeys, existingEmoteSetKeys;
|
2021-03-21 15:42:45 +01:00
|
|
|
|
|
|
|
auto emoteData = this->emotes_.access();
|
|
|
|
auto userEmoteSets = emoteData->emoteSets;
|
|
|
|
|
|
|
|
// get list of already fetched emote sets
|
|
|
|
for (const auto &userEmoteSet : userEmoteSets)
|
|
|
|
{
|
2022-02-28 15:59:10 +01:00
|
|
|
existingEmoteSetKeys.push_back(userEmoteSet->key);
|
2021-03-21 15:42:45 +01:00
|
|
|
}
|
2021-06-06 19:27:45 +02:00
|
|
|
|
2021-03-21 15:42:45 +01:00
|
|
|
// filter out emote sets from userstate message, which are not in fetched emote set list
|
2021-07-17 17:18:17 +02:00
|
|
|
for (const auto &emoteSetKey : qAsConst(this->userstateEmoteSets_))
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
2022-02-28 15:59:10 +01:00
|
|
|
if (!existingEmoteSetKeys.contains(emoteSetKey))
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
|
|
|
newEmoteSetKeys.push_back(emoteSetKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return if there are no new emote sets
|
|
|
|
if (newEmoteSetKeys.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:06 +02:00
|
|
|
// requesting emotes
|
2022-06-17 20:52:20 +02:00
|
|
|
auto batches = splitListIntoBatches(newEmoteSetKeys);
|
2021-07-17 17:18:17 +02:00
|
|
|
for (int i = 0; i < batches.size(); i++)
|
2021-06-06 19:27:45 +02:00
|
|
|
{
|
2021-07-17 17:18:17 +02:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< QString(
|
|
|
|
"Loading %1 emotesets from IVR; batch %2/%3 (%4 sets): %5")
|
|
|
|
.arg(newEmoteSetKeys.size())
|
|
|
|
.arg(i + 1)
|
|
|
|
.arg(batches.size())
|
|
|
|
.arg(batches.at(i).size())
|
|
|
|
.arg(batches.at(i).join(","));
|
2021-06-06 19:27:45 +02:00
|
|
|
getIvr()->getBulkEmoteSets(
|
2021-07-17 17:18:17 +02:00
|
|
|
batches.at(i).join(","),
|
2022-04-05 10:01:18 +02:00
|
|
|
[this, weakChannel](QJsonArray emoteSetArray) {
|
2021-06-06 19:27:45 +02:00
|
|
|
auto emoteData = this->emotes_.access();
|
2021-07-11 11:12:49 +02:00
|
|
|
auto localEmoteData = this->localEmotes_.access();
|
2023-11-04 18:45:18 +01:00
|
|
|
|
|
|
|
std::unordered_set<QString> subscriberChannelIDs;
|
|
|
|
std::vector<IvrEmoteSet> ivrEmoteSets;
|
|
|
|
ivrEmoteSets.reserve(emoteSetArray.size());
|
|
|
|
|
|
|
|
for (auto emoteSet : emoteSetArray)
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
2023-11-04 18:45:18 +01:00
|
|
|
IvrEmoteSet ivrEmoteSet(emoteSet.toObject());
|
|
|
|
if (!ivrEmoteSet.tier.isNull())
|
|
|
|
{
|
|
|
|
subscriberChannelIDs.insert(ivrEmoteSet.channelId);
|
|
|
|
}
|
|
|
|
ivrEmoteSets.emplace_back(ivrEmoteSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &emoteSet : emoteData->emoteSets)
|
|
|
|
{
|
|
|
|
if (emoteSet->subscriber)
|
|
|
|
{
|
|
|
|
subscriberChannelIDs.insert(emoteSet->channelID);
|
|
|
|
}
|
|
|
|
}
|
2021-03-21 15:42:45 +01:00
|
|
|
|
2023-11-04 18:45:18 +01:00
|
|
|
for (const auto &ivrEmoteSet : ivrEmoteSets)
|
|
|
|
{
|
|
|
|
auto emoteSet = std::make_shared<EmoteSet>();
|
2021-03-21 15:42:45 +01:00
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
QString setKey = ivrEmoteSet.setId;
|
|
|
|
emoteSet->key = setKey;
|
2021-03-21 15:42:45 +01:00
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// check if the emoteset is already in emoteData
|
|
|
|
auto isAlreadyFetched =
|
|
|
|
std::find_if(emoteData->emoteSets.begin(),
|
|
|
|
emoteData->emoteSets.end(),
|
|
|
|
[setKey](std::shared_ptr<EmoteSet> set) {
|
|
|
|
return (set->key == setKey);
|
|
|
|
});
|
|
|
|
if (isAlreadyFetched != emoteData->emoteSets.end())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-06-06 19:27:45 +02:00
|
|
|
|
2023-11-04 18:45:18 +01:00
|
|
|
emoteSet->channelID = ivrEmoteSet.channelId;
|
2021-07-17 17:18:17 +02:00
|
|
|
emoteSet->channelName = ivrEmoteSet.login;
|
|
|
|
emoteSet->text = ivrEmoteSet.displayName;
|
2023-11-04 18:45:18 +01:00
|
|
|
emoteSet->subscriber = !ivrEmoteSet.tier.isNull();
|
|
|
|
|
|
|
|
// NOTE: If a user does not have a subscriber emote set, but a follower emote set, this logic will be wrong
|
|
|
|
// However, that's not a realistic problem.
|
|
|
|
bool haveSubscriberSetForChannel =
|
|
|
|
subscriberChannelIDs.contains(ivrEmoteSet.channelId);
|
2021-06-06 19:27:45 +02:00
|
|
|
|
2021-07-11 11:12:49 +02:00
|
|
|
for (const auto &emoteObj : ivrEmoteSet.emotes)
|
2021-06-06 19:27:45 +02:00
|
|
|
{
|
2021-07-11 11:12:49 +02:00
|
|
|
IvrEmote ivrEmote(emoteObj.toObject());
|
2021-06-06 19:27:45 +02:00
|
|
|
|
|
|
|
auto id = EmoteId{ivrEmote.id};
|
2021-07-17 12:35:43 +02:00
|
|
|
auto code = EmoteName{
|
|
|
|
TwitchEmotes::cleanUpEmoteCode(ivrEmote.code)};
|
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
emoteSet->emotes.push_back(TwitchEmote{id, code});
|
2021-06-06 19:27:45 +02:00
|
|
|
|
2024-01-20 11:49:32 +01:00
|
|
|
auto emote = getIApp()
|
|
|
|
->getEmotes()
|
|
|
|
->getTwitchEmotes()
|
|
|
|
->getOrCreateEmote(id, code);
|
2021-07-11 11:12:49 +02:00
|
|
|
|
|
|
|
// Follower emotes can be only used in their origin channel
|
2023-11-04 18:45:18 +01:00
|
|
|
// unless the user is subscribed, then they can be used anywhere.
|
|
|
|
if (ivrEmote.emoteType == "FOLLOWER" &&
|
|
|
|
!haveSubscriberSetForChannel)
|
2021-07-11 11:12:49 +02:00
|
|
|
{
|
2021-07-17 17:18:17 +02:00
|
|
|
emoteSet->local = true;
|
2021-07-11 11:12:49 +02:00
|
|
|
|
|
|
|
// EmoteMap for target channel wasn't initialized yet, doing it now
|
|
|
|
if (localEmoteData->find(ivrEmoteSet.channelId) ==
|
|
|
|
localEmoteData->end())
|
|
|
|
{
|
|
|
|
localEmoteData->emplace(ivrEmoteSet.channelId,
|
|
|
|
EmoteMap());
|
|
|
|
}
|
|
|
|
|
|
|
|
localEmoteData->at(ivrEmoteSet.channelId)
|
|
|
|
.emplace(code, emote);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emoteData->emotes.emplace(code, emote);
|
|
|
|
}
|
2021-06-06 19:27:45 +02:00
|
|
|
}
|
2021-07-17 17:18:17 +02:00
|
|
|
std::sort(emoteSet->emotes.begin(), emoteSet->emotes.end(),
|
2021-06-06 19:27:45 +02:00
|
|
|
[](const TwitchEmote &l, const TwitchEmote &r) {
|
|
|
|
return l.name.string < r.name.string;
|
|
|
|
});
|
2021-07-17 17:18:17 +02:00
|
|
|
emoteData->emoteSets.emplace_back(emoteSet);
|
2021-03-21 15:42:45 +01:00
|
|
|
}
|
2022-04-05 10:01:18 +02:00
|
|
|
|
|
|
|
if (auto channel = weakChannel.lock(); channel != nullptr)
|
|
|
|
{
|
2024-07-07 22:03:05 +02:00
|
|
|
channel->addSystemMessage(
|
|
|
|
"Twitch subscriber emotes reloaded.");
|
2022-04-05 10:01:18 +02:00
|
|
|
}
|
2021-06-06 19:27:45 +02:00
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// fetching emotes failed, ivr API might be down
|
|
|
|
});
|
|
|
|
};
|
2021-03-21 15:42:45 +01:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const TwitchAccount::TwitchAccountEmoteData>
|
2018-08-15 22:46:20 +02:00
|
|
|
TwitchAccount::accessEmotes() const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
|
|
|
return this->emotes_.accessConst();
|
|
|
|
}
|
|
|
|
|
2021-07-11 11:12:49 +02:00
|
|
|
SharedAccessGuard<const std::unordered_map<QString, EmoteMap>>
|
|
|
|
TwitchAccount::accessLocalEmotes() const
|
|
|
|
{
|
|
|
|
return this->localEmotes_.accessConst();
|
|
|
|
}
|
|
|
|
|
2019-01-20 14:45:59 +01:00
|
|
|
// AutoModActions
|
2021-05-14 13:14:43 +02:00
|
|
|
void TwitchAccount::autoModAllow(const QString msgID, ChannelPtr channel)
|
2019-01-20 14:47:04 +01:00
|
|
|
{
|
2021-05-14 13:14:43 +02:00
|
|
|
getHelix()->manageAutoModMessages(
|
|
|
|
this->getUserId(), msgID, "ALLOW",
|
|
|
|
[] {
|
|
|
|
// success
|
|
|
|
},
|
|
|
|
[channel](auto error) {
|
|
|
|
// failure
|
|
|
|
QString errorMessage("Failed to allow AutoMod message - ");
|
2019-01-20 16:07:31 +01:00
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case HelixAutoModMessageError::MessageAlreadyProcessed: {
|
|
|
|
errorMessage += "message has already been processed.";
|
|
|
|
}
|
|
|
|
break;
|
2019-01-20 17:03:45 +01:00
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
case HelixAutoModMessageError::UserNotAuthenticated: {
|
|
|
|
errorMessage += "you need to re-authenticate.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HelixAutoModMessageError::UserNotAuthorized: {
|
|
|
|
errorMessage +=
|
|
|
|
"you don't have permission to perform that action";
|
|
|
|
}
|
|
|
|
break;
|
2019-09-09 15:21:49 +02:00
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
case HelixAutoModMessageError::MessageNotFound: {
|
|
|
|
errorMessage += "target message not found.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This would most likely happen if the service is down, or if the JSON payload returned has changed format
|
|
|
|
case HelixAutoModMessageError::Unknown:
|
|
|
|
default: {
|
|
|
|
errorMessage += "an unknown error occured.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-07-07 22:03:05 +02:00
|
|
|
channel->addSystemMessage(errorMessage);
|
2021-05-14 13:14:43 +02:00
|
|
|
});
|
2019-01-20 14:47:04 +01:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
void TwitchAccount::autoModDeny(const QString msgID, ChannelPtr channel)
|
2019-01-20 14:47:04 +01:00
|
|
|
{
|
2021-05-14 13:14:43 +02:00
|
|
|
getHelix()->manageAutoModMessages(
|
|
|
|
this->getUserId(), msgID, "DENY",
|
|
|
|
[] {
|
|
|
|
// success
|
|
|
|
},
|
|
|
|
[channel](auto error) {
|
|
|
|
// failure
|
|
|
|
QString errorMessage("Failed to deny AutoMod message - ");
|
2019-01-20 16:07:31 +01:00
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case HelixAutoModMessageError::MessageAlreadyProcessed: {
|
|
|
|
errorMessage += "message has already been processed.";
|
|
|
|
}
|
|
|
|
break;
|
2019-01-20 17:03:45 +01:00
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
case HelixAutoModMessageError::UserNotAuthenticated: {
|
|
|
|
errorMessage += "you need to re-authenticate.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HelixAutoModMessageError::UserNotAuthorized: {
|
|
|
|
errorMessage +=
|
|
|
|
"you don't have permission to perform that action";
|
|
|
|
}
|
|
|
|
break;
|
2019-09-09 15:21:49 +02:00
|
|
|
|
2021-05-14 13:14:43 +02:00
|
|
|
case HelixAutoModMessageError::MessageNotFound: {
|
|
|
|
errorMessage += "target message not found.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This would most likely happen if the service is down, or if the JSON payload returned has changed format
|
|
|
|
case HelixAutoModMessageError::Unknown:
|
|
|
|
default: {
|
|
|
|
errorMessage += "an unknown error occured.";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-07-07 22:03:05 +02:00
|
|
|
channel->addSystemMessage(errorMessage);
|
2021-05-14 13:14:43 +02:00
|
|
|
});
|
2019-01-20 14:47:04 +01:00
|
|
|
}
|
2019-01-20 14:45:59 +01:00
|
|
|
|
2023-07-29 11:49:44 +02:00
|
|
|
const QString &TwitchAccount::getSeventvUserID() const
|
|
|
|
{
|
|
|
|
return this->seventvUserID_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchAccount::loadSeventvUserID()
|
|
|
|
{
|
|
|
|
if (this->isAnon())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this->seventvUserID_.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-26 16:54:19 +01:00
|
|
|
auto *seventv = getIApp()->getSeventvAPI();
|
|
|
|
if (!seventv)
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoSeventv)
|
|
|
|
<< "Not loading 7TV User ID because the 7TV API is not initialized";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
seventv->getUserByTwitchID(
|
2023-07-29 11:49:44 +02:00
|
|
|
this->getUserId(),
|
|
|
|
[this](const auto &json) {
|
|
|
|
const auto id = json["user"]["id"].toString();
|
|
|
|
if (!id.isEmpty())
|
|
|
|
{
|
|
|
|
this->seventvUserID_ = id;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[](const auto &result) {
|
|
|
|
qCDebug(chatterinoSeventv)
|
|
|
|
<< "Failed to load 7TV user-id:" << result.formatError();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace chatterino
|