diff --git a/CHANGELOG.md b/CHANGELOG.md index a20663931..25d5ba304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Major: Added clip creation support. You can create clips with `/clip` command, `Alt+X` keybind or `Create a clip` option in split header's context menu. This requires a new authentication scope so re-authentication will be required to use it. (#2271, #2377, #2528) - Major: Added "Channel Filters". See https://wiki.chatterino.com/Filters/ for how they work or how to configure them. (#1748, #2083, #2090, #2200, #2225) - Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001, #2316, #2342, #2376) -- Major: Add `/settitle` and `/setgame` commands, originally made for Mm2PL/Dankerino. (#2534) +- Major: Add `/settitle` and `/setgame` commands, originally made for Mm2PL/Dankerino. (#2534, #2609) - Major: Color mentions to match the mentioned users. You can disable this by unchecking "Color @usernames" under `Settings -> General -> Advanced (misc.)`. (#1963, #2284) - Major: Commands `/ignore` and `/unignore` have been renamed to `/block` and `/unblock` in order to keep consistency with Twitch's terms. (#2370) - Major: Added support for bit emotes - the ones you unlock after cheering to streamer. (#2550) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 644bb5b39..e6b7a9414 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -687,15 +687,15 @@ void CommandController::initialize(Settings &, Paths &paths) } if (auto twitchChannel = dynamic_cast(channel.get())) { - getHelix()->fetchGames( - QStringList(), {words.mid(1).join(" ")}, + getHelix()->searchGames( + words.mid(1).join(" "), [channel, twitchChannel](std::vector games) { - if (games.size() == 0) + if (games.empty()) { channel->addMessage( makeSystemMessage("Game not found.")); } - else // 0 or 1 games + else // 1 or more games { auto status = twitchChannel->accessStreamStatus(); getHelix()->updateChannel( diff --git a/src/providers/twitch/api/Helix.cpp b/src/providers/twitch/api/Helix.cpp index 28eaf410f..0af299970 100644 --- a/src/providers/twitch/api/Helix.cpp +++ b/src/providers/twitch/api/Helix.cpp @@ -296,6 +296,42 @@ void Helix::fetchGames(QStringList gameIds, QStringList gameNames, .execute(); } +void Helix::searchGames(QString gameName, + ResultCallback> successCallback, + HelixFailureCallback failureCallback) +{ + QUrlQuery urlQuery; + urlQuery.addQueryItem("query", gameName); + + this->makeRequest("search/categories", urlQuery) + .onSuccess([successCallback, failureCallback](auto result) -> Outcome { + auto root = result.parseJson(); + auto data = root.value("data"); + + if (!data.isArray()) + { + failureCallback(); + return Failure; + } + + std::vector games; + + for (const auto &jsonStream : data.toArray()) + { + games.emplace_back(jsonStream.toObject()); + } + + successCallback(games); + + return Success; + }) + .onError([failureCallback](auto /*result*/) { + // TODO: make better xd + failureCallback(); + }) + .execute(); +} + void Helix::getGameById(QString gameId, ResultCallback successCallback, HelixFailureCallback failureCallback) diff --git a/src/providers/twitch/api/Helix.hpp b/src/providers/twitch/api/Helix.hpp index 38fc153d1..ea5c7beed 100644 --- a/src/providers/twitch/api/Helix.hpp +++ b/src/providers/twitch/api/Helix.hpp @@ -252,6 +252,11 @@ public: ResultCallback> successCallback, HelixFailureCallback failureCallback); + // https://dev.twitch.tv/docs/api/reference#search-categories + void searchGames(QString gameName, + ResultCallback> successCallback, + HelixFailureCallback failureCallback); + void getGameById(QString gameId, ResultCallback successCallback, HelixFailureCallback failureCallback); diff --git a/src/providers/twitch/api/README.md b/src/providers/twitch/api/README.md index ddea624ef..779758fe3 100644 --- a/src/providers/twitch/api/README.md +++ b/src/providers/twitch/api/README.md @@ -152,6 +152,14 @@ Requires `user:manage:blocked_users` scope - `widgets/dialogs/UserInfoPopup.cpp` to unblock a user via checkbox in the usercard - `controllers/commands/CommandController.cpp` to unblock a user via "/unblock" command +### Search Categories + +URL: https://dev.twitch.tv/docs/api/reference#search-categories + +- We implement this in `providers/twitch/api/Helix.cpp searchGames` + Used in: + - `controllers/commands/CommandController.cpp` in `/setgame` command to fuzzy search for game titles + ## TMI The TMI api is undocumented.