diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b24b4852..0b2a3494d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Minor: Added settings to disable custom FrankerFaceZ VIP/mod badges. (#2693, #2759) - Minor: Limit the number of recent chatters to improve memory usage and reduce freezes. (#2796, #2814) - Minor: Added `/popout` command. Usage: `/popout [channel]`. It opens browser chat for the provided channel. Can also be used without arguments to open current channels browser chat. (#2556, #2812) +- Minor: Improved matching of game names when using `/setgame` command (#2636) - Bugfix: Fixed FFZ emote links for global emotes (#2807, #2808) ## 2.3.2 diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index cbf003c50..3b4ba2f4f 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -722,7 +722,7 @@ void CommandController::initialize(Settings &, Paths &paths) return ""; }); this->registerCommand("/setgame", [](const QStringList &words, - ChannelPtr channel) { + const ChannelPtr channel) { if (words.size() < 2) { channel->addMessage( @@ -731,30 +731,48 @@ void CommandController::initialize(Settings &, Paths &paths) } if (auto twitchChannel = dynamic_cast(channel.get())) { + const auto gameName = words.mid(1).join(" "); + getHelix()->searchGames( - words.mid(1).join(" "), - [channel, twitchChannel](std::vector games) { + gameName, + [channel, twitchChannel, + gameName](const std::vector &games) { if (games.empty()) { channel->addMessage( makeSystemMessage("Game not found.")); + return; } - else // 1 or more games + + auto matchedGame = games.at(0); + + if (games.size() > 1) { - auto status = twitchChannel->accessStreamStatus(); - getHelix()->updateChannel( - twitchChannel->roomId(), games.at(0).id, "", "", - [channel, games](NetworkResult) { - channel->addMessage(makeSystemMessage( - QString("Updated game to %1") - .arg(games.at(0).name))); - }, - [channel] { - channel->addMessage(makeSystemMessage( - "Game update failed! Are you " - "missing the required scope?")); - }); + // NOTE: Improvements could be made with 'fuzzy string matching' code here + // attempt to find the best looking game by comparing exactly with lowercase values + for (const auto &game : games) + { + if (game.name.toLower() == gameName.toLower()) + { + matchedGame = game; + break; + } + } } + + auto status = twitchChannel->accessStreamStatus(); + getHelix()->updateChannel( + twitchChannel->roomId(), matchedGame.id, "", "", + [channel, games, matchedGame](const NetworkResult &) { + channel->addMessage( + makeSystemMessage(QString("Updated game to %1") + .arg(matchedGame.name))); + }, + [channel] { + channel->addMessage(makeSystemMessage( + "Game update failed! Are you " + "missing the required scope?")); + }); }, [channel] { channel->addMessage(