Moved streamlist logic to the service file
This commit is contained in:
parent
53b7ba640d
commit
cd92577095
2 changed files with 28 additions and 22 deletions
|
@ -69,22 +69,7 @@ public partial class Searches
|
||||||
if (page-- < 1)
|
if (page-- < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var allStreams = new List<FollowedStream>();
|
var allStreams = await _service.GetAllStreamsAsync((SocketGuild)ctx.Guild);
|
||||||
await using (var uow = _db.GetDbContext())
|
|
||||||
{
|
|
||||||
var all = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams))
|
|
||||||
.FollowedStreams.OrderBy(x => x.Id)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
for (var index = all.Count - 1; index >= 0; index--)
|
|
||||||
{
|
|
||||||
var fs = all[index];
|
|
||||||
if (((SocketGuild)ctx.Guild).GetTextChannel(fs.ChannelId) is null)
|
|
||||||
await _service.UnfollowStreamAsync(fs.GuildId, index);
|
|
||||||
else
|
|
||||||
allStreams.Insert(0, fs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
|
|
|
@ -492,10 +492,10 @@ public sealed class StreamNotificationService : IEService, IReadyExecutor
|
||||||
public EmbedBuilder GetEmbed(ulong guildId, StreamData status, bool showViewers = true)
|
public EmbedBuilder GetEmbed(ulong guildId, StreamData status, bool showViewers = true)
|
||||||
{
|
{
|
||||||
var embed = _sender.CreateEmbed()
|
var embed = _sender.CreateEmbed()
|
||||||
.WithTitle(status.Name)
|
.WithTitle(status.Name)
|
||||||
.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);
|
||||||
|
|
||||||
if (showViewers)
|
if (showViewers)
|
||||||
{
|
{
|
||||||
|
@ -647,4 +647,25 @@ public sealed class StreamNotificationService : IEService, IReadyExecutor
|
||||||
public StreamDataKey Key { get; init; }
|
public StreamDataKey Key { get; init; }
|
||||||
public ulong GuildId { get; init; }
|
public ulong GuildId { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<FollowedStream>> GetAllStreamsAsync(SocketGuild guild)
|
||||||
|
{
|
||||||
|
var allStreams = new List<FollowedStream>();
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
var all = uow.GuildConfigsForId(guild.Id, set => set.Include(gc => gc.FollowedStreams))
|
||||||
|
.FollowedStreams
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
for (var index = all.Count - 1; index >= 0; index--)
|
||||||
|
{
|
||||||
|
var fs = all[index];
|
||||||
|
if (guild.GetTextChannel(fs.ChannelId) is null)
|
||||||
|
await UnfollowStreamAsync(fs.GuildId, index);
|
||||||
|
else
|
||||||
|
allStreams.Insert(0, fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allStreams;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue