chore: migrate /vips command to Helix call (#4053)

* feat(helix): create response model for VIP listing

* feat(helix): stub out channel/vips request + handler

* feat(helix): parse VIPs list from data and pass to callback

* feat(helix): handle errors when getting VIP list then pass to callback

* feat(command): add barebones handler for helix-based /vips

* feat(command): provide better /vips output when user is not broadcaster

* chore(format): bulk reformat with clang-format

* chore(changelog): add entry for /vips Helix migration

* fix(helix): use correct method when calling VIP list endpoint

* fix(helix): use correct VIP list endpoint

* chore(tidy): please clang-tidy by marking parameter as unused

* feat(command): display unsorted VIP list returned from Helix API

* feat(settings): clone raid timegate settings for /vips

* feat(command): check /vips timegate setting before execution

* feat(command): handle 0 VIPs from Helix response

* feat(command): sort users alphabetically from Helix VIPs response

* fix(command): highlight users in Helix /vips output to match IRC

* fix(command): replace dynamic /vips error message with hardcoded string

* chore(comment): remove TODO comment that was DONE

* chore(format): bulk reformat using clang-format

* fix(command): send 0 VIP message after creation

* chore: apply suggestions from Felanbird

* fix(helix): change mention of user ban to VIPs in VIP list error message

* feat(helix): distinguish non-broadcaster auth error when getting VIPs

* chore(command): move handling of non-broadcaster /vips usage to API response

* chore(format): re-indent multiline string to get away from 80 char limit

* reformat

* fix tests

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
James Upjohn
2022-10-10 23:56:55 +13:00
committed by GitHub
parent e604a36777
commit ceecc7ef91
7 changed files with 290 additions and 0 deletions
+93
View File
@@ -1991,6 +1991,99 @@ void Helix::sendWhisper(
.execute();
}
// List the VIPs of a channel
// https://dev.twitch.tv/docs/api/reference#get-vips
void Helix::getChannelVIPs(
QString broadcasterID,
ResultCallback<std::vector<HelixVip>> successCallback,
FailureCallback<HelixListVIPsError, QString> failureCallback)
{
using Error = HelixListVIPsError;
QUrlQuery urlQuery;
urlQuery.addQueryItem("broadcaster_id", broadcasterID);
// No point pagi/pajanating, Twitch's max VIP count doesn't go over 100
// TODO(jammehcow): probably still implement pagination
// as the mod list can go over 100 (I assume, I see no limit)
urlQuery.addQueryItem("first", "100");
this->makeRequest("channels/vips", urlQuery)
.type(NetworkRequestType::Get)
.header("Content-Type", "application/json")
.onSuccess([successCallback](auto result) -> Outcome {
if (result.status() != 200)
{
qCWarning(chatterinoTwitch)
<< "Success result for getting VIPs was" << result.status()
<< "but we expected it to be 200";
}
auto response = result.parseJson();
std::vector<HelixVip> channelVips;
for (const auto &jsonStream : response.value("data").toArray())
{
channelVips.emplace_back(jsonStream.toObject());
}
successCallback(channelVips);
return Success;
})
.onError([failureCallback](auto result) {
auto obj = result.parseJson();
auto message = obj.value("message").toString();
switch (result.status())
{
case 400: {
failureCallback(Error::Forwarded, message);
}
break;
case 401: {
if (message.startsWith("Missing scope",
Qt::CaseInsensitive))
{
failureCallback(Error::UserMissingScope, message);
}
else if (message.compare(
"The ID in broadcaster_id must match the user "
"ID found in the request's OAuth token.",
Qt::CaseInsensitive) == 0)
{
// Must be the broadcaster.
failureCallback(Error::UserNotBroadcaster, message);
}
else
{
failureCallback(Error::Forwarded, message);
}
}
break;
case 403: {
failureCallback(Error::UserNotAuthorized, message);
}
break;
case 429: {
failureCallback(Error::Ratelimited, message);
}
break;
default: {
qCDebug(chatterinoTwitch)
<< "Unhandled error listing VIPs:" << result.status()
<< result.getData() << obj;
failureCallback(Error::Unknown, message);
}
break;
}
})
.execute();
}
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
{
assert(!url.startsWith("/"));