mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 16:28:36 -04:00
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.
40 lines
1.1 KiB
C#
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 ) );
|
|
}
|
|
}
|