From 6f7470c0b3e811a2051fc36aa77af87e7053ac08 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sat, 7 Sep 2024 17:02:13 +0800 Subject: [PATCH] Added an event for Twitch commercials --- KfChatDotNetBot/Services/Twitch.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); }