You can now follow picarto streams (.picarto/.pa)
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<PicartoResponse>(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 "??";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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)]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user