Migrate /chatters commands to use Helix api (#4088)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Colton Clemmer
2022-11-01 17:18:57 -05:00
committed by GitHub
parent abb69f6794
commit 495f3ed4a9
6 changed files with 257 additions and 59 deletions
+53 -11
View File
@@ -878,23 +878,65 @@ void CommandController::initialize(Settings &, Paths &paths)
return "";
});
this->registerCommand(
"/chatters", [](const auto & /*words*/, auto channel) {
auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
this->registerCommand("/chatters", [](const auto &words, auto channel) {
auto formatError = [](HelixGetChattersError error, QString message) {
using Error = HelixGetChattersError;
if (twitchChannel == nullptr)
QString errorMessage = QString("Failed to get chatter count: ");
switch (error)
{
channel->addMessage(makeSystemMessage(
"The /chatters command only works in Twitch Channels"));
return "";
case Error::Forwarded: {
errorMessage += message;
}
break;
case Error::UserMissingScope: {
errorMessage += "Missing required scope. "
"Re-login with your "
"account and try again.";
}
break;
case Error::UserNotAuthorized: {
errorMessage += "You must have moderator permissions to "
"use this command.";
}
break;
case Error::Unknown: {
errorMessage += "An unknown error has occurred.";
}
break;
}
return errorMessage;
};
auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel == nullptr)
{
channel->addMessage(makeSystemMessage(
QString("Chatter count: %1")
.arg(localizeNumbers(twitchChannel->chatterCount()))));
"The /chatters command only works in Twitch Channels"));
return "";
});
}
// Refresh chatter list via helix api for mods
getHelix()->getChatters(
twitchChannel->roomId(),
getApp()->accounts->twitch.getCurrent()->getUserId(), 1,
[channel](auto result) {
channel->addMessage(
makeSystemMessage(QString("Chatter count: %1")
.arg(localizeNumbers(result.total))));
},
[channel, formatError](auto error, auto message) {
auto errorMessage = formatError(error, message);
channel->addMessage(makeSystemMessage(errorMessage));
});
return "";
});
this->registerCommand("/clip", [](const auto & /*words*/, auto channel) {
if (const auto type = channel->getType();