mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Stream notification support for trovo.live finalized
This commit is contained in:
@@ -440,7 +440,11 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
|
|||||||
.WithUrl(status.StreamUrl)
|
.WithUrl(status.StreamUrl)
|
||||||
.WithDescription(status.StreamUrl)
|
.WithDescription(status.StreamUrl)
|
||||||
.AddField(GetText(guildId, strs.status), status.IsLive ? "🟢 Online" : "🔴 Offline", true)
|
.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)
|
if (status.IsLive)
|
||||||
embed = embed.WithOkColor();
|
embed = embed.WithOkColor();
|
||||||
|
@@ -5,6 +5,6 @@ namespace NadekoBot.Modules.Searches.Common.StreamNotifications.Providers;
|
|||||||
|
|
||||||
public class TrovoRequestData
|
public class TrovoRequestData
|
||||||
{
|
{
|
||||||
[JsonPropertyName("channel_id")]
|
[JsonPropertyName("username")]
|
||||||
public string ChannelId { get; set; }
|
public string Username { get; set; }
|
||||||
}
|
}
|
@@ -38,7 +38,10 @@ public class TrovoProvider : Provider
|
|||||||
var trovoClientId = _creds.GetCreds().TrovoClientId;
|
var trovoClientId = _creds.GetCreds().TrovoClientId;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(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();
|
http.DefaultRequestHeaders.Clear();
|
||||||
@@ -53,7 +56,7 @@ public class TrovoProvider : Provider
|
|||||||
$"https://open-api.trovo.live/openplatform/channels/id",
|
$"https://open-api.trovo.live/openplatform/channels/id",
|
||||||
new TrovoRequestData()
|
new TrovoRequestData()
|
||||||
{
|
{
|
||||||
ChannelId = login
|
Username = login
|
||||||
});
|
});
|
||||||
|
|
||||||
res.EnsureSuccessStatusCode();
|
res.EnsureSuccessStatusCode();
|
||||||
@@ -67,6 +70,7 @@ public class TrovoProvider : Provider
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_failingStreams.TryRemove(data.Username, out _);
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
IsLive = data.IsLive,
|
IsLive = data.IsLive,
|
||||||
@@ -91,6 +95,14 @@ public class TrovoProvider : Provider
|
|||||||
|
|
||||||
public override async Task<IReadOnlyCollection<StreamData>> GetStreamDataAsync(List<string> usernames)
|
public override async Task<IReadOnlyCollection<StreamData>> GetStreamDataAsync(List<string> 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<StreamData>();
|
||||||
|
}
|
||||||
|
|
||||||
var results = new List<StreamData>(usernames.Count);
|
var results = new List<StreamData>(usernames.Count);
|
||||||
foreach (var chunk in usernames.Chunk(10)
|
foreach (var chunk in usernames.Chunk(10)
|
||||||
.Select(x => x.Select(GetStreamDataAsync)))
|
.Select(x => x.Select(GetStreamDataAsync)))
|
||||||
|
Reference in New Issue
Block a user