2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2018-04-28 15:48:40 +02:00
|
|
|
|
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"
|
2021-07-11 11:12:49 +02:00
|
|
|
#include "common/QLogging.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 "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"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/PubSubManager.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "providers/twitch/TwitchCommon.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
2020-03-14 12:13:57 +01:00
|
|
|
#include "providers/twitch/api/Helix.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"
|
2020-07-18 14:12:11 +02:00
|
|
|
#include "util/FormatTime.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/PostToThread.hpp"
|
2021-07-11 11:12:49 +02:00
|
|
|
#include "util/QStringHash.hpp"
|
2018-08-29 19:25:37 +02:00
|
|
|
#include "widgets/Window.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2020-03-14 12:13:57 +01:00
|
|
|
#include <rapidjson/document.h>
|
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";
|
2021-03-13 17:54:34 +01:00
|
|
|
constexpr int TITLE_REFRESH_PERIOD = 10000;
|
2021-01-17 14:47:34 +01:00
|
|
|
constexpr int CLIP_CREATION_COOLDOWN = 5000;
|
|
|
|
const QString CLIPS_LINK("https://clips.twitch.tv/%1");
|
|
|
|
const QString CLIPS_FAILURE_CLIPS_DISABLED_TEXT(
|
|
|
|
"Failed to create a clip - the streamer has clips disabled entirely or "
|
|
|
|
"requires a certain subscriber or follower status to create clips.");
|
|
|
|
const QString CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT(
|
|
|
|
"Failed to create a clip - you need to re-authenticate.");
|
|
|
|
const QString CLIPS_FAILURE_UNKNOWN_ERROR_TEXT(
|
|
|
|
"Failed to create a clip - an unknown error occurred.");
|
|
|
|
const QString LOGIN_PROMPT_TEXT("Click here to add your account again.");
|
|
|
|
const Link ACCOUNTS_LINK(Link::OpenAccountsPage, QString());
|
2019-05-01 22:10:51 +02:00
|
|
|
|
2020-07-18 14:12:11 +02:00
|
|
|
// convertClearchatToNotice takes a Communi::IrcMessage that is a CLEARCHAT command and converts it to a readable NOTICE message
|
|
|
|
// This has historically been done in the Recent Messages API, but this functionality is being moved to Chatterino instead
|
|
|
|
auto convertClearchatToNotice(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
auto channelName = message->parameter(0);
|
|
|
|
QString noticeMessage{};
|
|
|
|
if (message->tags().contains("target-user-id"))
|
|
|
|
{
|
|
|
|
auto target = message->parameter(1);
|
|
|
|
|
|
|
|
if (message->tags().contains("ban-duration"))
|
|
|
|
{
|
|
|
|
// User was timed out
|
|
|
|
noticeMessage =
|
|
|
|
QString("%1 has been timed out for %2.")
|
|
|
|
.arg(target)
|
|
|
|
.arg(formatTime(
|
|
|
|
message->tag("ban-duration").toString()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User was permanently banned
|
|
|
|
noticeMessage =
|
|
|
|
QString("%1 has been permanently banned.").arg(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Chat was cleared
|
|
|
|
noticeMessage = "Chat has been cleared by a moderator.";
|
|
|
|
}
|
|
|
|
|
2021-10-17 15:06:58 +02:00
|
|
|
// rebuild the raw IRC message so we can convert it back to an ircmessage again!
|
2020-07-18 14:12:11 +02:00
|
|
|
// this could probably be done in a smarter way
|
2020-10-03 13:37:07 +02:00
|
|
|
|
2020-07-18 14:12:11 +02:00
|
|
|
auto s = QString(":tmi.twitch.tv NOTICE %1 :%2")
|
|
|
|
.arg(channelName)
|
|
|
|
.arg(noticeMessage);
|
|
|
|
|
2020-10-03 13:37:07 +02:00
|
|
|
auto newMessage = Communi::IrcMessage::fromData(s.toUtf8(), nullptr);
|
|
|
|
newMessage->setTags(message->tags());
|
|
|
|
|
|
|
|
return newMessage;
|
2020-07-18 14:12:11 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2022-01-11 01:18:02 +01:00
|
|
|
auto content = jsonMessage.toString();
|
|
|
|
content.replace(COMBINED_FIXER, ZERO_WIDTH_JOINER);
|
2020-07-18 14:12:11 +02:00
|
|
|
|
2022-01-11 01:18:02 +01:00
|
|
|
auto message =
|
|
|
|
Communi::IrcMessage::fromData(content.toUtf8(), nullptr);
|
2020-07-18 14:12:11 +02:00
|
|
|
|
|
|
|
if (message->command() == "CLEARCHAT")
|
|
|
|
{
|
|
|
|
message = convertClearchatToNotice(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
messages.emplace_back(std::move(message));
|
2018-08-10 18:56:17 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 22:46:20 +02:00
|
|
|
return messages;
|
|
|
|
}
|
2021-05-24 12:13:59 +02:00
|
|
|
std::pair<Outcome, std::unordered_set<QString>> parseChatters(
|
|
|
|
const QJsonObject &jsonRoot)
|
2018-08-15 22:46:20 +02:00
|
|
|
{
|
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
|
|
|
|
2021-05-24 12:13:59 +02:00
|
|
|
auto usernames = std::unordered_set<QString>();
|
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
|
|
|
|
2021-07-13 13:23:50 +02:00
|
|
|
TwitchChannel::TwitchChannel(const QString &name)
|
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))
|
2020-12-06 14:07:33 +01:00
|
|
|
, nameOptions{name, name}
|
2018-07-15 20:28:54 +02:00
|
|
|
, subscriptionUrl_("https://www.twitch.tv/subs/" + name)
|
|
|
|
, channelUrl_("https://twitch.tv/" + name)
|
2020-06-12 19:44:05 +02:00
|
|
|
, popoutPlayerUrl_("https://player.twitch.tv/?parent=twitch.tv&channel=" +
|
|
|
|
name)
|
2018-08-12 00:01:37 +02:00
|
|
|
, 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
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
|
2018-06-11 11:51:46 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->bSignals_.emplace_back(
|
|
|
|
getApp()->accounts->twitch.currentUserChanged.connect([=] {
|
2021-12-19 15:57:56 +01:00
|
|
|
this->setMod(false);
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
|
|
|
}));
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
2020-11-08 12:02:19 +01:00
|
|
|
this->userStateChanged.connect([this] {
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
2020-11-08 12:02:19 +01:00
|
|
|
});
|
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]() {
|
2022-05-07 17:22:39 +02:00
|
|
|
this->refreshPubSub();
|
2019-10-12 15:09:12 +02:00
|
|
|
this->refreshTitle();
|
2018-08-02 14:23:27 +02:00
|
|
|
this->refreshLiveStatus();
|
2018-08-13 13:54:39 +02:00
|
|
|
this->refreshBadges();
|
|
|
|
this->refreshCheerEmotes();
|
2020-05-16 12:43:44 +02:00
|
|
|
this->refreshFFZChannelEmotes(false);
|
|
|
|
this->refreshBTTVChannelEmotes(false);
|
2018-08-02 14:23:27 +02:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
this->messageRemovedFromStart.connect([this](MessagePtr &msg) {
|
|
|
|
if (msg->replyThread)
|
|
|
|
{
|
|
|
|
if (msg->replyThread->liveCount(msg) == 0)
|
|
|
|
{
|
|
|
|
this->threads_.erase(msg->replyThread->rootId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-14 14:24:18 +02:00
|
|
|
// timers
|
2020-11-08 12:02:19 +01:00
|
|
|
QObject::connect(&this->chattersListTimer_, &QTimer::timeout, [=] {
|
|
|
|
this->refreshChatters();
|
|
|
|
});
|
2018-07-14 14:24:18 +02:00
|
|
|
this->chattersListTimer_.start(5 * 60 * 1000);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
QObject::connect(&this->threadClearTimer_, &QTimer::timeout, [=] {
|
|
|
|
// We periodically check for any dangling reply threads that missed
|
|
|
|
// being cleaned up on messageRemovedFromStart. This could occur if
|
|
|
|
// some other part of the program, like a user card, held a reference
|
|
|
|
// to the message.
|
|
|
|
//
|
|
|
|
// It seems difficult to actually replicate a situation where things
|
|
|
|
// are actually cleaned up, but I've verified that cleanups DO happen.
|
|
|
|
this->cleanUpReplyThreads();
|
|
|
|
});
|
|
|
|
this->threadClearTimer_.start(5 * 60 * 1000);
|
|
|
|
|
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()
|
|
|
|
{
|
2020-12-06 14:07:33 +01:00
|
|
|
this->fetchDisplayName();
|
2018-08-13 13:54:39 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-12-06 14:07:33 +01:00
|
|
|
const QString &TwitchChannel::getDisplayName() const
|
|
|
|
{
|
|
|
|
return this->nameOptions.displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setDisplayName(const QString &name)
|
|
|
|
{
|
|
|
|
this->nameOptions.displayName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchChannel::getLocalizedName() const
|
|
|
|
{
|
|
|
|
return this->nameOptions.localizedName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::setLocalizedName(const QString &name)
|
|
|
|
{
|
|
|
|
this->nameOptions.localizedName = name;
|
|
|
|
}
|
|
|
|
|
2020-05-16 12:43:44 +02:00
|
|
|
void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh)
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
BttvEmotes::loadChannel(
|
2020-12-12 16:15:49 +01:00
|
|
|
weakOf<Channel>(this), this->roomId(), this->getLocalizedName(),
|
2020-05-16 12:43:44 +02:00
|
|
|
[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)));
|
2020-05-16 12:43:44 +02:00
|
|
|
},
|
|
|
|
manualRefresh);
|
2019-08-27 20:45:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 12:43:44 +02:00
|
|
|
void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh)
|
2019-08-27 20:45:55 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
FfzEmotes::loadChannel(
|
2020-05-16 12:43:44 +02:00
|
|
|
weakOf<Channel>(this), this->roomId(),
|
2019-09-07 13:48:30 +02:00
|
|
|
[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
|
|
|
}
|
2020-05-16 12:43:44 +02:00
|
|
|
},
|
2021-04-17 14:42:30 +02:00
|
|
|
[this, weak = weakOf<Channel>(this)](auto &&vipBadge) {
|
|
|
|
if (auto shared = weak.lock())
|
|
|
|
{
|
|
|
|
this->ffzCustomVipBadge_.set(std::move(vipBadge));
|
|
|
|
}
|
|
|
|
},
|
2020-05-16 12:43:44 +02:00
|
|
|
manualRefresh);
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
|
|
|
|
{
|
2020-08-22 11:45:18 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
if (!reward.isUserInputRequired)
|
|
|
|
{
|
|
|
|
MessageBuilder builder;
|
2021-08-01 15:44:04 +02:00
|
|
|
TwitchMessageBuilder::appendChannelPointRewardMessage(
|
|
|
|
reward, &builder, this->isMod(), this->isBroadcaster());
|
2020-08-08 15:37:22 +02:00
|
|
|
this->addMessage(builder.release());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
bool result = false;
|
2020-08-08 15:37:22 +02:00
|
|
|
{
|
|
|
|
auto channelPointRewards = this->channelPointRewards_.access();
|
|
|
|
result = channelPointRewards->try_emplace(reward.id, reward).second;
|
|
|
|
}
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
this->channelPointRewardAdded.invoke(reward);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchChannel::isChannelPointRewardKnown(const QString &rewardId)
|
|
|
|
{
|
|
|
|
const auto &pointRewards = this->channelPointRewards_.accessConst();
|
|
|
|
const auto &it = pointRewards->find(rewardId);
|
|
|
|
return it != pointRewards->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::optional<ChannelPointReward> TwitchChannel::channelPointReward(
|
|
|
|
const QString &rewardId) const
|
|
|
|
{
|
|
|
|
auto rewards = this->channelPointRewards_.accessConst();
|
|
|
|
auto it = rewards->find(rewardId);
|
|
|
|
|
|
|
|
if (it == rewards->end())
|
|
|
|
return boost::none;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::showLoginMessage()
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2022-07-31 12:45:25 +02:00
|
|
|
const auto linkColor = MessageColor(MessageColor::Link);
|
|
|
|
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
|
|
|
|
const auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
const auto expirationText =
|
|
|
|
QStringLiteral("You need to log in to send messages. You can link your "
|
|
|
|
"Twitch account");
|
|
|
|
const auto loginPromptText = QStringLiteral("in the settings.");
|
|
|
|
|
|
|
|
auto builder = MessageBuilder();
|
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
builder.message().flags.set(MessageFlag::DoNotTriggerNotification);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(loginPromptText, MessageElementFlag::Text,
|
|
|
|
linkColor)
|
|
|
|
->setLink(accountsLink);
|
|
|
|
|
|
|
|
this->addMessage(builder.release());
|
|
|
|
}
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
QString TwitchChannel::prepareMessage(const QString &message) const
|
|
|
|
{
|
|
|
|
auto app = getApp();
|
2018-06-05 18:53:49 +02:00
|
|
|
QString parsedMessage = app->emotes->emojis.replaceShortCodes(message);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2022-01-11 01:18:02 +01:00
|
|
|
// This is to make sure that combined emoji go through properly, see
|
|
|
|
// https://github.com/Chatterino/chatterino2/issues/3384 and
|
|
|
|
// https://mm2pl.github.io/emoji_rfc.pdf for more details
|
|
|
|
parsedMessage.replace(ZERO_WIDTH_JOINER, ESCAPE_TAG);
|
2021-10-30 14:49:41 +02:00
|
|
|
parsedMessage = parsedMessage.simplified();
|
2018-01-22 15:24:39 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
2022-07-31 12:45:25 +02: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_)
|
|
|
|
{
|
2021-08-01 14:38:07 +02:00
|
|
|
auto spaceIndex = parsedMessage.indexOf(' ');
|
2021-08-15 11:52:32 +02:00
|
|
|
// If the message starts with either '/' or '.' Twitch will treat it as a command, omitting
|
|
|
|
// first space and only rest of the arguments treated as actual message content
|
|
|
|
// In cases when user sends a message like ". .a b" first character and first space are omitted as well
|
|
|
|
bool ignoreFirstSpace =
|
|
|
|
parsedMessage.at(0) == '/' || parsedMessage.at(0) == '.';
|
|
|
|
if (ignoreFirstSpace)
|
|
|
|
{
|
|
|
|
spaceIndex = parsedMessage.indexOf(' ', spaceIndex + 1);
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:38:07 +02:00
|
|
|
if (spaceIndex == -1)
|
|
|
|
{
|
|
|
|
// no spaces found, fall back to old magic character
|
|
|
|
parsedMessage.append(MAGIC_MESSAGE_SUFFIX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// replace the space we found in spaceIndex with two spaces
|
|
|
|
parsedMessage.replace(spaceIndex, 1, " ");
|
|
|
|
}
|
2018-06-24 17:20:15 +02:00
|
|
|
}
|
2018-03-24 12:02:07 +01:00
|
|
|
}
|
2018-01-22 15:24:39 +01:00
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
return parsedMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::sendMessage(const QString &message)
|
|
|
|
{
|
|
|
|
auto app = getApp();
|
|
|
|
if (!app->accounts->twitch.isLoggedIn())
|
|
|
|
{
|
|
|
|
if (!message.isEmpty())
|
|
|
|
{
|
|
|
|
this->showLoginMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[TwitchChannel" << this->getName() << "] Send message:" << message;
|
|
|
|
|
|
|
|
// Do last message processing
|
|
|
|
QString parsedMessage = this->prepareMessage(message);
|
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch) << "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
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::sendReply(const QString &message, const QString &replyId)
|
|
|
|
{
|
|
|
|
auto app = getApp();
|
|
|
|
if (!app->accounts->twitch.isLoggedIn())
|
|
|
|
{
|
|
|
|
if (!message.isEmpty())
|
|
|
|
{
|
|
|
|
this->showLoginMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(chatterinoTwitch) << "[TwitchChannel" << this->getName()
|
|
|
|
<< "] Send reply message:" << message;
|
|
|
|
|
|
|
|
// Do last message processing
|
|
|
|
QString parsedMessage = this->prepareMessage(message);
|
|
|
|
if (parsedMessage.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool messageSent = false;
|
|
|
|
this->sendReplySignal.invoke(this->getName(), parsedMessage, replyId,
|
|
|
|
messageSent);
|
|
|
|
|
|
|
|
if (messageSent)
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoTwitch) << "sent";
|
|
|
|
this->lastSentMessage_ = parsedMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2022-03-19 12:02:29 +01:00
|
|
|
getApp()->twitch->connect();
|
2019-09-18 08:05:51 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<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;
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<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-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
|
|
|
}
|
|
|
|
|
2021-01-16 13:58:11 +01:00
|
|
|
int TwitchChannel::chatterCount()
|
|
|
|
{
|
|
|
|
return this->chatterCount_;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2021-05-09 16:17:04 +02:00
|
|
|
// Channel live message
|
2021-05-08 16:46:41 +02:00
|
|
|
MessageBuilder builder;
|
|
|
|
TwitchMessageBuilder::liveSystemMessage(this->getDisplayName(),
|
|
|
|
&builder);
|
|
|
|
this->addMessage(builder.release());
|
2021-05-09 16:17:04 +02:00
|
|
|
|
|
|
|
// Message in /live channel
|
|
|
|
MessageBuilder builder2;
|
|
|
|
TwitchMessageBuilder::liveMessage(this->getDisplayName(),
|
|
|
|
&builder2);
|
2022-03-19 12:02:29 +01:00
|
|
|
getApp()->twitch->liveChannel->addMessage(builder2.release());
|
2021-05-09 16:17:04 +02:00
|
|
|
|
|
|
|
// Notify on all channels with a ping sound
|
|
|
|
if (getSettings()->notificationOnAnyChannel &&
|
|
|
|
!(isInStreamerMode() &&
|
|
|
|
getSettings()->streamerModeSuppressLiveNotifications))
|
|
|
|
{
|
|
|
|
getApp()->notifications->playSound();
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-19 19:27:31 +02:00
|
|
|
// Channel offline message
|
2021-05-08 16:46:41 +02:00
|
|
|
MessageBuilder builder;
|
|
|
|
TwitchMessageBuilder::offlineSystemMessage(
|
|
|
|
this->getDisplayName(), &builder);
|
|
|
|
this->addMessage(builder.release());
|
2021-06-19 19:27:31 +02:00
|
|
|
|
|
|
|
// "delete" old 'CHANNEL is live' message
|
|
|
|
LimitedQueueSnapshot<MessagePtr> snapshot =
|
2022-03-19 12:02:29 +01:00
|
|
|
getApp()->twitch->liveChannel->getMessageSnapshot();
|
2021-06-19 19:27:31 +02:00
|
|
|
int snapshotLength = snapshot.size();
|
|
|
|
|
|
|
|
// MSVC hates this code if the parens are not there
|
|
|
|
int end = (std::max)(0, snapshotLength - 200);
|
|
|
|
auto liveMessageSearchText =
|
|
|
|
QString("%1 is live!").arg(this->getDisplayName());
|
|
|
|
|
|
|
|
for (int i = snapshotLength - 1; i >= end; --i)
|
|
|
|
{
|
|
|
|
auto &s = snapshot[i];
|
|
|
|
|
|
|
|
if (s->messageText == liveMessageSearchText)
|
|
|
|
{
|
|
|
|
s->flags.set(MessageFlag::Disabled);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2019-10-12 15:09:12 +02:00
|
|
|
void TwitchChannel::refreshTitle()
|
|
|
|
{
|
2021-03-13 17:54:34 +01:00
|
|
|
// timer has never started, proceed and start it
|
|
|
|
if (!this->titleRefreshedTimer_.isValid())
|
2019-10-12 15:09:12 +02:00
|
|
|
{
|
2021-03-13 17:54:34 +01:00
|
|
|
this->titleRefreshedTimer_.start();
|
2019-10-12 15:09:12 +02:00
|
|
|
}
|
2021-03-13 17:54:34 +01:00
|
|
|
else if (this->roomId().isEmpty() ||
|
|
|
|
this->titleRefreshedTimer_.elapsed() < TITLE_REFRESH_PERIOD)
|
2019-10-12 15:09:12 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-03-13 17:54:34 +01:00
|
|
|
this->titleRefreshedTimer_.restart();
|
2019-10-12 15:09:12 +02:00
|
|
|
|
2021-01-21 13:48:48 +01:00
|
|
|
getHelix()->getChannel(
|
2021-03-13 17:54:34 +01:00
|
|
|
this->roomId(),
|
2021-01-21 13:48:48 +01:00
|
|
|
[this, weak = weakOf<Channel>(this)](HelixChannel channel) {
|
|
|
|
ChannelPtr shared = weak.lock();
|
2019-10-12 15:09:12 +02:00
|
|
|
|
2021-01-21 13:48:48 +01:00
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-10-12 15:09:12 +02:00
|
|
|
|
2021-01-21 13:48:48 +01:00
|
|
|
{
|
|
|
|
auto status = this->streamStatus_.access();
|
|
|
|
status->title = channel.title;
|
|
|
|
}
|
2019-10-12 15:09:12 +02:00
|
|
|
|
2021-01-21 13:48:48 +01:00
|
|
|
this->liveStatusChanged.invoke();
|
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// failure
|
|
|
|
});
|
2019-10-12 15:09:12 +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())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch) << "[TwitchChannel" << this->getName()
|
|
|
|
<< "] Refreshing live status (Missing ID)";
|
2017-11-04 14:57:29 +01:00
|
|
|
this->setLive(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-14 12:13:57 +01:00
|
|
|
getHelix()->getStreamById(
|
|
|
|
roomID,
|
|
|
|
[this, weak = weakOf<Channel>(this)](bool live, const auto &stream) {
|
|
|
|
ChannelPtr shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 00:58:25 +01:00
|
|
|
|
2020-03-14 12:13:57 +01:00
|
|
|
this->parseLiveStatus(live, stream);
|
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// failure
|
2022-05-28 20:10:10 +02:00
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// finally
|
2020-03-14 12:13:57 +01:00
|
|
|
});
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2018-01-05 00:58:25 +01:00
|
|
|
|
2020-03-14 12:13:57 +01:00
|
|
|
void TwitchChannel::parseLiveStatus(bool live, const HelixStream &stream)
|
2018-07-15 20:28:54 +02:00
|
|
|
{
|
2020-03-14 12:13:57 +01:00
|
|
|
if (!live)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2018-07-15 20:28:54 +02:00
|
|
|
this->setLive(false);
|
2020-03-14 12:13:57 +01:00
|
|
|
return;
|
2018-07-15 20:28:54 +02:00
|
|
|
}
|
2017-12-28 17:47:00 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-03-14 12:13:57 +01:00
|
|
|
auto status = this->streamStatus_.access();
|
|
|
|
status->viewerCount = stream.viewerCount;
|
2022-04-09 14:27:04 +02:00
|
|
|
status->gameId = stream.gameId;
|
|
|
|
status->game = stream.gameName;
|
2020-03-14 12:13:57 +01:00
|
|
|
status->title = stream.title;
|
|
|
|
QDateTime since = QDateTime::fromString(stream.startedAt, 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;
|
2020-03-14 12:13:57 +01:00
|
|
|
status->streamType = stream.type;
|
|
|
|
}
|
2018-04-08 15:14:14 +02:00
|
|
|
|
2020-03-14 12:13:57 +01:00
|
|
|
this->setLive(true);
|
2018-04-08 15:14:14 +02:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
// Signal all listeners that the stream status has been updated
|
|
|
|
this->liveStatusChanged.invoke();
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-18 15:21:09 +02:00
|
|
|
QUrl url(Env::get().recentMessagesApiUrl.arg(this->getName()));
|
|
|
|
QUrlQuery urlQuery(url);
|
|
|
|
if (!urlQuery.hasQueryItem("limit"))
|
|
|
|
{
|
|
|
|
urlQuery.addQueryItem(
|
|
|
|
"limit", QString::number(getSettings()->twitchMessageHistoryLimit));
|
|
|
|
}
|
|
|
|
url.setQuery(urlQuery);
|
2020-12-06 13:04:49 +01:00
|
|
|
|
2021-07-18 14:15:38 +02:00
|
|
|
auto weak = weakOf<Channel>(this);
|
|
|
|
|
2020-12-06 13:04:49 +01:00
|
|
|
NetworkRequest(url)
|
2021-07-18 14:15:38 +02:00
|
|
|
.onSuccess([this, weak](NetworkResult result) -> Outcome {
|
2019-08-20 21:50:36 +02:00
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return Failure;
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2021-07-18 14:15:38 +02:00
|
|
|
auto root = result.parseJson();
|
|
|
|
auto messages = parseRecentMessages(root, 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
|
|
|
{
|
2021-05-09 18:44:57 +02:00
|
|
|
if (message->tags().contains("rm-received-ts"))
|
|
|
|
{
|
|
|
|
QDate msgDate = QDateTime::fromMSecsSinceEpoch(
|
|
|
|
message->tags()
|
|
|
|
.value("rm-received-ts")
|
|
|
|
.toLongLong())
|
|
|
|
.date();
|
|
|
|
if (msgDate != shared.get()->lastDate_)
|
|
|
|
{
|
|
|
|
shared.get()->lastDate_ = msgDate;
|
|
|
|
auto msg = makeSystemMessage(
|
2021-05-16 00:34:42 +02:00
|
|
|
QLocale().toString(msgDate, QLocale::LongFormat),
|
2021-05-09 18:44:57 +02:00
|
|
|
QTime(0, 0));
|
|
|
|
msg->flags.set(MessageFlag::RecentMessage);
|
|
|
|
allBuiltMessages.emplace_back(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
auto builtMessages = handler.parseMessageWithReply(
|
|
|
|
shared.get(), message, allBuiltMessages);
|
|
|
|
|
|
|
|
for (auto builtMessage : builtMessages)
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
|
|
|
builtMessage->flags.set(MessageFlag::RecentMessage);
|
|
|
|
allBuiltMessages.emplace_back(builtMessage);
|
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
}
|
|
|
|
|
2021-07-18 14:15:38 +02:00
|
|
|
postToThread([this, shared, root,
|
|
|
|
messages = std::move(allBuiltMessages)]() mutable {
|
|
|
|
shared->addMessagesAtStart(messages);
|
|
|
|
|
|
|
|
// Notify user about a possible gap in logs if it returned some messages
|
|
|
|
// but isn't currently joined to a channel
|
|
|
|
if (QString errorCode = root.value("error_code").toString();
|
|
|
|
!errorCode.isEmpty())
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< QString("rm error_code=%1, channel=%2")
|
|
|
|
.arg(errorCode, this->getName());
|
|
|
|
if (errorCode == "channel_not_joined" && !messages.empty())
|
|
|
|
{
|
|
|
|
shared->addMessage(makeSystemMessage(
|
|
|
|
"Message history service recovering, there may be "
|
|
|
|
"gaps in the message history."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
return Success;
|
|
|
|
})
|
2021-07-18 14:15:38 +02:00
|
|
|
.onError([weak](NetworkResult result) {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return;
|
|
|
|
|
|
|
|
shared->addMessage(makeSystemMessage(
|
|
|
|
QString("Message history service unavailable (Error %1)")
|
|
|
|
.arg(result.status())));
|
|
|
|
})
|
2019-08-20 21:50:36 +02:00
|
|
|
.execute();
|
2018-07-14 14:24:18 +02:00
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
void TwitchChannel::refreshPubSub()
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2018-08-11 17:15:17 +02:00
|
|
|
auto roomId = this->roomId();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (roomId.isEmpty())
|
2022-05-07 17:22:39 +02:00
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
return;
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto currentAccount = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
|
|
|
getApp()->twitch->pubsub->setAccount(currentAccount);
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
getApp()->twitch->pubsub->listenToChannelModerationActions(roomId);
|
|
|
|
getApp()->twitch->pubsub->listenToAutomod(roomId);
|
|
|
|
getApp()->twitch->pubsub->listenToChannelPointRewards(roomId);
|
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)
|
2021-01-16 13:58:11 +01:00
|
|
|
{
|
2019-08-20 21:50:36 +02:00
|
|
|
return Failure;
|
2021-01-16 13:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto data = result.parseJson();
|
|
|
|
this->chatterCount_ = data.value("chatter_count").toInt();
|
2019-08-20 21:50:36 +02:00
|
|
|
|
2021-01-16 13:58:11 +01:00
|
|
|
auto pair = parseChatters(std::move(data));
|
2019-08-20 21:50:36 +02:00
|
|
|
if (pair.first)
|
|
|
|
{
|
2021-05-24 12:13:59 +02:00
|
|
|
this->updateOnlineChatters(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
|
|
|
|
2020-12-06 14:07:33 +01:00
|
|
|
void TwitchChannel::fetchDisplayName()
|
|
|
|
{
|
|
|
|
getHelix()->getUserByName(
|
|
|
|
this->getName(),
|
|
|
|
[weak = weakOf<Channel>(this)](const auto &user) {
|
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
return;
|
|
|
|
auto channel = static_cast<TwitchChannel *>(shared.get());
|
|
|
|
if (QString::compare(user.displayName, channel->getName(),
|
|
|
|
Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
channel->setDisplayName(user.displayName);
|
|
|
|
channel->setLocalizedName(user.displayName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
channel->setLocalizedName(QString("%1(%2)")
|
|
|
|
.arg(channel->getName())
|
|
|
|
.arg(user.displayName));
|
|
|
|
}
|
2020-12-20 16:43:35 +01:00
|
|
|
channel->addRecentChatter(channel->getDisplayName());
|
2020-12-06 14:07:33 +01:00
|
|
|
channel->displayNameChanged.invoke();
|
|
|
|
},
|
|
|
|
[] {});
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
void TwitchChannel::addReplyThread(const std::shared_ptr<MessageThread> &thread)
|
|
|
|
{
|
|
|
|
this->threads_[thread->rootId()] = thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::unordered_map<QString, std::weak_ptr<MessageThread>>
|
|
|
|
&TwitchChannel::threads() const
|
|
|
|
{
|
|
|
|
return this->threads_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchChannel::cleanUpReplyThreads()
|
|
|
|
{
|
|
|
|
for (auto it = this->threads_.begin(), last = this->threads_.end();
|
|
|
|
it != last;)
|
|
|
|
{
|
|
|
|
bool doErase = true;
|
|
|
|
if (auto thread = it->second.lock())
|
|
|
|
{
|
|
|
|
doErase = thread->liveCount() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doErase)
|
|
|
|
{
|
|
|
|
it = this->threads_.erase(it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-05-15 19:02:47 +02:00
|
|
|
getHelix()->getCheermotes(
|
|
|
|
this->roomId(),
|
|
|
|
[this, weak = weakOf<Channel>(this)](
|
|
|
|
const std::vector<HelixCheermoteSet> &cheermoteSets) -> Outcome {
|
2020-01-12 10:06:01 +01:00
|
|
|
auto shared = weak.lock();
|
|
|
|
if (!shared)
|
|
|
|
{
|
|
|
|
return Failure;
|
|
|
|
}
|
|
|
|
|
2018-08-10 18:56:17 +02:00
|
|
|
std::vector<CheerEmoteSet> emoteSets;
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
for (const auto &set : cheermoteSets)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
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
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
for (const auto &tier : set.tiers)
|
2019-09-08 12:45:25 +02:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
CheerEmote cheerEmote;
|
|
|
|
|
|
|
|
cheerEmote.color = QColor(tier.color);
|
|
|
|
cheerEmote.minBits = tier.minBits;
|
2019-12-19 21:36:02 +01:00
|
|
|
cheerEmote.regex = cheerEmoteSet.regex;
|
2018-08-06 21:17:03 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2021-03-13 14:16:32 +01:00
|
|
|
// Combine the prefix (e.g. BibleThump) with the tier (1, 100 etc.)
|
|
|
|
auto emoteTooltip =
|
|
|
|
set.prefix + tier.id + "<br>Twitch Cheer Emote";
|
2018-08-06 21:17:03 +02:00
|
|
|
cheerEmote.animatedEmote = std::make_shared<Emote>(
|
|
|
|
Emote{EmoteName{"cheer emote"},
|
|
|
|
ImageSet{
|
2021-05-15 19:02:47 +02:00
|
|
|
tier.darkAnimated.imageURL1x,
|
|
|
|
tier.darkAnimated.imageURL2x,
|
|
|
|
tier.darkAnimated.imageURL4x,
|
2018-08-06 21:17:03 +02:00
|
|
|
},
|
2021-03-13 14:16:32 +01:00
|
|
|
Tooltip{emoteTooltip}, Url{}});
|
2018-08-06 21:17:03 +02:00
|
|
|
cheerEmote.staticEmote = std::make_shared<Emote>(
|
|
|
|
Emote{EmoteName{"cheer emote"},
|
|
|
|
ImageSet{
|
2021-05-15 19:02:47 +02:00
|
|
|
tier.darkStatic.imageURL1x,
|
|
|
|
tier.darkStatic.imageURL2x,
|
|
|
|
tier.darkStatic.imageURL4x,
|
2018-08-06 21:17:03 +02:00
|
|
|
},
|
2021-03-13 14:16:32 +01:00
|
|
|
Tooltip{emoteTooltip}, Url{}});
|
2018-08-06 21:17:03 +02:00
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
cheerEmoteSet.cheerEmotes.emplace_back(
|
|
|
|
std::move(cheerEmote));
|
2018-08-06 21:17:03 +02:00
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
// Sort cheermotes by cost
|
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
|
|
|
|
2021-05-15 19:02:47 +02:00
|
|
|
emoteSets.emplace_back(std::move(cheerEmoteSet));
|
2018-08-06 21:17:03 +02:00
|
|
|
}
|
2021-05-15 19:02:47 +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;
|
2021-05-15 19:02:47 +02:00
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// Failure
|
|
|
|
return Failure;
|
|
|
|
});
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
2021-01-17 14:47:34 +01:00
|
|
|
void TwitchChannel::createClip()
|
|
|
|
{
|
|
|
|
if (!this->isLive())
|
|
|
|
{
|
|
|
|
this->addMessage(makeSystemMessage(
|
|
|
|
"Cannot create clip while the channel is offline!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-13 17:54:34 +01:00
|
|
|
// timer has never started, proceed and start it
|
|
|
|
if (!this->clipCreationTimer_.isValid())
|
|
|
|
{
|
|
|
|
this->clipCreationTimer_.start();
|
|
|
|
}
|
|
|
|
else if (this->clipCreationTimer_.elapsed() < CLIP_CREATION_COOLDOWN ||
|
|
|
|
this->isClipCreationInProgress)
|
2021-01-17 14:47:34 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addMessage(makeSystemMessage("Creating clip..."));
|
|
|
|
this->isClipCreationInProgress = true;
|
|
|
|
|
|
|
|
getHelix()->createClip(
|
|
|
|
this->roomId(),
|
|
|
|
// successCallback
|
|
|
|
[this](const HelixClip &clip) {
|
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
QString text(
|
|
|
|
"Clip created! Copy link to clipboard or edit it in browser.");
|
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
2021-01-17 14:47:34 +01:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
// text
|
|
|
|
builder.emplace<TextElement>("Clip created!",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
// clip link
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>("Copy link to clipboard",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::Link)
|
|
|
|
->setLink(Link(Link::CopyToClipboard, CLIPS_LINK.arg(clip.id)));
|
|
|
|
// separator text
|
|
|
|
builder.emplace<TextElement>("or", MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
// edit link
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>("edit it in browser.",
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::Link)
|
|
|
|
->setLink(Link(Link::Url, clip.editUrl));
|
|
|
|
|
|
|
|
this->addMessage(builder.release());
|
|
|
|
},
|
|
|
|
// failureCallback
|
|
|
|
[this](auto error) {
|
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
QString text;
|
2021-01-17 14:47:34 +01:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case HelixClipError::ClipsDisabled: {
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
CLIPS_FAILURE_CLIPS_DISABLED_TEXT,
|
|
|
|
MessageElementFlag::Text, MessageColor::System);
|
2021-07-11 12:19:35 +02:00
|
|
|
text = CLIPS_FAILURE_CLIPS_DISABLED_TEXT;
|
2021-01-17 14:47:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HelixClipError::UserNotAuthenticated: {
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT,
|
|
|
|
MessageElementFlag::Text, MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(LOGIN_PROMPT_TEXT,
|
|
|
|
MessageElementFlag::Text,
|
|
|
|
MessageColor::Link)
|
|
|
|
->setLink(ACCOUNTS_LINK);
|
2021-07-11 12:19:35 +02:00
|
|
|
text = QString("%1 %2").arg(
|
|
|
|
CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT,
|
|
|
|
LOGIN_PROMPT_TEXT);
|
2021-01-17 14:47:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This would most likely happen if the service is down, or if the JSON payload returned has changed format
|
|
|
|
case HelixClipError::Unknown:
|
|
|
|
default: {
|
|
|
|
builder.emplace<TextElement>(
|
|
|
|
CLIPS_FAILURE_UNKNOWN_ERROR_TEXT,
|
|
|
|
MessageElementFlag::Text, MessageColor::System);
|
2021-07-11 12:19:35 +02:00
|
|
|
text = CLIPS_FAILURE_UNKNOWN_ERROR_TEXT;
|
2021-01-17 14:47:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-11 12:19:35 +02:00
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
|
|
|
|
2021-01-17 14:47:34 +01:00
|
|
|
this->addMessage(builder.release());
|
|
|
|
},
|
|
|
|
// finallyCallback - this will always execute, so clip creation won't ever be stuck
|
|
|
|
[this] {
|
2021-03-13 17:54:34 +01:00
|
|
|
this->clipCreationTimer_.restart();
|
2021-01-17 14:47:34 +01:00
|
|
|
this->isClipCreationInProgress = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-04-17 14:42:30 +02:00
|
|
|
boost::optional<EmotePtr> TwitchChannel::ffzCustomVipBadge() const
|
|
|
|
{
|
|
|
|
return this->ffzCustomVipBadge_.get();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "Error parsing bit amount in cheerEmote";
|
2019-09-08 12:45:25 +02:00
|
|
|
}
|
|
|
|
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
|