From 7a85677d7496ae0f9d682f906eb4a1c16ebdad73 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 17 Nov 2017 18:27:24 +0100 Subject: [PATCH] You can now follow picarto streams (.picarto/.pa) --- .../Searches/Common/StreamResponses.cs | 26 ++++++++++++++++--- .../Services/StreamNotificationService.cs | 15 ++++++++++- .../Searches/StreamNotificationCommands.cs | 7 +++++ .../Database/Models/FollowedStream.cs | 3 ++- NadekoBot.Core/Services/Impl/StatsService.cs | 2 +- .../_strings/cmd/command_strings.json | 13 +++++++--- 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/NadekoBot.Core/Modules/Searches/Common/StreamResponses.cs b/NadekoBot.Core/Modules/Searches/Common/StreamResponses.cs index 9eb791cb..4823787b 100644 --- a/NadekoBot.Core/Modules/Searches/Common/StreamResponses.cs +++ b/NadekoBot.Core/Modules/Searches/Common/StreamResponses.cs @@ -8,7 +8,7 @@ namespace NadekoBot.Modules.Searches.Common string Title { get; } bool Live { get; } string Game { get; } - int FollowerCount { get; } + int Followers { get; } string Url { get; } string Icon { get; } } @@ -26,7 +26,6 @@ namespace NadekoBot.Modules.Searches.Common public string Title => ""; public bool Live => IsLive == "1"; public string Game => ""; - public int FollowerCount => Followers; public string Icon => !string.IsNullOrWhiteSpace(UserLogo) ? "https://edge.sf.hitbox.tv" + UserLogo : ""; @@ -34,6 +33,25 @@ namespace NadekoBot.Modules.Searches.Common public string Url { get; set; } } + public class PicartoResponse : IStreamResponse + { + public string Name { get; set; } + public int Viewers { get; set; } + + public string Title { get; set; } + + [JsonProperty("online")] + public bool Live { get; set; } + [JsonProperty("category")] + public string Game { get; set; } + + public int Followers { get; set; } + + public string Url => "https://picarto.tv/" + Name; + [JsonProperty("thumbnail")] + public string Icon { get; set; } + } + public class TwitchResponse : IStreamResponse { public string Error { get; set; } = null; @@ -58,7 +76,7 @@ namespace NadekoBot.Modules.Searches.Common public string Title => Stream?.Channel?.Status; public bool Live => IsLive; public string Game => Stream?.Game; - public int FollowerCount => Stream?.Channel?.Followers ?? 0; + public int Followers => Stream?.Channel?.Followers ?? 0; public string Url { get; set; } public string Icon => Stream?.Channel?.Logo; } @@ -89,7 +107,7 @@ namespace NadekoBot.Modules.Searches.Common public string Title => Name; public bool Live => IsLive; public string Game => Type?.Name ?? ""; - public int FollowerCount => NumFollowers; + public int Followers => NumFollowers; public string Icon => Thumbnail?.Url; } } diff --git a/NadekoBot.Core/Modules/Searches/Services/StreamNotificationService.cs b/NadekoBot.Core/Modules/Searches/Services/StreamNotificationService.cs index 2ca9fd58..2e1ab585 100644 --- a/NadekoBot.Core/Modules/Searches/Services/StreamNotificationService.cs +++ b/NadekoBot.Core/Modules/Searches/Services/StreamNotificationService.cs @@ -126,6 +126,17 @@ namespace NadekoBot.Modules.Searches.Services bmData.Url = beamUrl; _cachedStatuses.AddOrUpdate(beamUrl, bmData, (key, old) => bmData); return bmData; + case FollowedStream.FollowedStreamType.Picarto: + var picartoUrl = $"https://api.picarto.tv/v1/channel/name/{stream.Username.ToLowerInvariant()}"; + if (checkCache && _cachedStatuses.TryGetValue(picartoUrl, out result)) + return result; + + var paResponse = await _http.GetAsync(picartoUrl).ConfigureAwait(false); + if(!paResponse.IsSuccessStatusCode) + throw new StreamNotFoundException($"{stream.Username} [{stream.Type}]"); + var paData = JsonConvert.DeserializeObject(await paResponse.Content.ReadAsStringAsync()); + _cachedStatuses.AddOrUpdate(picartoUrl, paData, (key, old) => paData); + return paData; default: break; } @@ -155,7 +166,7 @@ namespace NadekoBot.Modules.Searches.Services true); embed.AddField(GetText(fs, "followers"), - status.FollowerCount.ToString(), + status.Followers.ToString(), true); if (!string.IsNullOrWhiteSpace(status.Icon)) @@ -178,6 +189,8 @@ namespace NadekoBot.Modules.Searches.Services return $"https://www.twitch.tv/{fs.Username}/"; if (fs.Type == FollowedStream.FollowedStreamType.Mixer) return $"https://www.mixer.com/{fs.Username}/"; + if (fs.Type == FollowedStream.FollowedStreamType.Picarto) + return $"https://www.picarto.tv/{fs.Username}"; return "??"; } } diff --git a/NadekoBot.Core/Modules/Searches/StreamNotificationCommands.cs b/NadekoBot.Core/Modules/Searches/StreamNotificationCommands.cs index 8b565704..9aa47842 100644 --- a/NadekoBot.Core/Modules/Searches/StreamNotificationCommands.cs +++ b/NadekoBot.Core/Modules/Searches/StreamNotificationCommands.cs @@ -39,6 +39,13 @@ namespace NadekoBot.Modules.Searches await TrackStream((ITextChannel)Context.Channel, username, FollowedStream.FollowedStreamType.Twitch) .ConfigureAwait(false); + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequireUserPermission(GuildPermission.ManageMessages)] + public async Task Picarto([Remainder] string username) => + await TrackStream((ITextChannel)Context.Channel, username, FollowedStream.FollowedStreamType.Picarto) + .ConfigureAwait(false); + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageMessages)] diff --git a/NadekoBot.Core/Services/Database/Models/FollowedStream.cs b/NadekoBot.Core/Services/Database/Models/FollowedStream.cs index 57273418..46e064db 100644 --- a/NadekoBot.Core/Services/Database/Models/FollowedStream.cs +++ b/NadekoBot.Core/Services/Database/Models/FollowedStream.cs @@ -9,7 +9,8 @@ public enum FollowedStreamType { - Twitch, Smashcast, Mixer + Twitch, Smashcast, Mixer, + Picarto } public override int GetHashCode() => diff --git a/NadekoBot.Core/Services/Impl/StatsService.cs b/NadekoBot.Core/Services/Impl/StatsService.cs index 4ca20e95..64c0ac9b 100644 --- a/NadekoBot.Core/Services/Impl/StatsService.cs +++ b/NadekoBot.Core/Services/Impl/StatsService.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services.Impl private readonly IBotCredentials _creds; private readonly DateTime _started; - public const string BotVersion = "2.5.3"; + public const string BotVersion = "2.5.4"; public string Author => "Kwoth#2560"; public string Library => "Discord.Net"; diff --git a/src/NadekoBot/_strings/cmd/command_strings.json b/src/NadekoBot/_strings/cmd/command_strings.json index 34eb5eb9..5cdb1b94 100644 --- a/src/NadekoBot/_strings/cmd/command_strings.json +++ b/src/NadekoBot/_strings/cmd/command_strings.json @@ -1357,21 +1357,28 @@ }, "smashcast": { "Cmd": "smashcast hb", - "Desc": "Notifies this channel when a certain user starts streaming.", + "Desc": "Notifies this channel when the specified user starts streaming.", "Usage": [ "{0}smashcast SomeStreamer" ] }, "twitch": { "Cmd": "twitch tw", - "Desc": "Notifies this channel when a certain user starts streaming.", + "Desc": "Notifies this channel when the specified user starts streaming.", "Usage": [ "{0}twitch SomeStreamer" ] }, + "picarto": { + "Cmd": "picarto pa", + "Desc": "Notifies this channel when the specified user starts streaming.", + "Usage": [ + "{0}picarto SomeStreamer" + ] + }, "mixer": { "Cmd": "mixer bm", - "Desc": "Notifies this channel when a certain user starts streaming.", + "Desc": "Notifies this channel when the specified user starts streaming.", "Usage": [ "{0}mixer SomeStreamer" ]