.liqu can be ordered by keywords (default) or id now, closes #1857
This commit is contained in:
parent
8fb21d1a3e
commit
a0c5b469b8
@ -26,17 +26,16 @@ namespace NadekoBot.Modules.Utility
|
|||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ListQuotes(int page = 1)
|
public async Task ListQuotes(int page = 1, OrderType order = OrderType.Keyword)
|
||||||
{
|
{
|
||||||
page -= 1;
|
page -= 1;
|
||||||
|
|
||||||
if (page < 0)
|
if (page < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IEnumerable<Quote> quotes;
|
IEnumerable<Quote> quotes;
|
||||||
using (var uow = _db.UnitOfWork)
|
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())
|
if (quotes.Any())
|
||||||
|
@ -13,4 +13,11 @@ namespace NadekoBot.Core.Services.Database.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum OrderType
|
||||||
|
{
|
||||||
|
Id,
|
||||||
|
Keyword
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace NadekoBot.Core.Services.Database.Repositories
|
|||||||
IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword);
|
IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword);
|
||||||
Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword);
|
Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword);
|
||||||
Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text);
|
Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text);
|
||||||
IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take);
|
IEnumerable<Quote> GetGroup(ulong guildId, int page, OrderType order);
|
||||||
void RemoveAllByKeyword(ulong guildId, string keyword);
|
void RemoveAllByKeyword(ulong guildId, string keyword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,16 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
|||||||
public IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword) =>
|
public IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword) =>
|
||||||
_set.Where(q => q.GuildId == guildId && q.Keyword == keyword);
|
_set.Where(q => q.GuildId == guildId && q.Keyword == keyword);
|
||||||
|
|
||||||
public IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take) =>
|
public IEnumerable<Quote> GetGroup(ulong guildId, int page, OrderType order)
|
||||||
_set.Where(q=>q.GuildId == guildId).OrderBy(q => q.Keyword).Skip(skip).Take(take).ToList();
|
{
|
||||||
|
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<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
|
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
|
||||||
{
|
{
|
||||||
|
@ -1971,10 +1971,10 @@
|
|||||||
},
|
},
|
||||||
"listquotes": {
|
"listquotes": {
|
||||||
"Cmd": "listquotes liqu",
|
"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": [
|
"Usage": [
|
||||||
"{0}liqu",
|
"{0}liqu 3",
|
||||||
"{0}liqu 3"
|
"{0}liqu 3 id"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"typedel": {
|
"typedel": {
|
||||||
|
Loading…
Reference in New Issue
Block a user