dev: Started cleanup of quote commands. Moving logic to the service

This commit is contained in:
Kwoth
2024-08-18 23:52:32 +00:00
parent 0b9e812d59
commit 9aaf062d78
3 changed files with 50 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
#nullable disable
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Db.Models;
@@ -9,21 +10,6 @@ public static class QuoteExtensions
public static IEnumerable<Quote> GetForGuild(this DbSet<Quote> quotes, ulong guildId)
=> quotes.AsQueryable().Where(x => x.GuildId == guildId);
public static IReadOnlyCollection<Quote> GetGroup(
this DbSet<Quote> quotes,
ulong guildId,
int page,
OrderType order)
{
var q = quotes.AsQueryable().Where(x => x.GuildId == guildId);
if (order == OrderType.Keyword)
q = q.OrderBy(x => x.Keyword);
else
q = q.OrderBy(x => x.Id);
return q.Skip(15 * page).Take(15).ToArray();
}
public static async Task<Quote> GetRandomQuoteByKeywordAsync(
this DbSet<Quote> quotes,
ulong guildId,
@@ -45,7 +31,7 @@ public static class QuoteExtensions
&& (EF.Functions.Like(q.Text.ToUpper(), $"%{text.ToUpper()}%")
|| EF.Functions.Like(q.AuthorName, text)))
.ToArrayAsync())
.RandomOrDefault();
.RandomOrDefault();
}
public static void RemoveAllByKeyword(this DbSet<Quote> quotes, ulong guildId, string keyword)