Implement Helix Search Categories end-point & update /setgame (#2609)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user