mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Match game names exactly when using /setgame (#2825)
Co-authored-by: Paweł <zneix@zneix.eu> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
7e4f8be316
commit
faae2c2e8e
|
@ -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
|
||||
|
|
|
@ -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<TwitchChannel *>(channel.get()))
|
||||
{
|
||||
const auto gameName = words.mid(1).join(" ");
|
||||
|
||||
getHelix()->searchGames(
|
||||
words.mid(1).join(" "),
|
||||
[channel, twitchChannel](std::vector<HelixGame> games) {
|
||||
gameName,
|
||||
[channel, twitchChannel,
|
||||
gameName](const std::vector<HelixGame> &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(
|
||||
|
|
Loading…
Reference in a new issue