Implement /marker command (#2360)
This command works the same as it does on Twitch web chat - it creates a streamer marker at the current timestamp with an optional description
This commit is contained in:
@@ -442,6 +442,66 @@ void Helix::getChannel(QString broadcasterId,
|
||||
.execute();
|
||||
}
|
||||
|
||||
void Helix::createStreamMarker(
|
||||
QString broadcasterId, QString description,
|
||||
ResultCallback<HelixStreamMarker> successCallback,
|
||||
std::function<void(HelixStreamMarkerError)> failureCallback)
|
||||
{
|
||||
QJsonObject payload;
|
||||
|
||||
if (!description.isEmpty())
|
||||
{
|
||||
payload.insert("description", QJsonValue(description));
|
||||
}
|
||||
payload.insert("user_id", QJsonValue(broadcasterId));
|
||||
|
||||
this->makeRequest("streams/markers", QUrlQuery())
|
||||
.type(NetworkRequestType::Post)
|
||||
.header("Content-Type", "application/json")
|
||||
.payload(QJsonDocument(payload).toJson(QJsonDocument::Compact))
|
||||
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
auto data = root.value("data");
|
||||
|
||||
if (!data.isArray())
|
||||
{
|
||||
failureCallback(HelixStreamMarkerError::Unknown);
|
||||
return Failure;
|
||||
}
|
||||
|
||||
HelixStreamMarker streamMarker(data.toArray()[0].toObject());
|
||||
|
||||
successCallback(streamMarker);
|
||||
return Success;
|
||||
})
|
||||
.onError([failureCallback](NetworkResult result) {
|
||||
switch (result.status())
|
||||
{
|
||||
case 403: {
|
||||
// User isn't a Channel Editor, so he can't create markers
|
||||
failureCallback(HelixStreamMarkerError::UserNotAuthorized);
|
||||
}
|
||||
break;
|
||||
|
||||
case 401: {
|
||||
// User does not have the required scope to be able to create stream markers, user must reauthenticate
|
||||
failureCallback(
|
||||
HelixStreamMarkerError::UserNotAuthenticated);
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
qCDebug(chatterinoTwitch)
|
||||
<< "Failed to create a stream marker: "
|
||||
<< result.status() << result.getData();
|
||||
failureCallback(HelixStreamMarkerError::Unknown);
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
.execute();
|
||||
};
|
||||
|
||||
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
|
||||
{
|
||||
assert(!url.startsWith("/"));
|
||||
|
||||
@@ -165,12 +165,33 @@ struct HelixChannel {
|
||||
}
|
||||
};
|
||||
|
||||
struct HelixStreamMarker {
|
||||
QString createdAt;
|
||||
QString description;
|
||||
QString id;
|
||||
int positionSeconds;
|
||||
|
||||
explicit HelixStreamMarker(QJsonObject jsonObject)
|
||||
: createdAt(jsonObject.value("created_at").toString())
|
||||
, description(jsonObject.value("description").toString())
|
||||
, id(jsonObject.value("id").toString())
|
||||
, positionSeconds(jsonObject.value("position_seconds").toInt())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
enum class HelixClipError {
|
||||
Unknown,
|
||||
ClipsDisabled,
|
||||
UserNotAuthenticated,
|
||||
};
|
||||
|
||||
enum class HelixStreamMarkerError {
|
||||
Unknown,
|
||||
UserNotAuthorized,
|
||||
UserNotAuthenticated,
|
||||
};
|
||||
|
||||
class Helix final : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
@@ -242,6 +263,12 @@ public:
|
||||
ResultCallback<HelixChannel> successCallback,
|
||||
HelixFailureCallback failureCallback);
|
||||
|
||||
// https://dev.twitch.tv/docs/api/reference/#create-stream-marker
|
||||
void createStreamMarker(
|
||||
QString broadcasterId, QString description,
|
||||
ResultCallback<HelixStreamMarker> successCallback,
|
||||
std::function<void(HelixStreamMarkerError)> failureCallback);
|
||||
|
||||
void update(QString clientId, QString oauthToken);
|
||||
|
||||
static void initialize();
|
||||
|
||||
@@ -84,7 +84,7 @@ URL: https://dev.twitch.tv/docs/api/reference#get-streams
|
||||
URL: https://dev.twitch.tv/docs/api/reference#create-user-follows
|
||||
Requires `user:edit:follows` scope
|
||||
|
||||
* We implement this in `providers/twitch/api/Helix.cpp followUser`
|
||||
* We implement this in `providers/twitch/api/Helix.cpp followUser`
|
||||
Used in:
|
||||
* `widgets/dialogs/UserInfoPopup.cpp` to follow a user by ticking follow checkbox in usercard
|
||||
* `controllers/commands/CommandController.cpp` in /follow command
|
||||
@@ -93,7 +93,7 @@ Requires `user:edit:follows` scope
|
||||
URL: https://dev.twitch.tv/docs/api/reference#delete-user-follows
|
||||
Requires `user:edit:follows` scope
|
||||
|
||||
* We implement this in `providers/twitch/api/Helix.cpp unfollowUser`
|
||||
* We implement this in `providers/twitch/api/Helix.cpp unfollowUser`
|
||||
Used in:
|
||||
* `widgets/dialogs/UserInfoPopup.cpp` to unfollow a user by unticking follow checkbox in usercard
|
||||
* `controllers/commands/CommandController.cpp` in /unfollow command
|
||||
@@ -102,7 +102,7 @@ Requires `user:edit:follows` scope
|
||||
URL: https://dev.twitch.tv/docs/api/reference#create-clip
|
||||
Requires `clips:edit` scope
|
||||
|
||||
* We implement this in `providers/twitch/api/Helix.cpp createClip`
|
||||
* We implement this in `providers/twitch/api/Helix.cpp createClip`
|
||||
Used in:
|
||||
* `TwitchChannel` to create a clip of a live broadcast
|
||||
|
||||
@@ -113,6 +113,14 @@ URL: https://dev.twitch.tv/docs/api/reference#get-channel-information
|
||||
Used in:
|
||||
* `TwitchChannel` to refresh stream title
|
||||
|
||||
### Create Stream Marker
|
||||
URL: https://dev.twitch.tv/docs/api/reference/#create-stream-marker
|
||||
Requires `user:edit:broadcast` scope
|
||||
|
||||
* We implement this in `providers/twitch/api/Helix.cpp createStreamMarker`
|
||||
Used in:
|
||||
* `controllers/commands/CommandController.cpp` in /marker command
|
||||
|
||||
## TMI
|
||||
The TMI api is undocumented.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user