diff --git a/NadekoBot.Core/Modules/Utility/QuoteCommands.cs b/NadekoBot.Core/Modules/Utility/QuoteCommands.cs index 9b5746f8..76dabc9f 100644 --- a/NadekoBot.Core/Modules/Utility/QuoteCommands.cs +++ b/NadekoBot.Core/Modules/Utility/QuoteCommands.cs @@ -26,17 +26,16 @@ namespace NadekoBot.Modules.Utility [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task ListQuotes(int page = 1) + public async Task ListQuotes(int page = 1, OrderType order = OrderType.Keyword) { page -= 1; - if (page < 0) return; IEnumerable quotes; using (var uow = _db.UnitOfWork) { - quotes = uow.Quotes.GetGroup(Context.Guild.Id, page * 16, 16); + quotes = uow.Quotes.GetGroup(Context.Guild.Id, page, order); } if (quotes.Any()) diff --git a/NadekoBot.Core/Services/Database/Models/Quote.cs b/NadekoBot.Core/Services/Database/Models/Quote.cs index 3f04823f..4240e5f7 100644 --- a/NadekoBot.Core/Services/Database/Models/Quote.cs +++ b/NadekoBot.Core/Services/Database/Models/Quote.cs @@ -13,4 +13,11 @@ namespace NadekoBot.Core.Services.Database.Models [Required] public string Text { get; set; } } + + + public enum OrderType + { + Id, + Keyword + } } diff --git a/NadekoBot.Core/Services/Database/Repositories/IQuoteRepository.cs b/NadekoBot.Core/Services/Database/Repositories/IQuoteRepository.cs index 4781ca7f..f80a3d42 100644 --- a/NadekoBot.Core/Services/Database/Repositories/IQuoteRepository.cs +++ b/NadekoBot.Core/Services/Database/Repositories/IQuoteRepository.cs @@ -9,7 +9,7 @@ namespace NadekoBot.Core.Services.Database.Repositories IEnumerable GetAllQuotesByKeyword(ulong guildId, string keyword); Task GetRandomQuoteByKeywordAsync(ulong guildId, string keyword); Task SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text); - IEnumerable GetGroup(ulong guildId, int skip, int take); + IEnumerable GetGroup(ulong guildId, int page, OrderType order); void RemoveAllByKeyword(ulong guildId, string keyword); } } diff --git a/NadekoBot.Core/Services/Database/Repositories/Impl/QuoteRepository.cs b/NadekoBot.Core/Services/Database/Repositories/Impl/QuoteRepository.cs index 132d4192..72630a5e 100644 --- a/NadekoBot.Core/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/NadekoBot.Core/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -18,8 +18,16 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl public IEnumerable GetAllQuotesByKeyword(ulong guildId, string keyword) => _set.Where(q => q.GuildId == guildId && q.Keyword == keyword); - public IEnumerable GetGroup(ulong guildId, int skip, int take) => - _set.Where(q=>q.GuildId == guildId).OrderBy(q => q.Keyword).Skip(skip).Take(take).ToList(); + public IEnumerable GetGroup(ulong guildId, int page, OrderType order) + { + var q = _set.Where(x => x.GuildId == guildId); + if (order == OrderType.Keyword) + q.OrderBy(x => x.Keyword); + else + q.OrderBy(x => x.Id); + + return q.Skip(15 * page).Take(15).ToArray(); + } public Task GetRandomQuoteByKeywordAsync(ulong guildId, string keyword) { diff --git a/src/NadekoBot/_strings/cmd/command_strings.json b/src/NadekoBot/_strings/cmd/command_strings.json index 96b04854..250db1ee 100644 --- a/src/NadekoBot/_strings/cmd/command_strings.json +++ b/src/NadekoBot/_strings/cmd/command_strings.json @@ -1971,10 +1971,10 @@ }, "listquotes": { "Cmd": "listquotes liqu", - "Desc": "Lists all quotes on the server ordered alphabetically. 15 Per page.", + "Desc": "Lists all quotes on the server ordered alphabetically or by ID. 15 Per page.", "Usage": [ - "{0}liqu", - "{0}liqu 3" + "{0}liqu 3", + "{0}liqu 3 id" ] }, "typedel": {