Added .liqu command which lists quotes

This commit is contained in:
Kwoth 2016-10-27 12:36:42 +02:00
parent 84a0fc4c8f
commit 828eb29b5c
5 changed files with 64 additions and 0 deletions

View File

@ -15,6 +15,30 @@ namespace NadekoBot.Modules.Utility
{ {
public partial class 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<Quote> 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ShowQuote(IUserMessage umsg, [Remainder] string keyword) public async Task ShowQuote(IUserMessage umsg, [Remainder] string keyword)

View File

@ -3407,6 +3407,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to listquotes liqu.
/// </summary>
public static string listquotes_cmd {
get {
return ResourceManager.GetString("listquotes_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}liqu` or `{0}liqu 3`.
/// </summary>
public static string listquotes_desc {
get {
return ResourceManager.GetString("listquotes_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lists all quotes on the server ordered alphabetically. 15 Per page..
/// </summary>
public static string listquotes_usage {
get {
return ResourceManager.GetString("listquotes_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to liststreams ls. /// Looks up a localized string similar to liststreams ls.
/// </summary> /// </summary>

View File

@ -2565,4 +2565,13 @@
<data name="autotranslate_usage" xml:space="preserve"> <data name="autotranslate_usage" xml:space="preserve">
<value>`{0}at` or `{0}at del`</value> <value>`{0}at` or `{0}at del`</value>
</data> </data>
<data name="listquotes_cmd" xml:space="preserve">
<value>listquotes liqu</value>
</data>
<data name="listquotes_desc" xml:space="preserve">
<value>`{0}liqu` or `{0}liqu 3`</value>
</data>
<data name="listquotes_usage" xml:space="preserve">
<value>Lists all quotes on the server ordered alphabetically. 15 Per page.</value>
</data>
</root> </root>

View File

@ -11,5 +11,6 @@ namespace NadekoBot.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);
IEnumerable<Quote> GetGroup(int skip, int take);
} }
} }

View File

@ -18,6 +18,9 @@ namespace NadekoBot.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(int skip, int take) =>
_set.OrderBy(q => q.Keyword).Skip(skip).Take(take).ToList();
public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword) public Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword)
{ {
var rng = new NadekoRandom(); var rng = new NadekoRandom();