Added stream notifications hopefuly?

This commit is contained in:
Kwoth 2016-09-01 02:17:48 +02:00
parent 1557ba2e81
commit 9a957b95e3
5 changed files with 304 additions and 331 deletions

View File

@ -1,348 +1,288 @@
//using Discord.Commands; using Discord.Commands;
//using NadekoBot.Classes; using Newtonsoft.Json.Linq;
//using Newtonsoft.Json.Linq; using System;
//using System; using System.Collections.Concurrent;
//using System.Collections.Concurrent; using System.Linq;
//using System.Linq; using System.Threading.Tasks;
//using System.Threading.Tasks; using Discord;
//using Discord; using NadekoBot.Services;
//using NadekoBot.Services; using System.Threading;
//using System.Threading; using NadekoBot.Services.Database;
using System.Collections.Generic;
using NadekoBot.Services.Database.Models;
using System.Net.Http;
using Discord.WebSocket;
using NadekoBot.Attributes;
//todo DB namespace NadekoBot.Modules.Searches
//namespace NadekoBot.Modules.Searches {
//{ public partial class Searches
// public partial class Searches {
// { [Group]
// [Group] public class StreamNotificationCommands
// public class StreamNotificationCommands {
// { private Timer checkTimer { get; }
// private readonly Timer checkTimer; private ConcurrentDictionary<string, Tuple<bool, string>> cachedStatuses = new ConcurrentDictionary<string, Tuple<bool, string>>();
// private ConcurrentDictionary<string, Tuple<bool, string>> cachedStatuses = new ConcurrentDictionary<string, Tuple<bool, string>>(); private bool FirstPass { get; set; } = true;
// private bool FirstPass { get; set; } = true;
// public StreamNotifications(DiscordModule module) public StreamNotificationCommands()
// { {
// checkTimer = new Timer(async (state) => checkTimer = new Timer(async (state) =>
// { {
// cachedStatuses.Clear(); cachedStatuses.Clear();
// try try
// { {
// var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams); IEnumerable<FollowedStream> streams;
// if (!streams.Any()) return; using (var uow = DbHandler.UnitOfWork())
// foreach (var stream in streams) {
// { streams = uow.GuildConfigs.GetAllFollowedStreams();
// Tuple<bool, string> data; }
// try foreach (var stream in streams)
// { {
// data = await GetStreamStatus(stream).ConfigureAwait(false); Tuple<bool, string> data;
// } try
// catch {
// { data = await GetStreamStatus(stream).ConfigureAwait(false);
// continue; }
// } catch
{
continue;
}
// if (data.Item1 != stream.LastStatus) if (data.Item1 != stream.LastStatus)
// { {
// stream.LastStatus = data.Item1; stream.LastStatus = data.Item1;
// if (FirstPass) if (FirstPass)
// continue; continue;
// var server = NadekoBot.Client.GetServer(stream.ServerId); var server = NadekoBot.Client.GetGuild(stream.GuildId);
// var channel = server?.GetChannel(stream.ChannelId); var channel = server?.GetTextChannel(stream.ChannelId);
// if (channel == null) if (channel == null)
// continue; continue;
// var msg = $"`{stream.Username}`'s stream is now " + var msg = $"`{stream.Username}`'s stream is now " +
// $"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " + $"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " +
// $"**{data.Item2}** viewers."; $"**{data.Item2}** viewers.";
// if (stream.LastStatus) if (stream.LastStatus)
// if (stream.Type == StreamNotificationConfig.StreamType.Hitbox) if (stream.Type == FollowedStream.FollowedStreamType.Hitbox)
// msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】"; msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
// else if (stream.Type == StreamNotificationConfig.StreamType.Twitch) else if (stream.Type == FollowedStream.FollowedStreamType.Twitch)
// msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】"; msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
// else if (stream.Type == StreamNotificationConfig.StreamType.Beam) else if (stream.Type == FollowedStream.FollowedStreamType.Beam)
// msg += $"\n`Here is the Link:`【 http://www.beam.pro/{stream.Username}/ 】"; msg += $"\n`Here is the Link:`【 http://www.beam.pro/{stream.Username}/ 】";
// else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming) //else if (stream.Type == FollowedStream.FollowedStreamType.YoutubeGaming)
// msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】"; // msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】";
// await channel.SendMessageAsync(msg).ConfigureAwait(false); await channel.SendMessageAsync(msg).ConfigureAwait(false);
// } }
// } }
// FirstPass = false; FirstPass = false;
// } }
// catch { } catch { }
// }, null, TimeSpan.Zero, TimeSpan.FromSeconds(15)); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
// } }
// public StreamNotifications(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) private async Task<Tuple<bool, string>> GetStreamStatus(FollowedStream stream, bool checkCache = true)
// { {
// } bool isLive;
string response;
JObject data;
Tuple<bool, string> result;
switch (stream.Type)
{
case FollowedStream.FollowedStreamType.Hitbox:
var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username}";
if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result))
return result;
using (var http = new HttpClient())
{
response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false);
}
data = JObject.Parse(response);
isLive = data["media_is_live"].ToString() == "1";
result = new Tuple<bool, string>(isLive, data["media_views"].ToString());
cachedStatuses.TryAdd(hitboxUrl, result);
return result;
case FollowedStream.FollowedStreamType.Twitch:
var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}";
if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result))
return result;
using (var http = new HttpClient())
{
response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false);
}
data = JObject.Parse(response);
isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString());
result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : "0");
cachedStatuses.TryAdd(twitchUrl, result);
return result;
case FollowedStream.FollowedStreamType.Beam:
var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username}";
if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result))
return result;
using (var http = new HttpClient())
{
response = await http.GetStringAsync(beamUrl).ConfigureAwait(false);
}
data = JObject.Parse(response);
isLive = data["online"].ToObject<bool>() == true;
result = new Tuple<bool, string>(isLive, data["viewersCurrent"].ToString());
cachedStatuses.TryAdd(beamUrl, result);
return result;
default:
break;
}
return new Tuple<bool, string>(false, "0");
}
// private async Task<Tuple<bool, string>> GetStreamStatus(StreamNotificationConfig stream, bool checkCache = true) [LocalizedCommand, LocalizedDescription, LocalizedSummary]
// { [RequireContext(ContextType.Guild)]
// bool isLive; [RequirePermission(GuildPermission.ManageMessages)]
// string response; public async Task Hitbox(IUserMessage msg, [Remainder] string username) =>
// JObject data; await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Hitbox)
// Tuple<bool, string> result; .ConfigureAwait(false);
// switch (stream.Type)
// {
// case StreamNotificationConfig.StreamType.Hitbox:
// var hitboxUrl = $"https://api.hitbox.tv/media/status/{stream.Username}";
// if (checkCache && cachedStatuses.TryGetValue(hitboxUrl, out result))
// return result;
// response = await http.GetStringAsync(hitboxUrl).ConfigureAwait(false);
// data = JObject.Parse(response);
// isLive = data["media_is_live"].ToString() == "1";
// result = new Tuple<bool, string>(isLive, data["media_views"].ToString());
// cachedStatuses.TryAdd(hitboxUrl, result);
// return result;
// case StreamNotificationConfig.StreamType.Twitch:
// var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}";
// if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result))
// return result;
// response = await http.GetStringAsync(twitchUrl).ConfigureAwait(false);
// data = JObject.Parse(response);
// isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString());
// result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : "0");
// cachedStatuses.TryAdd(twitchUrl, result);
// return result;
// case StreamNotificationConfig.StreamType.Beam:
// var beamUrl = $"https://beam.pro/api/v1/channels/{stream.Username}";
// if (checkCache && cachedStatuses.TryGetValue(beamUrl, out result))
// return result;
// response = await http.GetStringAsync(beamUrl).ConfigureAwait(false);
// data = JObject.Parse(response);
// isLive = data["online"].ToObject<bool>() == true;
// result = new Tuple<bool, string>(isLive, data["viewersCurrent"].ToString());
// cachedStatuses.TryAdd(beamUrl, result);
// return result;
// default:
// break;
// }
// return new Tuple<bool, string>(false, "0");
// }
// internal override void Init(CommandGroupBuilder cgb) [LocalizedCommand, LocalizedDescription, LocalizedSummary]
// { [RequireContext(ContextType.Guild)]
// cgb.CreateCommand(Module.Prefix + "hitbox") [RequirePermission(GuildPermission.ManageMessages)]
// .Alias(Module.Prefix + "hb") public async Task Twitch(IUserMessage msg, [Remainder] string username) =>
// .Description("Notifies this channel when a certain user starts streaming." + await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Twitch)
// $" | `{Prefix}hitbox SomeStreamer`") .ConfigureAwait(false);
// .Parameter("username", ParameterType.Unparsed)
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(TrackStream(StreamNotificationConfig.StreamType.Hitbox));
// cgb.CreateCommand(Module.Prefix + "twitch") [LocalizedCommand, LocalizedDescription, LocalizedSummary]
// .Alias(Module.Prefix + "tw") [RequireContext(ContextType.Guild)]
// .Description("Notifies this channel when a certain user starts streaming." + [RequirePermission(GuildPermission.ManageMessages)]
// $" | `{Prefix}twitch SomeStreamer`") public async Task Beam(IUserMessage msg, [Remainder] string username) =>
// .AddCheck(SimpleCheckers.ManageServer()) await TrackStream((ITextChannel)msg.Channel, username, FollowedStream.FollowedStreamType.Beam)
// .Parameter("username", ParameterType.Unparsed) .ConfigureAwait(false);
// .Do(TrackStream(StreamNotificationConfig.StreamType.Twitch));
// cgb.CreateCommand(Module.Prefix + "beam") [LocalizedCommand, LocalizedDescription, LocalizedSummary]
// .Alias(Module.Prefix + "bm") [RequireContext(ContextType.Guild)]
// .Description("Notifies this channel when a certain user starts streaming." + public async Task ListStreams(IUserMessage imsg)
// $" | `{Prefix}beam SomeStreamer`") {
// .AddCheck(SimpleCheckers.ManageServer()) var channel = (ITextChannel)imsg.Channel;
// .Parameter("username", ParameterType.Unparsed)
// .Do(TrackStream(StreamNotificationConfig.StreamType.Beam));
// cgb.CreateCommand(Module.Prefix + "checkhitbox") IEnumerable<FollowedStream> streams;
// .Alias(Module.Prefix + "chhb") using (var uow = DbHandler.UnitOfWork())
// .Description("Checks if a certain user is streaming on the hitbox platform." + {
// $" | `{Prefix}chhb SomeStreamer`") streams = uow.GuildConfigs.For(channel.Guild.Id).FollowedStreams;
// .Parameter("username", ParameterType.Unparsed) }
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(async e =>
// {
// var stream = username?.Trim();
// if (string.IsNullOrWhiteSpace(stream))
// return;
// try
// {
// var streamStatus = (await GetStreamStatus(new StreamNotificationConfig
// {
// Username = stream,
// Type = StreamNotificationConfig.StreamType.Hitbox
// }));
// if (streamStatus.Item1)
// {
// await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
// }
// }
// catch
// {
// await channel.SendMessageAsync("No channel found.");
// }
// });
// cgb.CreateCommand(Module.Prefix + "checktwitch") if (!streams.Any())
// .Alias(Module.Prefix + "chtw") {
// .Description("Checks if a certain user is streaming on the twitch platform." + await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false);
// $" | `{Prefix}chtw SomeStreamer`") return;
// .AddCheck(SimpleCheckers.ManageServer()) }
// .Parameter("username", ParameterType.Unparsed)
// .Do(async e =>
// {
// var stream = username?.Trim();
// if (string.IsNullOrWhiteSpace(stream))
// return;
// try
// {
// var streamStatus = (await GetStreamStatus(new StreamNotificationConfig
// {
// Username = stream,
// Type = StreamNotificationConfig.StreamType.Twitch
// }));
// if (streamStatus.Item1)
// {
// await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
// }
// }
// catch
// {
// await channel.SendMessageAsync("No channel found.");
// }
// });
// cgb.CreateCommand(Module.Prefix + "checkbeam") var text = string.Join("\n", streams.Select(snc =>
// .Alias(Module.Prefix + "chbm") {
// .Description("Checks if a certain user is streaming on the beam platform." + return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】";
// $" | `{Prefix}chbm SomeStreamer`") }));
// .AddCheck(SimpleCheckers.ManageServer())
// .Parameter("username", ParameterType.Unparsed)
// .Do(async e =>
// {
// var stream = username?.Trim();
// if (string.IsNullOrWhiteSpace(stream))
// return;
// try
// {
// var streamStatus = (await GetStreamStatus(new StreamNotificationConfig
// {
// Username = stream,
// Type = StreamNotificationConfig.StreamType.Beam
// }));
// if (streamStatus.Item1)
// {
// await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
// }
// }
// catch
// {
// await channel.SendMessageAsync("No channel found.");
// }
// });
// cgb.CreateCommand(Module.Prefix + "removestream") await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false);
// .Alias(Module.Prefix + "rms") }
// .Description("Removes notifications of a certain streamer on this channel." +
// $" | `{Prefix}rms SomeGuy`")
// .AddCheck(SimpleCheckers.ManageServer())
// .Parameter("username", ParameterType.Unparsed)
// .Do(async e =>
// {
// var username = username?.ToLower().Trim();
// if (string.IsNullOrWhiteSpace(username))
// return;
// var config = SpecificConfigurations.Default.Of(e.Server.Id); [LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task RemoveStream(IUserMessage msg, [Remainder] string username)
{
var channel = (ITextChannel)msg.Channel;
// var toRemove = config.ObservingStreams username = username.ToUpperInvariant().Trim();
// .FirstOrDefault(snc => snc.ChannelId == e.Channel.Id &&
// snc.Username.ToLower().Trim() == username);
// if (toRemove == null)
// {
// await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false);
// return;
// }
// config.ObservingStreams.Remove(toRemove); FollowedStream toRemove;
// await ConfigHandler.SaveConfig().ConfigureAwait(false); using (var uow = DbHandler.UnitOfWork())
// await channel.SendMessageAsync($":ok: Removed `{toRemovumsg.Authorname}`'s stream from notifications.").ConfigureAwait(false); {
// }); var config = uow.GuildConfigs.For(channel.Guild.Id);
var streams = config.FollowedStreams;
toRemove = streams.Where(fs => fs.ChannelId == channel.Id && fs.Username.ToUpperInvariant() == username).FirstOrDefault();
if (toRemove != null)
{
config.FollowedStreams = streams.Except(new[] { toRemove }).ToList();
await uow.CompleteAsync();
}
}
if (toRemove == null)
{
await channel.SendMessageAsync(":anger: No such stream.").ConfigureAwait(false);
return;
}
await channel.SendMessageAsync($":ok: Removed `{toRemove.Username}`'s stream ({toRemove.Type}) from notifications.").ConfigureAwait(false);
}
// cgb.CreateCommand(Module.Prefix + "liststreams") [LocalizedCommand, LocalizedDescription, LocalizedSummary]
// .Alias(Module.Prefix + "ls") [RequireContext(ContextType.Guild)]
// .Description("Lists all streams you are following on this server." + public async Task CheckStream(IUserMessage imsg, FollowedStream.FollowedStreamType platform, [Remainder] string username)
// $" | `{Prefix}ls`") {
// .Do(async e => var channel = (ITextChannel)imsg.Channel;
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id); var stream = username?.Trim();
if (string.IsNullOrWhiteSpace(stream))
return;
try
{
var streamStatus = (await GetStreamStatus(new FollowedStream
{
Username = stream,
Type = platform
}));
if (streamStatus.Item1)
{
await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
}
}
catch
{
await channel.SendMessageAsync("No channel found.");
}
}
// var streams = config.ObservingStreams.Where(snc => private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type)
// snc.ServerId == e.Server.Id); {
username = username.ToUpperInvariant().Trim();
// var streamsArray = streams as StreamNotificationConfig[] ?? streams.ToArray(); var stream = new FollowedStream
{
// if (streamsArray.Length == 0) GuildId = channel.Guild.Id,
// { ChannelId = channel.Id,
// await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false); Username = username,
// return; Type = type,
// } };
bool exists;
// var text = string.Join("\n", streamsArray.Select(snc => using (var uow = DbHandler.UnitOfWork())
// { {
// try exists = uow.GuildConfigs.For(channel.Guild.Id).FollowedStreams.Where(fs => fs.ChannelId == channel.Id && fs.Username.ToUpperInvariant().Trim() == username).Any();
// { }
// return $"`{snc.Username}`'s stream on **{e.Server.GetChannel(e.Channel.Id).Name}** channel. 【`{snc.Type.ToString()}`】"; if (exists)
// } {
// catch { } await channel.SendMessageAsync($":anger: I am already following `{username}` ({type}) stream on this channel.").ConfigureAwait(false);
// return ""; return;
// })); }
Tuple<bool, string> data;
// await channel.SendMessageAsync($"You are following **{streamsArray.Length}** streams on this server.\n\n" + text).ConfigureAwait(false); try
// }); {
// } data = await GetStreamStatus(stream).ConfigureAwait(false);
}
// private Func<CommandEventArgs, Task> TrackStream(StreamNotificationConfig.StreamType type) => catch
// async e => {
// { await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false);
// var username = username?.ToLowerInvariant(); return;
// if (string.IsNullOrWhiteSpace(username)) }
// return; var msg = $"Stream is currently **{(data.Item1 ? "ONLINE" : "OFFLINE")}** with **{data.Item2}** viewers";
if (data.Item1)
// var config = SpecificConfigurations.Default.Of(e.Server.Id); if (type == FollowedStream.FollowedStreamType.Hitbox)
msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
// var stream = new StreamNotificationConfig else if (type == FollowedStream.FollowedStreamType.Twitch)
// { msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
// ServerId = e.Server.Id, else if (type == FollowedStream.FollowedStreamType.Beam)
// ChannelId = e.Channel.Id, msg += $"\n`Here is the Link:`【 https://beam.pro/{stream.Username}/ 】";
// Username = username, //else if (type == FollowedStream.FollowedStreamType.YoutubeGaming)
// Type = type, // msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}";
// }; stream.LastStatus = data.Item1;
// var exists = config.ObservingStreams.Contains(stream); using (var uow = DbHandler.UnitOfWork())
// if (exists) {
// { uow.GuildConfigs.For(channel.Guild.Id).FollowedStreams.Add(stream);
// await channel.SendMessageAsync(":anger: I am already notifying that stream on this channel.").ConfigureAwait(false); await uow.CompleteAsync();
// return; }
// } msg = $":ok: I will notify this channel when status changes.\n{msg}";
// Tuple<bool, string> data; await channel.SendMessageAsync(msg).ConfigureAwait(false);
// try }
// { }
// data = await GetStreamStatus(stream).ConfigureAwait(false); }
// } }
// catch
// {
// await channel.SendMessageAsync(":anger: Stream probably doesn't exist.").ConfigureAwait(false);
// return;
// }
// var msg = $"Stream is currently **{(data.Item1 ? "ONLINE" : "OFFLINE")}** with **{data.Item2}** viewers";
// if (data.Item1)
// if (type == StreamNotificationConfig.StreamType.Hitbox)
// msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】";
// else if (type == StreamNotificationConfig.StreamType.Twitch)
// msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】";
// else if (type == StreamNotificationConfig.StreamType.Beam)
// msg += $"\n`Here is the Link:`【 https://beam.pro/{stream.Username}/ 】";
// else if (type == StreamNotificationConfig.StreamType.YoutubeGaming)
// msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}";
// stream.LastStatus = data.Item1;
// if (!exists)
// msg = $":ok: I will notify this channel when status changes.\n{msg}";
// await channel.SendMessageAsync(msg).ConfigureAwait(false);
// config.ObservingStreams.Add(stream);
// };
// }
// }
//}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database.Models
{
public class FollowedStream : DbEntity
{
public ulong ChannelId { get; set; }
public string Username { get; set; }
public FollowedStreamType Type { get; set; }
public bool LastStatus { get; set; }
public ulong GuildId { get; set; }
public enum FollowedStreamType
{
Twitch, Hitbox, Beam
}
}
}

