diff --git a/KfChatDotNetBot/Services/Twitch.cs b/KfChatDotNetBot/Services/Twitch.cs index 47956f5..fd6c4e2 100644 --- a/KfChatDotNetBot/Services/Twitch.cs +++ b/KfChatDotNetBot/Services/Twitch.cs @@ -17,7 +17,9 @@ public class Twitch : IDisposable private string? _proxy; private List _channels; public delegate void OnStreamStateUpdateEventHandler(object sender, int channelId, bool isLive); + public delegate void OnStreamCommercialEventHandler(object sender, int channelId, int length, bool scheduled); public event OnStreamStateUpdateEventHandler OnStreamStateUpdated; + public event OnStreamCommercialEventHandler OnStreamCommercial; private CancellationToken _cancellationToken = CancellationToken.None; private Task? _pingTask = null; private CancellationTokenSource _pingCts = new(); @@ -161,6 +163,14 @@ public class Twitch : IDisposable db.SaveChanges(); return; } + + if (twitchMessage.GetProperty("type").GetString() == "commercial") + { + _logger.Info("Twitch commercial received"); + OnStreamCommercial?.Invoke(this, channelId, twitchMessage.GetProperty("length").GetInt32(), + twitchMessage.GetProperty("scheduled").GetBoolean()); + return; + } _logger.Info("Message from Twitch was unhandled"); _logger.Info(message.Text); }