From 8c1c75c24615272108e8b9c39d43fa24cf3c7f9b Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 16 Feb 2022 01:47:29 +0100 Subject: [PATCH] Stream notification support for trovo.live finalized --- .../StreamNotificationService.cs | 6 +++++- .../Models/TrovoRequestData.cs | 4 ++-- .../Providers/TrovoProvider.cs | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs index 9607c42e9..c42e0c8a0 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs @@ -440,7 +440,11 @@ public sealed class StreamNotificationService : INService, IReadyExecutor .WithUrl(status.StreamUrl) .WithDescription(status.StreamUrl) .AddField(GetText(guildId, strs.status), status.IsLive ? "🟢 Online" : "🔴 Offline", true) - .AddField(GetText(guildId, strs.viewers), status.IsLive ? status.Viewers.ToString() : "-", true); + .AddField(GetText(guildId, strs.viewers), + status.Viewers == 0 && !status.IsLive + ? "-" + : status.Viewers, + true); if (status.IsLive) embed = embed.WithOkColor(); diff --git a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TrovoRequestData.cs b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TrovoRequestData.cs index def9b2d11..25dc136c2 100644 --- a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TrovoRequestData.cs +++ b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Models/TrovoRequestData.cs @@ -5,6 +5,6 @@ namespace NadekoBot.Modules.Searches.Common.StreamNotifications.Providers; public class TrovoRequestData { - [JsonPropertyName("channel_id")] - public string ChannelId { get; set; } + [JsonPropertyName("username")] + public string Username { get; set; } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TrovoProvider.cs b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TrovoProvider.cs index cf26f06f4..b8f2e49ee 100644 --- a/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TrovoProvider.cs +++ b/src/NadekoBot/Modules/Searches/_Common/StreamNotifications/Providers/TrovoProvider.cs @@ -38,7 +38,10 @@ public class TrovoProvider : Provider var trovoClientId = _creds.GetCreds().TrovoClientId; if (string.IsNullOrWhiteSpace(trovoClientId)) - trovoClientId = "waiting for key"; + { + Log.Warning("Trovo streams will be ignored until TrovoClientId is added to creds.yml"); + return default; + } http.DefaultRequestHeaders.Clear(); @@ -53,7 +56,7 @@ public class TrovoProvider : Provider $"https://open-api.trovo.live/openplatform/channels/id", new TrovoRequestData() { - ChannelId = login + Username = login }); res.EnsureSuccessStatusCode(); @@ -67,6 +70,7 @@ public class TrovoProvider : Provider return null; } + _failingStreams.TryRemove(data.Username, out _); return new() { IsLive = data.IsLive, @@ -91,6 +95,14 @@ public class TrovoProvider : Provider public override async Task> GetStreamDataAsync(List usernames) { + var trovoClientId = _creds.GetCreds().TrovoClientId; + + if (string.IsNullOrWhiteSpace(trovoClientId)) + { + Log.Warning("Trovo streams will be ignored until TrovoClientId is added to creds.yml"); + return Array.Empty(); + } + var results = new List(usernames.Count); foreach (var chunk in usernames.Chunk(10) .Select(x => x.Select(GetStreamDataAsync)))