View File

@ -33,5 +33,9 @@ namespace NadekoBot.Services.Database.Models
public bool AutoDeleteSelfAssignedRoleMessages { get; set; } public bool AutoDeleteSelfAssignedRoleMessages { get; set; }
public float DefaultMusicVolume { get; set; } = 1.0f; public float DefaultMusicVolume { get; set; } = 1.0f;
public bool VoicePlusTextEnabled { get; set; } public bool VoicePlusTextEnabled { get; set; }
//stream notifications
public List<FollowedStream> FollowedStreams { get; set; } = new List<FollowedStream>();
} }
} }

View File

@ -11,5 +11,6 @@ namespace NadekoBot.Services.Database.Repositories
public interface IGuildConfigRepository : IRepository<GuildConfig> public interface IGuildConfigRepository : IRepository<GuildConfig>
{ {
GuildConfig For(ulong guildId); GuildConfig For(ulong guildId);
IEnumerable<FollowedStream> GetAllFollowedStreams();
} }
} }

View File

@ -20,7 +20,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
/// <returns></returns> /// <returns></returns>
public GuildConfig For(ulong guildId) public GuildConfig For(ulong guildId)
{ {
var config = _set.FirstOrDefault(c => c.GuildId == guildId); var config = _set.Include(gc=>gc.FollowedStreams)
.FirstOrDefault(c => c.GuildId == guildId);
if (config == null) if (config == null)
{ {
@ -32,5 +33,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl
} }
return config; return config;
} }
public IEnumerable<FollowedStream> GetAllFollowedStreams() =>
_set.Include(gc => gc.FollowedStreams)
.SelectMany(gc => gc.FollowedStreams)
.ToList();
} }
} }