diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index f1133359..19ccc770 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -15,6 +15,30 @@ namespace NadekoBot.Modules.Utility { public partial class Utility { + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task ListQuotes(IUserMessage imsg, int page = 1) + { + var channel = (ITextChannel)imsg.Channel; + + page -= 1; + + if (page < 0) + return; + + IEnumerable quotes; + using (var uow = DbHandler.UnitOfWork()) + { + quotes = uow.Quotes.GetGroup(page * 16, 16); + } + + if (quotes.Any()) + await channel.SendMessageAsync($"`Page {page + 1} of quotes:`\n```xl\n" + String.Join("\n", quotes.Select((q) => $"{q.Keyword,-20} by {q.AuthorName}")) + "\n```") + .ConfigureAwait(false); + else + await channel.SendMessageAsync("`No quotes on this page.`").ConfigureAwait(false); + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task ShowQuote(IUserMessage umsg, [Remainder] string keyword) diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index f4cf477f..ef639f4c 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -3407,6 +3407,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to listquotes liqu. + /// + public static string listquotes_cmd { + get { + return ResourceManager.GetString("listquotes_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}liqu` or `{0}liqu 3`. + /// + public static string listquotes_desc { + get { + return ResourceManager.GetString("listquotes_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lists all quotes on the server ordered alphabetically. 15 Per page.. + /// + public static string listquotes_usage { + get { + return ResourceManager.GetString("listquotes_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to liststreams ls. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 8fc36849..23fdb67f 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2565,4 +2565,13 @@ `{0}at` or `{0}at del` + + listquotes liqu + + + `{0}liqu` or `{0}liqu 3` + + + Lists all quotes on the server ordered alphabetically. 15 Per page. + \ No newline at end of file diff --git a/src/NadekoBot/Services/Database/Repositories/IQuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/IQuoteRepository.cs index f119fb1e..7dd06e8b 100644 --- a/src/NadekoBot/Services/Database/Repositories/IQuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/IQuoteRepository.cs @@ -11,5 +11,6 @@ namespace NadekoBot.Services.Database.Repositories { IEnumerable GetAllQuotesByKeyword(ulong guildId, string keyword); Task GetRandomQuoteByKeywordAsync(ulong guildId, string keyword); + IEnumerable GetGroup(int skip, int take); } } diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index 35e9bd0e..d0cf8ae9 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -18,6 +18,9 @@ namespace NadekoBot.Services.Database.Repositories.Impl public IEnumerable GetAllQuotesByKeyword(ulong guildId, string keyword) => _set.Where(q => q.GuildId == guildId && q.Keyword == keyword); + public IEnumerable GetGroup(int skip, int take) => + _set.OrderBy(q => q.Keyword).Skip(skip).Take(take).ToList(); + public Task GetRandomQuoteByKeywordAsync(ulong guildId, string keyword) { var rng = new NadekoRandom();