diff --git a/Config.cs b/Config.cs index b771a98..eaf3c6d 100644 --- a/Config.cs +++ b/Config.cs @@ -583,7 +583,8 @@ private static void CreateConfigFile(FileInfo file, bool example = false) writer.WriteLine(string.Concat(Keys.OverpoweredInFight.ToString(), " = Abev08")); writer.WriteLine("; Song request timeout from the same user (HH:MM:SS format -> 1 hour: 1:00:00, 1 minute 0:01:00, 1 second: 0:00:01). Default: empty - 2 minutes"); writer.WriteLine(string.Concat(Keys.SongRequestTimeout.ToString(), " = ")); - writer.WriteLine("; Discord message that will be sent when the stream goes online. Default: empty - \"Hello @everyone, stream just started https://twitch.tv/{ChannelName} !\""); + writer.WriteLine("; Discord message that will be sent when the stream goes online. Default: empty - \"Hello @everyone, stream just started https://twitch.tv/{ChannelName} ! {title}\""); + writer.WriteLine("; The \"{title}\" part of the message will be replaced with current stream title and can be used in custom online message specified below."); writer.WriteLine(string.Concat(Keys.DiscordMessageOnline.ToString(), " = ")); writer.WriteLine(); @@ -797,6 +798,11 @@ public static bool GetBroadcasterStatus() request.Headers.Add("Client-Id", Secret.Data[Secret.Keys.CustomerID]); string resp = Notifications.Client.Send(request).Content.ReadAsStringAsync().Result; + if (resp is null || resp.Length == 0 || resp.StartsWith('<')) + { + MainWindow.ConsoleWarning(">> Couldn't acquire stream status."); + return false; + } var response = StatusResponse.Deserialize(resp); if (response is null || response.Data is null || response.Data.Length == 0) { @@ -807,7 +813,11 @@ public static bool GetBroadcasterStatus() { foreach (var data in response.Data) { - if (data.ID.Equals(Config.Data[Config.Keys.ChannelID])) return data.IsLive == true; + if (data.ID.Equals(Config.Data[Config.Keys.ChannelID])) + { + Discrod.LastStreamTitle = data.Title; + return data.IsLive == true; + } } } diff --git a/Discrod.cs b/Discrod.cs index cb66756..640937e 100644 --- a/Discrod.cs +++ b/Discrod.cs @@ -8,6 +8,7 @@ public static class Discrod /// Is connection to Discord API working? public static bool Working { get; set; } public static string CustomOnlineMessage { get; set; } + public static string LastStreamTitle { get; set; } public static void SendOnlineMessage() { @@ -18,7 +19,8 @@ public static void SendOnlineMessage() string message; if (CustomOnlineMessage?.Length > 0) message = CustomOnlineMessage; - else message = $"Hello @everyone, stream just started https://twitch.tv/{Config.Data[Config.Keys.ChannelName]} !"; + else message = $"Hello @everyone, stream just started https://twitch.tv/{Config.Data[Config.Keys.ChannelName]} ! {{title}}"; + message = message.Replace("{title}", LastStreamTitle).Trim(); using HttpRequestMessage request = new(HttpMethod.Post, $"https://discord.com/api/v10/channels/{Secret.Data[Secret.Keys.DiscordChannelID]}/messages"); request.Content = new StringContent(