Add /setgame and /settitle (#2534)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL
2021-04-04 15:31:08 +00:00
committed by GitHub
parent dff2629e81
commit f9246a9e3a
7 changed files with 151 additions and 0 deletions
@@ -643,7 +643,85 @@ void CommandController::initialize(Settings &, Paths &paths)
getApp()->windows->getMainWindow().getNotebook().getSelectedPage());
currentPage->getSelectedSplit()->getChannelView().clearMessages();
return "";
});
this->registerCommand("/settitle", [](const QStringList &words,
ChannelPtr channel) {
if (words.size() < 2)
{
channel->addMessage(
makeSystemMessage("Usage: /settitle <stream title>."));
return "";
}
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
{
auto status = twitchChannel->accessStreamStatus();
auto title = words.mid(1).join(" ");
getHelix()->updateChannel(
twitchChannel->roomId(), "", "", title,
[channel, title](NetworkResult) {
channel->addMessage(makeSystemMessage(
QString("Updated title to %1").arg(title)));
},
[channel] {
channel->addMessage(
makeSystemMessage("Title update failed! Are you "
"missing the required scope?"));
});
}
else
{
channel->addMessage(makeSystemMessage(
"Unable to set title of non-Twitch channel."));
}
return "";
});
this->registerCommand("/setgame", [](const QStringList &words,
ChannelPtr channel) {
if (words.size() < 2)
{
channel->addMessage(
makeSystemMessage("Usage: /setgame <stream game>."));
return "";
}
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
{
getHelix()->fetchGames(
QStringList(), {words.mid(1).join(" ")},
[channel, twitchChannel](std::vector<HelixGame> games) {
if (games.size() == 0)
{
channel->addMessage(
makeSystemMessage("Game not found."));
}
else // 0 or 1 games
{
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?"));
});
}
},
[channel] {
channel->addMessage(
makeSystemMessage("Failed to look up game."));
});
}
else
{
channel->addMessage(
makeSystemMessage("Unable to set game of non-Twitch channel."));
}
return "";
});
}