Implement Helix Search Categories end-point & update /setgame (#2609)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Yoitsu 2021-04-11 02:34:27 +03:00 committed by GitHub
parent 00ccdbc781
commit a448af5f57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 5 deletions

View file

@ -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)

View file

@ -687,15 +687,15 @@ void CommandController::initialize(Settings &, Paths &paths)
}
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
{
getHelix()->fetchGames(
QStringList(), {words.mid(1).join(" ")},
getHelix()->searchGames(
words.mid(1).join(" "),
[channel, twitchChannel](std::vector<HelixGame> 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(

View file

@ -296,6 +296,42 @@ void Helix::fetchGames(QStringList gameIds, QStringList gameNames,
.execute();
}
void Helix::searchGames(QString gameName,
ResultCallback<std::vector<HelixGame>> 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<HelixGame> 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<HelixGame> successCallback,
HelixFailureCallback failureCallback)

View file

@ -252,6 +252,11 @@ public:
ResultCallback<std::vector<HelixGame>> successCallback,
HelixFailureCallback failureCallback);
// https://dev.twitch.tv/docs/api/reference#search-categories
void searchGames(QString gameName,
ResultCallback<std::vector<HelixGame>> successCallback,
HelixFailureCallback failureCallback);
void getGameById(QString gameId, ResultCallback<HelixGame> successCallback,
HelixFailureCallback failureCallback);

View file

@ -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.