mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Allow Commercial API endpoint to handle commercial lengths (#4141)
This commit is contained in:
parent
f86b5b90a8
commit
46cdb89498
|
@ -71,7 +71,7 @@
|
||||||
- Minor: Migrated /vips to Helix API. Chat command will continue to be used until February 11th 2023. (#4053)
|
- Minor: Migrated /vips to Helix API. Chat command will continue to be used until February 11th 2023. (#4053)
|
||||||
- Minor: Migrated /uniquechat and /r9kbeta to Helix API. (#4057)
|
- Minor: Migrated /uniquechat and /r9kbeta to Helix API. (#4057)
|
||||||
- Minor: Migrated /uniquechatoff and /r9kbetaoff to Helix API. (#4057)
|
- Minor: Migrated /uniquechatoff and /r9kbetaoff to Helix API. (#4057)
|
||||||
- Minor: Migrated /commercial to Helix API. (#4094)
|
- Minor: Migrated /commercial to Helix API. (#4094, #4141)
|
||||||
- Minor: Added stream titles to windows live toast notifications. (#1297)
|
- Minor: Added stream titles to windows live toast notifications. (#1297)
|
||||||
- Minor: Make menus and placeholders display appropriate custom key combos. (#4045)
|
- Minor: Make menus and placeholders display appropriate custom key combos. (#4045)
|
||||||
- Minor: Migrated /chatters to Helix API. (#4088, #4097, #4114)
|
- Minor: Migrated /chatters to Helix API. (#4088, #4097, #4114)
|
||||||
|
|
|
@ -2847,6 +2847,13 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Error::MissingLengthParameter: {
|
||||||
|
errorMessage +=
|
||||||
|
"Command must include a desired commercial break "
|
||||||
|
"length that is greater than zero.";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Error::Ratelimited: {
|
case Error::Ratelimited: {
|
||||||
errorMessage += "You must wait until your cooldown period "
|
errorMessage += "You must wait until your cooldown period "
|
||||||
"expires before you can run another "
|
"expires before you can run another "
|
||||||
|
@ -3009,29 +3016,16 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
auto broadcasterID = tc->roomId();
|
auto broadcasterID = tc->roomId();
|
||||||
auto length = words.at(1).toInt();
|
auto length = words.at(1).toInt();
|
||||||
|
|
||||||
// We would prefer not to early out here and rather handle the API error
|
|
||||||
// like the rest of them, but the API doesn't give us a proper length error.
|
|
||||||
// Valid lengths can be found in the length body parameter description
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#start-commercial
|
|
||||||
const QList<int> validLengths = {30, 60, 90, 120, 150, 180};
|
|
||||||
if (!validLengths.contains(length))
|
|
||||||
{
|
|
||||||
channel->addMessage(makeSystemMessage(
|
|
||||||
"Invalid commercial duration length specified. Valid "
|
|
||||||
"options "
|
|
||||||
"are 30, 60, 90, 120, 150, and 180 seconds"));
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
getHelix()->startCommercial(
|
getHelix()->startCommercial(
|
||||||
broadcasterID, length,
|
broadcasterID, length,
|
||||||
[channel](auto response) {
|
[channel](auto response) {
|
||||||
channel->addMessage(makeSystemMessage(
|
channel->addMessage(makeSystemMessage(
|
||||||
QString("Starting commercial break. Keep in mind you "
|
QString("Starting %1 second long commercial break. "
|
||||||
"are still "
|
"Keep in mind you are still "
|
||||||
"live and not all viewers will receive a "
|
"live and not all viewers will receive a "
|
||||||
"commercial. "
|
"commercial. "
|
||||||
"You may run another commercial in %1 seconds.")
|
"You may run another commercial in %2 seconds.")
|
||||||
|
.arg(response.length)
|
||||||
.arg(response.retryAfter)));
|
.arg(response.retryAfter)));
|
||||||
},
|
},
|
||||||
[channel, formatStartCommercialError](auto error,
|
[channel, formatStartCommercialError](auto error,
|
||||||
|
|
|
@ -2398,6 +2398,11 @@ void Helix::startCommercial(
|
||||||
failureCallback(Error::BroadcasterNotStreaming,
|
failureCallback(Error::BroadcasterNotStreaming,
|
||||||
message);
|
message);
|
||||||
}
|
}
|
||||||
|
else if (message.startsWith("Missing required parameter",
|
||||||
|
Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
failureCallback(Error::MissingLengthParameter, message);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
failureCallback(Error::Forwarded, message);
|
failureCallback(Error::Forwarded, message);
|
||||||
|
|
|
@ -620,6 +620,7 @@ enum class HelixStartCommercialError {
|
||||||
TokenMustMatchBroadcaster,
|
TokenMustMatchBroadcaster,
|
||||||
UserMissingScope,
|
UserMissingScope,
|
||||||
BroadcasterNotStreaming,
|
BroadcasterNotStreaming,
|
||||||
|
MissingLengthParameter,
|
||||||
Ratelimited,
|
Ratelimited,
|
||||||
|
|
||||||
// The error message is forwarded directly from the Twitch API
|
// The error message is forwarded directly from the Twitch API
|
||||||
|
|
Loading…
Reference in a new issue