Files
sbox-public/engine/Sandbox.Engine/Platform/Stream/Twitch/TwitchAPI.Channels.cs
Garry Newman 62feec4b64 Twitch Api (#5016)
Engine: reworks Twitch IRC parsing/client + Streamer event surface (viewers roster, chat/sub/gift/raid messages) and removes older/broken Twitch API features.

Menu/Editor: adds service linking/stream-connect UI (new Services modal; pause/game modal + editor title button) gated by a project setting.

Services/utilities: introduces helper APIs for linking/listing services; adds unit tests for the IRC parser and subscription tier parsing.
2026-06-06 21:46:13 +01:00

40 lines
1.1 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace Sandbox.Twitch;
internal partial class TwitchAPI
{
/// <summary>
/// A channel update. Only the non-null fields are sent, so each setter
/// patches a single property.
/// </summary>
internal class UpdateChannelRequest
{
[JsonPropertyName( "broadcaster_language" )]
public string Language { get; set; }
[JsonPropertyName( "delay" )]
public int? Delay { get; set; }
}
private static readonly JsonSerializerOptions IgnoreNulls = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
public Task SetChannelLanguage( string userId, string language )
{
return UpdateChannel( userId, new UpdateChannelRequest { Language = language } );
}
public Task SetChannelDelay( string userId, int delay )
{
return UpdateChannel( userId, new UpdateChannelRequest { Delay = delay } );
}
private Task UpdateChannel( string userId, UpdateChannelRequest update )
{
return Patch( $"/channels?broadcaster_id={userId}", JsonSerializer.Serialize( update, IgnoreNulls ) );
}
}