Migrate /announce command to Helix API. (#4003)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL
2022-09-24 17:50:02 +02:00
committed by GitHub
parent c692dd9b44
commit 8bda8a8b26
5 changed files with 185 additions and 0 deletions
@@ -1568,6 +1568,70 @@ void CommandController::initialize(Settings &, Paths &paths)
return "";
});
this->registerCommand(
"/announce", [](const QStringList &words, auto channel) -> QString {
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel == nullptr)
{
channel->addMessage(makeSystemMessage(
"This command can only be used in Twitch channels."));
return "";
}
if (words.size() < 2)
{
channel->addMessage(makeSystemMessage(
"Usage: /announce <message> - Call attention to your "
"message with a highlight."));
return "";
}
auto user = getApp()->accounts->twitch.getCurrent();
if (user->isAnon())
{
channel->addMessage(makeSystemMessage(
"You must be logged in to use the /announce command"));
return "";
}
getHelix()->sendChatAnnouncement(
twitchChannel->roomId(), user->getUserId(),
words.mid(1).join(" "), HelixAnnouncementColor::Primary,
[]() {
// do nothing.
},
[channel](auto error, auto message) {
using Error = HelixSendChatAnnouncementError;
QString errorMessage =
QString("Failed to send announcement - ");
switch (error)
{
case Error::UserMissingScope: {
// TODO(pajlada): Phrase MISSING_REQUIRED_SCOPE
errorMessage +=
"Missing required scope. Re-login with your "
"account and try again.";
}
break;
case Error::Forwarded: {
errorMessage += message;
}
break;
case Error::Unknown:
default: {
errorMessage += "An unknown error has occurred.";
}
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
});
return "";
});
}
void CommandController::save()