diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index d6fb6a6b1..23c5e2083 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -739,22 +739,22 @@ void TwitchChannel::refreshBadges() void TwitchChannel::refreshCheerEmotes() { - /*auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" + - this->getRoomId()}; - auto request = NetworkRequest::twitchRequest(url.string); - request.setCaller(QThread::currentThread()); - - request.onSuccess( - [this, weak = weakOf(this)](auto result) -> Outcome { + QString url("https://api.twitch.tv/kraken/bits/actions?channel_id=" + + this->roomId()); + NetworkRequest::twitchRequest(url) + .onSuccess([this, + weak = weakOf(this)](auto result) -> Outcome { auto cheerEmoteSets = ParseCheermoteSets(result.parseRapidJson()); std::vector emoteSets; - for (auto &set : cheerEmoteSets) { + for (auto &set : cheerEmoteSets) + { auto cheerEmoteSet = CheerEmoteSet(); cheerEmoteSet.regex = QRegularExpression( "^" + set.prefix.toLower() + "([1-9][0-9]*)$"); - for (auto &tier : set.tiers) { + for (auto &tier : set.tiers) + { CheerEmote cheerEmote; cheerEmote.color = QColor(tier.color); @@ -795,10 +795,8 @@ void TwitchChannel::refreshCheerEmotes() *this->cheerEmoteSets_.access() = std::move(emoteSets); return Success; - }); - - request.execute(); - */ + }) + .execute(); } boost::optional TwitchChannel::twitchBadge( @@ -825,4 +823,48 @@ boost::optional TwitchChannel::ffzCustomModBadge() const return boost::none; } +boost::optional, boost::optional, + boost::optional>> + TwitchChannel::cheerEmote(const QString &string) +{ + auto sets = this->cheerEmoteSets_.access(); + for (const auto &set : *sets) + { + auto match = set.regex.match(string.toLower()); + if (!match.hasMatch()) + { + continue; + } + QString amount = match.captured(1); + bool ok = false; + int bitAmount = amount.toInt(&ok); + if (!ok) + { + log("Error parsing bit amount in cheerEmote"); + } + for (const auto &emote : set.cheerEmotes) + { + if (amount >= emote.minBits) + { + using OPEP = boost::optional; + std::tuple> retval; + if (emote.staticEmote) + { + std::get<0>(retval) = emote.staticEmote; + } + if (emote.animatedEmote) + { + std::get<1>(retval) = emote.animatedEmote; + } + if (emote.color != QColor()) + { + std::get<2>(retval) = emote.color; + } + return retval; + } + } + } + return boost::none; +} + } // namespace chatterino diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index e8ea9c296..4cc6ad1ee 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -92,6 +92,12 @@ public: boost::optional twitchBadge(const QString &set, const QString &version) const; + // Cheers + boost::optional< + std::tuple, boost::optional, + boost::optional>> + cheerEmote(const QString &string); + // Signals pajlada::Signals::NoArgSignal roomIdChanged; pajlada::Signals::NoArgSignal userStateChanged; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 9b8d30cc2..8e02f3816 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -274,7 +274,7 @@ MessagePtr TwitchMessageBuilder::build() if (iterator != this->tags.end()) { this->hasBits_ = true; - // bits = iterator.value().toString(); + this->bits = iterator.value().toString(); } // twitch emotes @@ -1285,56 +1285,29 @@ void TwitchMessageBuilder::appendChatterinoBadges() } } -Outcome TwitchMessageBuilder::tryParseCheermote(const QString & /*string*/) +Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string) { - // auto app = getApp(); - //// Try to parse custom cheermotes - // const auto &channelResources = app->resources->channels[this->roomID_]; - // if (channelResources.loaded) { - // for (const auto &cheermoteSet : channelResources.cheermoteSets) { - // auto match = cheermoteSet.regex.match(string); - // if (!match.hasMatch()) { - // continue; - // } - // QString amount = match.captured(1); - // bool ok = false; - // int numBits = amount.toInt(&ok); - // if (!ok) { - // Log("Error parsing bit amount in tryParseCheermote"); - // return Failure; - // } - - // auto savedIt = cheermoteSet.cheermotes.end(); - - // // Fetch cheermote that matches our numBits - // for (auto it = cheermoteSet.cheermotes.begin(); it != - // cheermoteSet.cheermotes.end(); - // ++it) { - // if (numBits >= it->minBits) { - // savedIt = it; - // } else { - // break; - // } - // } - - // if (savedIt == cheermoteSet.cheermotes.end()) { - // Log("Error getting a cheermote from a cheermote set for the - // bit amount {}", - // numBits); - // return Failure; - // } - - // const auto &cheermote = *savedIt; - - // this->emplace(cheermote.animatedEmote, - // MessageElementFlag::BitsAnimated); - // this->emplace(amount, MessageElementFlag::Text, - // cheermote.color); - - // return Success; - // } - //} - - return Failure; + auto cheerOpt = this->twitchChannel->cheerEmote(string); + if (!cheerOpt) + { + return Failure; + } + auto &cheerPairAndColor = *cheerOpt; + if (std::get<0>(cheerPairAndColor)) + { + this->emplace(*std::get<0>(cheerPairAndColor), + MessageElementFlag::BitsStatic); + } + if (std::get<1>(cheerPairAndColor)) + { + this->emplace(*std::get<1>(cheerPairAndColor), + MessageElementFlag::BitsAnimated); + } + if (std::get<2>(cheerPairAndColor)) + { + this->emplace(this->bits, MessageElementFlag::BitsAmount, + *std::get<2>(cheerPairAndColor)); + } + return Success; } } // namespace chatterino diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index 98552d1cf..c43c14195 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -78,6 +78,7 @@ private: QString roomID_; bool hasBits_ = false; + QString bits; bool historicalMessage_ = false; QString userId_; diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 2a0b52c48..46bc2fa15 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -205,15 +205,27 @@ void Window::addDebugStuff() #ifdef QT_DEBUG std::vector cheerMessages, subMessages, miscMessages; // clang-format off - cheerMessages.emplace_back(R"(@badges=subscriber/12,premium/1;bits=2000;color=#B22222;display-name=arzenhuz;emotes=185989:33-37;id=1ae336ac-8e1a-4d6b-8b00-9fcee26e8337;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515783470139;turbo=0;user-id=111553331;user-type= :arzenhuz!arzenhuz@arzenhuz.tmi.twitch.tv PRIVMSG #pajlada :pajacheer2000 Buy pizza for both pajaH)"); - cheerMessages.emplace_back(R"(@badges=subscriber/12,premium/1;bits=37;color=#3FBF72;display-name=VADIKUS007;emotes=;id=eedd95fd-2a17-4da1-879c-a1e76ffce582;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515783184352;turbo=0;user-id=72256775;user-type= :vadikus007!vadikus007@vadikus007.tmi.twitch.tv PRIVMSG #pajlada :cheer37)"); - cheerMessages.emplace_back(R"(@badges=moderator/1,subscriber/24,bits/100;bits=1;color=#DCD3E6;display-name=swiftapples;emotes=80803:7-13;id=1c4647f6-f1a8-4acc-a9b2-b5d23d91258d;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1515538318854;turbo=0;user-id=80526177;user-type=mod :swiftapples!swiftapples@swiftapples.tmi.twitch.tv PRIVMSG #pajlada :cheer1 pajaHey)"); - cheerMessages.emplace_back(R"(@badges=subscriber/12,turbo/1;bits=1;color=#0A2927;display-name=Binkelderk;emotes=;id=a1d9bdc6-6f6a-4c03-8554-d5b34721a878;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515538899479;turbo=1;user-id=89081828;user-type= :binkelderk!binkelderk@binkelderk.tmi.twitch.tv PRIVMSG #pajlada :pajacheer1)"); - cheerMessages.emplace_back(R"(@badges=moderator/1,subscriber/24,bits/100;bits=1;color=#DCD3E6;display-name=swiftapples;emotes=80803:6-12;id=e9e21793-0b58-4ac6-8a1e-c19e165dbc9f;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1515539073209;turbo=0;user-id=80526177;user-type=mod :swiftapples!swiftapples@swiftapples.tmi.twitch.tv PRIVMSG #pajlada :bday1 pajaHey)"); - cheerMessages.emplace_back(R"(@badges=partner/1;bits=1;color=#CC44FF;display-name=pajlada;emotes=;id=ca89214e-4fb5-48ec-853e-d2e6b41355ea;mod=0;room-id=39705480;subscriber=0;tmi-sent-ts=1515546977622;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #leesherwhy :test123 owocheer1 456test)"); - cheerMessages.emplace_back(R"(@badges=subscriber/12,premium/1;bits=1;color=#3FBF72;display-name=VADIKUS007;emotes=;id=c4c5061b-f5c6-464b-8bff-7f1ac816caa7;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515782817171;turbo=0;user-id=72256775;user-type= :vadikus007!vadikus007@vadikus007.tmi.twitch.tv PRIVMSG #pajlada :trihard1)"); - cheerMessages.emplace_back(R"(@badges=;bits=1;color=#FF0000;display-name=?????;emotes=;id=979b6b4f-be9a-42fb-a54c-88fcb0aca18d;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1515782819084;turbo=0;user-id=70656218;user-type= :stels_tv!stels_tv@stels_tv.tmi.twitch.tv PRIVMSG #pajlada :trihard1)"); - cheerMessages.emplace_back(R"(@badges=subscriber/3,premium/1;bits=1;color=#FF0000;display-name=kalvarenga;emotes=;id=4744d6f0-de1d-475d-a3ff-38647113265a;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515782860740;turbo=0;user-id=108393131;user-type= :kalvarenga!kalvarenga@kalvarenga.tmi.twitch.tv PRIVMSG #pajlada :trihard1)"); + cheerMessages.emplace_back(R"(@badge-info=;badges=bits/1;bits=10;color=#008000;display-name=dGAussie;emotes=;flags=;id=5fb5ed1c-4e18-4a03-9cc7-4a69b7fedff7;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1566783370478;turbo=0;user-id=37141440;user-type= :dgaussie!dgaussie@dgaussie.tmi.twitch.tv PRIVMSG #pajlada :Cheer10 W00t podcast)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/1;badges=subscriber/0,bits/1;bits=1;color=#FF0000;display-name=FlameGodFlann;emotes=;flags=;id=93a63505-82f1-4a41-b573-2c63d6224db4;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1567283183354;turbo=0;user-id=56442185;user-type= :flamegodflann!flamegodflann@flamegodflann.tmi.twitch.tv PRIVMSG #pajlada :Cheer1 The Stella's gone back to the fridge, till nextime James!)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/4;badges=moderator/1,subscriber/3,sub-gifter/5;bits=1;color=#FF0000;display-name=69_faith_420;emotes=300443490:120-134;flags=;id=965515ff-c387-4779-9e85-cfb8c2e12423;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1567283108855;turbo=0;user-id=125608098;user-type=mod :69_faith_420!69_faith_420@69_faith_420.tmi.twitch.tv PRIVMSG #pajlada :cheer1 Lovely stream today! thanks for putting up with me, sorry if I talked too much. Take care tonight, stay hydrated comple42Hydrate)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/5;badges=moderator/1,subscriber/3,premium/1;bits=10;color=;display-name=Shedjunk;emotes=;flags=;id=af2a8991-9c85-456d-a6e7-cf7d909fa028;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1567283104905;turbo=0;user-id=52825550;user-type=mod :shedjunk!shedjunk@shedjunk.tmi.twitch.tv PRIVMSG #pajlada :@completeditmate Cheer10 Get your gums round these you bloody love albatross)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/4;badges=moderator/1,subscriber/3,sub-gifter/5;bits=1;color=#FF0000;display-name=69_faith_420;emotes=;flags=;id=d525a080-456c-419a-80e6-80ee9788f826;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1567282409412;turbo=0;user-id=125608098;user-type=mod :69_faith_420!69_faith_420@69_faith_420.tmi.twitch.tv PRIVMSG #pajlada :cheer1 By the way I've eaten about two slices of my pizza so far... ¯\_(ツ)_/¯)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/4;badges=moderator/1,subscriber/3,sub-gifter/5;bits=2;color=#FF0000;display-name=69_faith_420;emotes=;flags=;id=c5fd49c7-ecbc-46dd-a790-c9f10fdaaa67;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1567282184553;turbo=0;user-id=125608098;user-type=mod :69_faith_420!69_faith_420@69_faith_420.tmi.twitch.tv PRIVMSG #pajlada :cheer2 Stop what? I'm not doing anything.)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/4;badges=moderator/1,subscriber/3,sub-gifter/5;bits=2;color=#FF0000;display-name=69_faith_420;emotes=;flags=;id=397f4d2e-cac8-4689-922a-32709b9e8b4f;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1567282159076;turbo=0;user-id=125608098;user-type=mod :69_faith_420!69_faith_420@69_faith_420.tmi.twitch.tv PRIVMSG #pajlada :cheer2 Who keeps getting their bits out now?)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/1;badges=subscriber/0,bits/1;bits=2;color=#FF0000;display-name=FlameGodFlann;emotes=;flags=;id=664ddc92-649d-4889-9641-208a6e62ef1e;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1567282066199;turbo=0;user-id=56442185;user-type= :flamegodflann!flamegodflann@flamegodflann.tmi.twitch.tv PRIVMSG #pajlada :Cheer2 I'm saving my only can of Stella for your upcoming win, lets go!)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/3;badges=moderator/1,subscriber/3,bits/100;bits=10;color=#008000;display-name=k4izn;emotes=;flags=;id=3919af0b-93e0-412c-b238-d152f92ffea7;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1567811485257;turbo=0;user-id=207114672;user-type=mod :k4izn!k4izn@k4izn.tmi.twitch.tv PRIVMSG #pajlada :Cheer1 Cheer1 Cheer1 Cheer1 Cheer1 Cheer1 Cheer1 Cheer1 Cheer1 Cheer1 Kleiner Cheer(s) !)"); + cheerMessages.emplace_back(R"(@badge-info=subscriber/12;badges=subscriber/12,bits/1000;bits=20;color=#00CCFF;display-name=YaBoiBurnsy;emotes=;flags=;id=5b53975d-b339-484f-a2a0-3ffbedde0df2;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1567529634584;turbo=0;user-id=45258137;user-type= :yaboiburnsy!yaboiburnsy@yaboiburnsy.tmi.twitch.tv PRIVMSG #pajlada :ShowLove20)"); + cheerMessages.emplace_back(R"(@badge-info=;badges=bits/10000;bits=10000;color=;display-name=mathmaru;emotes=;flags=;id=00318434-150c-4a3b-8310-baa82942e7e9;mod=0;room-id=111448817;subscriber=0;tmi-sent-ts=1567273637572;turbo=0;user-id=151009486;user-type= :mathmaru!mathmaru@mathmaru.tmi.twitch.tv PRIVMSG #pajlada :cheer10000)"); + //cheerMessages.emplace_back(R"(@badges=subscriber/12,premium/1;bits=2000;color=#B22222;display-name=arzenhuz;emotes=185989:33-37;id=1ae336ac-8e1a-4d6b-8b00-9fcee26e8337;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515783470139;turbo=0;user-id=111553331;user-type= :arzenhuz!arzenhuz@arzenhuz.tmi.twitch.tv PRIVMSG #pajlada :pajacheer2000 Buy pizza for both pajaH)"); + //cheerMessages.emplace_back(R"(@badges=subscriber/12,premium/1;bits=37;color=#3FBF72;display-name=VADIKUS007;emotes=;id=eedd95fd-2a17-4da1-879c-a1e76ffce582;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515783184352;turbo=0;user-id=72256775;user-type= :vadikus007!vadikus007@vadikus007.tmi.twitch.tv PRIVMSG #pajlada :cheer37)"); + //cheerMessages.emplace_back(R"(@badges=moderator/1,subscriber/24,bits/100;bits=1;color=#DCD3E6;display-name=swiftapples;emotes=80803:7-13;id=1c4647f6-f1a8-4acc-a9b2-b5d23d91258d;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1515538318854;turbo=0;user-id=80526177;user-type=mod :swiftapples!swiftapples@swiftapples.tmi.twitch.tv PRIVMSG #pajlada :cheer1 pajaHey)"); + //cheerMessages.emplace_back(R"(@badges=subscriber/12,turbo/1;bits=1;color=#0A2927;display-name=Binkelderk;emotes=;id=a1d9bdc6-6f6a-4c03-8554-d5b34721a878;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515538899479;turbo=1;user-id=89081828;user-type= :binkelderk!binkelderk@binkelderk.tmi.twitch.tv PRIVMSG #pajlada :pajacheer1)"); + //cheerMessages.emplace_back(R"(@badges=moderator/1,subscriber/24,bits/100;bits=1;color=#DCD3E6;display-name=swiftapples;emotes=80803:6-12;id=e9e21793-0b58-4ac6-8a1e-c19e165dbc9f;mod=1;room-id=11148817;subscriber=1;tmi-sent-ts=1515539073209;turbo=0;user-id=80526177;user-type=mod :swiftapples!swiftapples@swiftapples.tmi.twitch.tv PRIVMSG #pajlada :bday1 pajaHey)"); + //cheerMessages.emplace_back(R"(@badges=partner/1;bits=1;color=#CC44FF;display-name=pajlada;emotes=;id=ca89214e-4fb5-48ec-853e-d2e6b41355ea;mod=0;room-id=39705480;subscriber=0;tmi-sent-ts=1515546977622;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #leesherwhy :test123 owocheer1 456test)"); + //cheerMessages.emplace_back(R"(@badges=subscriber/12,premium/1;bits=1;color=#3FBF72;display-name=VADIKUS007;emotes=;id=c4c5061b-f5c6-464b-8bff-7f1ac816caa7;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515782817171;turbo=0;user-id=72256775;user-type= :vadikus007!vadikus007@vadikus007.tmi.twitch.tv PRIVMSG #pajlada :trihard1)"); + //cheerMessages.emplace_back(R"(@badges=;bits=1;color=#FF0000;display-name=?????;emotes=;id=979b6b4f-be9a-42fb-a54c-88fcb0aca18d;mod=0;room-id=11148817;subscriber=0;tmi-sent-ts=1515782819084;turbo=0;user-id=70656218;user-type= :stels_tv!stels_tv@stels_tv.tmi.twitch.tv PRIVMSG #pajlada :trihard1)"); + //cheerMessages.emplace_back(R"(@badges=subscriber/3,premium/1;bits=1;color=#FF0000;display-name=kalvarenga;emotes=;id=4744d6f0-de1d-475d-a3ff-38647113265a;mod=0;room-id=11148817;subscriber=1;tmi-sent-ts=1515782860740;turbo=0;user-id=108393131;user-type= :kalvarenga!kalvarenga@kalvarenga.tmi.twitch.tv PRIVMSG #pajlada :trihard1)"); + subMessages.emplace_back(R"(@badges=staff/1,broadcaster/1,turbo/1;color=#008000;display-name=ronni;emotes=;id=db25007f-7a18-43eb-9379-80131e44d633;login=ronni;mod=0;msg-id=resub;msg-param-months=6;msg-param-sub-plan=Prime;msg-param-sub-plan-name=Prime;room-id=1337;subscriber=1;system-msg=ronni\shas\ssubscribed\sfor\s6\smonths!;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=staff :tmi.twitch.tv USERNOTICE #pajlada :Great stream -- keep it up!)"); subMessages.emplace_back(R"(@badges=staff/1,premium/1;color=#0000FF;display-name=TWW2;emotes=;id=e9176cd8-5e22-4684-ad40-ce53c2561c5e;login=tww2;mod=0;msg-id=subgift;msg-param-months=1;msg-param-recipient-display-name=Mr_Woodchuck;msg-param-recipient-id=89614178;msg-param-recipient-name=mr_woodchuck;msg-param-sub-plan-name=House\sof\sNyoro~n;msg-param-sub-plan=1000;room-id=19571752;subscriber=0;system-msg=TWW2\sgifted\sa\sTier\s1\ssub\sto\sMr_Woodchuck!;tmi-sent-ts=1521159445153;turbo=0;user-id=13405587;user-type=staff :tmi.twitch.tv USERNOTICE #pajlada)"); @@ -256,6 +268,13 @@ void Window::addDebugStuff() dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); }); + + createWindowShortcut(this, "F7", [=] { + const auto &messages = cheerMessages; + static int index = 0; + const auto &msg = messages[index++ % messages.size()]; + getApp()->twitch.server->addFakeMessage(msg); + }); #endif }