You can now follow picarto streams (.picarto/.pa)

This commit is contained in:
Master Kwoth 2017-11-17 18:27:24 +01:00
parent 940600bda6
commit 7a85677d74
6 changed files with 56 additions and 10 deletions

View File

@ -8,7 +8,7 @@ namespace NadekoBot.Modules.Searches.Common
string Title { get; } string Title { get; }
bool Live { get; } bool Live { get; }
string Game { get; } string Game { get; }
int FollowerCount { get; } int Followers { get; }
string Url { get; } string Url { get; }
string Icon { get; } string Icon { get; }
} }
@ -26,7 +26,6 @@ namespace NadekoBot.Modules.Searches.Common
public string Title => ""; public string Title => "";
public bool Live => IsLive == "1"; public bool Live => IsLive == "1";
public string Game => ""; public string Game => "";
public int FollowerCount => Followers;
public string Icon => !string.IsNullOrWhiteSpace(UserLogo) public string Icon => !string.IsNullOrWhiteSpace(UserLogo)
? "https://edge.sf.hitbox.tv" + UserLogo ? "https://edge.sf.hitbox.tv" + UserLogo
: ""; : "";
@ -34,6 +33,25 @@ namespace NadekoBot.Modules.Searches.Common
public string Url { get; set; } 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 class TwitchResponse : IStreamResponse
{ {
public string Error { get; set; } = null; public string Error { get; set; } = null;
@ -58,7 +76,7 @@ namespace NadekoBot.Modules.Searches.Common
public string Title => Stream?.Channel?.Status; public string Title => Stream?.Channel?.Status;
public bool Live => IsLive; public bool Live => IsLive;
public string Game => Stream?.Game; 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 Url { get; set; }
public string Icon => Stream?.Channel?.Logo; public string Icon => Stream?.Channel?.Logo;
} }
@ -89,7 +107,7 @@ namespace NadekoBot.Modules.Searches.Common
public string Title => Name; public string Title => Name;
public bool Live => IsLive; public bool Live => IsLive;
public string Game => Type?.Name ?? ""; public string Game => Type?.Name ?? "";
public int FollowerCount => NumFollowers; public int Followers => NumFollowers;
public string Icon => Thumbnail?.Url; public string Icon => Thumbnail?.Url;
} }
} }

View File

@ -126,6 +126,17 @@ namespace NadekoBot.Modules.Searches.Services
bmData.Url = beamUrl; bmData.Url = beamUrl;
_cachedStatuses.AddOrUpdate(beamUrl, bmData, (key, old) => bmData); _cachedStatuses.AddOrUpdate(beamUrl, bmData, (key, old) => bmData);
return 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: default:
break; break;
} }
@ -155,7 +166,7 @@ namespace NadekoBot.Modules.Searches.Services
true); true);
embed.AddField(GetText(fs, "followers"), embed.AddField(GetText(fs, "followers"),
status.FollowerCount.ToString(), status.Followers.ToString(),
true); true);
if (!string.IsNullOrWhiteSpace(status.Icon)) if (!string.IsNullOrWhiteSpace(status.Icon))
@ -178,6 +189,8 @@ namespace NadekoBot.Modules.Searches.Services
return $"https://www.twitch.tv/{fs.Username}/"; return $"https://www.twitch.tv/{fs.Username}/";
if (fs.Type == FollowedStream.FollowedStreamType.Mixer) if (fs.Type == FollowedStream.FollowedStreamType.Mixer)
return $"https://www.mixer.com/{fs.Username}/"; return $"https://www.mixer.com/{fs.Username}/";
if (fs.Type == FollowedStream.FollowedStreamType.Picarto)
return $"https://www.picarto.tv/{fs.Username}";
return "??"; return "??";
} }
} }

View File

@ -39,6 +39,13 @@ namespace NadekoBot.Modules.Searches
await TrackStream((ITextChannel)Context.Channel, username, FollowedStream.FollowedStreamType.Twitch) await TrackStream((ITextChannel)Context.Channel, username, FollowedStream.FollowedStreamType.Twitch)
.ConfigureAwait(false); .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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]

View File

@ -9,7 +9,8 @@
public enum FollowedStreamType public enum FollowedStreamType
{ {
Twitch, Smashcast, Mixer Twitch, Smashcast, Mixer,
Picarto
} }
public override int GetHashCode() => public override int GetHashCode() =>

View File

@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services.Impl
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
private readonly DateTime _started; 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 Author => "Kwoth#2560";
public string Library => "Discord.Net"; public string Library => "Discord.Net";

View File

@ -1357,21 +1357,28 @@
}, },
"smashcast": { "smashcast": {
"Cmd": "smashcast hb", "Cmd": "smashcast hb",
"Desc": "Notifies this channel when a certain user starts streaming.", "Desc": "Notifies this channel when the specified user starts streaming.",
"Usage": [ "Usage": [
"{0}smashcast SomeStreamer" "{0}smashcast SomeStreamer"
] ]
}, },
"twitch": { "twitch": {
"Cmd": "twitch tw", "Cmd": "twitch tw",
"Desc": "Notifies this channel when a certain user starts streaming.", "Desc": "Notifies this channel when the specified user starts streaming.",
"Usage": [ "Usage": [
"{0}twitch SomeStreamer" "{0}twitch SomeStreamer"
] ]
}, },
"picarto": {
"Cmd": "picarto pa",
"Desc": "Notifies this channel when the specified user starts streaming.",
"Usage": [
"{0}picarto SomeStreamer"
]
},
"mixer": { "mixer": {
"Cmd": "mixer bm", "Cmd": "mixer bm",
"Desc": "Notifies this channel when a certain user starts streaming.", "Desc": "Notifies this channel when the specified user starts streaming.",
"Usage": [ "Usage": [
"{0}mixer SomeStreamer" "{0}mixer SomeStreamer"
] ]