Skip to content

Commit

Permalink
Merge pull request #32 from meenzen/feat/more-event-types
Browse files Browse the repository at this point in the history
feat: support more event types
  • Loading branch information
meenzen authored Oct 9, 2023
2 parents 71e5905 + a4c8ea5 commit 918a7be
Show file tree
Hide file tree
Showing 24 changed files with 924 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Streamlabs.SocketClient.Extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Streamlabs.SocketClient.Extensions

See [Streamlabs.SocketClient](https://www.nuget.org/packages/Streamlabs.SocketClient.Extensions) for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<ItemGroup>
<ProjectReference Include="..\Streamlabs.SocketClient\Streamlabs.SocketClient.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="/" />
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions src/Streamlabs.SocketClient/Converters/IntStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Converters;

internal sealed class IntStringConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return int.Parse(
reader.GetString() ?? throw new InvalidOperationException("String is null"),
NumberStyles.AllowThousands,
CultureInfo.InvariantCulture
);
}

public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ namespace Streamlabs.SocketClient.Events.Abstractions;
[JsonDerivedType(typeof(AlertPlayingEvent), typeDiscriminator: "alertPlaying")]
[JsonDerivedType(typeof(BitsEvent), typeDiscriminator: "bits")]
[JsonDerivedType(typeof(FollowEvent), typeDiscriminator: "follow")]
[JsonDerivedType(typeof(RaidEvent), typeDiscriminator: "raid")]
[JsonDerivedType(typeof(RollEndCreditsEvent), typeDiscriminator: "rollEndCredits")]
[JsonDerivedType(typeof(StreamlabelsEvent), typeDiscriminator: "streamlabels")]
public interface IStreamlabsEvent { }
2 changes: 1 addition & 1 deletion src/Streamlabs.SocketClient/Events/FollowEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Streamlabs.SocketClient.Events;

public class FollowEvent : IStreamlabsEvent, IHasStreamlabsMessageCollection<FollowMessage>, IHasEventId
public sealed record FollowEvent : IStreamlabsEvent, IHasStreamlabsMessageCollection<FollowMessage>, IHasEventId
{
[JsonPropertyName("message")]
public required IReadOnlyCollection<FollowMessage> Messages { get; init; }
Expand Down
14 changes: 14 additions & 0 deletions src/Streamlabs.SocketClient/Events/RaidEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Streamlabs.SocketClient.Events.Abstractions;
using Streamlabs.SocketClient.Messages;
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Events;

public sealed record RaidEvent : IStreamlabsEvent, IHasStreamlabsMessageCollection<RaidMessage>
{
[JsonPropertyName("message")]
public required IReadOnlyCollection<RaidMessage> Messages { get; init; }

[JsonPropertyName("for")]
public required string For { get; init; }
}
14 changes: 14 additions & 0 deletions src/Streamlabs.SocketClient/Events/RollEndCreditsEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Streamlabs.SocketClient.Events.Abstractions;
using Streamlabs.SocketClient.Messages;
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Events;

public sealed record RollEndCreditsEvent : IStreamlabsEvent, IHasStreamlabsMessage<RollEndCreditsMessage>, IHasEventId
{
[JsonPropertyName("message")]
public required RollEndCreditsMessage Message { get; init; }

[JsonPropertyName("event_id")]
public required string EventId { get; init; }
}
14 changes: 14 additions & 0 deletions src/Streamlabs.SocketClient/Events/StreamlabelsEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Streamlabs.SocketClient.Events.Abstractions;
using Streamlabs.SocketClient.Messages;
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Events;

public sealed record StreamlabelsEvent : IStreamlabsEvent, IHasStreamlabsMessage<StreamlabelsMessage>, IHasEventId
{
[JsonPropertyName("message")]
public required StreamlabelsMessage Message { get; init; }

[JsonPropertyName("event_id")]
public required string EventId { get; init; }
}
3 changes: 3 additions & 0 deletions src/Streamlabs.SocketClient/IStreamlabsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public interface IStreamlabsClient : IDisposable
event EventHandler<BitsAlertPlayingMessage>? OnBitsAlertPlaying;
event EventHandler<SubscriptionAlertPlayingMessage>? OnSubscriptionAlertPlaying;
event EventHandler<FollowMessage>? OnFollow;
event EventHandler<RaidMessage>? OnRaid;
event EventHandler<RollEndCreditsMessage>? OnRollEndCredits;
event EventHandler<StreamlabelsMessage>? OnStreamlabelsMessage;
}
2 changes: 1 addition & 1 deletion src/Streamlabs.SocketClient/Messages/BitsMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Streamlabs.SocketClient.Messages;

public class BitsMessage
public sealed record BitsMessage
: IStreamlabsMessage,
IHasId<Guid>,
IHasName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
namespace Streamlabs.SocketClient.Messages.DataTypes;

[SuppressMessage("Minor Code Smell", "S2094:Classes should not be empty")]
public record EmptyPayload : IPayload;
public sealed record EmptyPayload : IPayload;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Messages.DataTypes;

public sealed record LabeledCollection<T>
{
[JsonPropertyName("label")]
public required string Label { get; init; }

[JsonPropertyName("values")]
public required IReadOnlyCollection<T> Values { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Streamlabs.SocketClient.Messages.Abstractions;
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Messages.DataTypes;

public sealed record RollEndCreditsPayload : IHasMessageId, IHasPriority
{
/// <summary>
/// A list of users that donated
/// </summary>
[JsonPropertyName("donations")]
public LabeledCollection<string>? Donations { get; init; }

/// <summary>
/// A list of users that used bits
/// </summary>
[JsonPropertyName("bits")]
public LabeledCollection<string>? Bits { get; init; }

/// <summary>
/// A list of users that are moderators
/// </summary>
[JsonPropertyName("moderators")]
public LabeledCollection<string>? Moderators { get; init; }

/// <summary>
/// A list of users that followed
/// </summary>
[JsonPropertyName("followers")]
public LabeledCollection<string>? Followers { get; init; }

/// <summary>
/// A list of users that subscribed or resubscribed
/// </summary>
[JsonPropertyName("subscribers")]
public LabeledCollection<string>? Subscribers { get; init; }

/// <summary>
/// A list of channels that raided
/// </summary>
public LabeledCollection<string>? Raids { get; init; }

/// <summary>
/// A list of channels that hosted
/// </summary>
public LabeledCollection<string>? Hosts { get; init; }

[JsonPropertyName("_id")]
public required string MessageId { get; init; }

[JsonPropertyName("priority")]
public required long Priority { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using Streamlabs.SocketClient.Messages.Abstractions;
using System.Text.Json.Serialization;

namespace Streamlabs.SocketClient.Messages.DataTypes;

public sealed record RollEndCreditsSettings : IHasMessageId, IHasPriority
{
[JsonPropertyName("theme")]
public required string Theme { get; init; }

[JsonPropertyName("donations")]
public required bool Donations { get; init; }

[JsonPropertyName("credit_title")]
public required string CreditTitle { get; init; }

[JsonPropertyName("credit_subtitle")]
public required string CreditSubTitle { get; init; }

[JsonPropertyName("donor_change")]
public required string DonorChange { get; init; }

[JsonPropertyName("loop_credits")]
public required bool LoopCredits { get; init; }

[JsonPropertyName("delay_time")]
public required int DelayTime { get; init; }

[JsonPropertyName("roll_speed")]
public required int RollSpeed { get; init; }

/// <summary>
/// The background color (hex)
/// </summary>
[JsonPropertyName("background_color")]
public required string BackgroundColor { get; init; }

[JsonPropertyName("font")]
public required string Font { get; init; }

/// <summary>
/// The font color (hex)
/// </summary>
[JsonPropertyName("font_color")]
public required string FontColor { get; init; }

[JsonPropertyName("font_size")]
public required int FontSize { get; init; }

[JsonPropertyName("roll_time")]
public required int RollTime { get; init; }

[JsonPropertyName("roll_options")]
public required string RollOptions { get; init; }

[JsonPropertyName("custom_enabled")]
public required bool CustomEnabled { get; init; }

[JsonPropertyName("custom_html")]
public required string CustomHtml { get; init; }

[JsonPropertyName("custom_css")]
public required string CustomCss { get; init; }

[JsonPropertyName("custom_js")]
public required string CustomJs { get; init; }

[JsonPropertyName("custom_json")]
public required string? CustomJson { get; init; }

[JsonPropertyName("show_amounts")]
public required bool ShowAmounts { get; init; }

[JsonPropertyName("roll_credits_on_load")]
public required bool RollCreditsOnLoad { get; init; }

[JsonPropertyName("followers")]
public required bool Followers { get; init; }

[JsonPropertyName("subscribers")]
public required bool Subscribers { get; init; }

[JsonPropertyName("bits")]
public required bool Bits { get; init; }

[JsonPropertyName("moderators")]
public required bool Moderators { get; init; }

[JsonPropertyName("raids")]
public required bool Raids { get; init; }

[JsonPropertyName("hosts")]
public required bool Hosts { get; init; }

[JsonPropertyName("followers_change")]
public required string FollowersChange { get; init; }

/// <summary>
/// This property is HTML encoded
/// </summary>
[JsonPropertyName("subscribers_change")]
public required string SubscribersChange { get; init; }

[JsonPropertyName("bits_change")]
public required string BitsChange { get; init; }

[JsonPropertyName("mods_change")]
public required string ModsChange { get; init; }

[JsonPropertyName("raids_change")]
public required string RaidsChange { get; init; }

[JsonPropertyName("hosts_change")]
public required string HostsChange { get; init; }

[JsonPropertyName("_id")]
public required string MessageId { get; init; }

[JsonPropertyName("priority")]
public required long Priority { get; init; }
}
Loading

0 comments on commit 918a7be

Please sign in to comment.