Merge pull request #1061 from shikhir-arora/dev
Add search by keyword and portion of quote command
This commit is contained in:
commit
8af17195fb
@ -1 +1 @@
|
||||
Subproject commit d2229228b92117899d65cd549a1f2853057b255b
|
||||
Subproject commit 9ce5c4757efc6cb6bb8959e851abcdcbe03217be
|
@ -71,6 +71,27 @@ namespace NadekoBot.Modules.Utility
|
||||
await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions());
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task SearchQuote(string keyword, [Remainder] string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text))
|
||||
return;
|
||||
|
||||
keyword = keyword.ToUpperInvariant();
|
||||
|
||||
Quote keywordquote;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(Context.Guild.Id, keyword, text).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (keywordquote == null)
|
||||
return;
|
||||
|
||||
await Context.Channel.SendMessageAsync("💬 " + keyword + ": " + keywordquote.Text.SanitizeMentions());
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AddQuote(string keyword, [Remainder] string text)
|
||||
|
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -2381,6 +2381,33 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to qsearch.
|
||||
/// </summary>
|
||||
public static string searchquote_cmd {
|
||||
get {
|
||||
return ResourceManager.GetString("searchquote_cmd", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Searches a quote for a given keyword and any string portion of a quote matching that keyword..
|
||||
/// </summary>
|
||||
public static string searchquote_desc {
|
||||
get {
|
||||
return ResourceManager.GetString("searchquote_desc", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}qsearch keyword text`.
|
||||
/// </summary>
|
||||
public static string searchquote_usage {
|
||||
get {
|
||||
return ResourceManager.GetString("searchquote_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to delmsgoncmd.
|
||||
/// </summary>
|
||||
|
@ -1142,6 +1142,15 @@
|
||||
</data>
|
||||
<data name="showquote_usage" xml:space="preserve">
|
||||
<value>`{0}.. abc`</value>
|
||||
</data>
|
||||
<data name="searchquote_cmd" xml:space="preserve">
|
||||
<value>qsearch</value>
|
||||
</data>
|
||||
<data name="searchquote_desc" xml:space="preserve">
|
||||
<value>Searches a quote for a given keyword and any string portion of a quote matching that keyword.</value>
|
||||
</data>
|
||||
<data name="searchquote_usage" xml:space="preserve">
|
||||
<value>`{0}qsearch keyword text`</value>
|
||||
</data>
|
||||
<data name="deletequote_cmd" xml:space="preserve">
|
||||
<value>deletequote delq</value>
|
||||
|
@ -8,6 +8,7 @@ namespace NadekoBot.Services.Database.Repositories
|
||||
{
|
||||
IEnumerable<Quote> GetAllQuotesByKeyword(ulong guildId, string keyword);
|
||||
Task<Quote> GetRandomQuoteByKeywordAsync(ulong guildId, string keyword);
|
||||
Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text);
|
||||
IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take);
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
||||
var rng = new NadekoRandom();
|
||||
return _set.Where(q => q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rng.Next()).FirstOrDefaultAsync();
|
||||
}
|
||||
public Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text)
|
||||
{
|
||||
var rngk = new NadekoRandom();
|
||||
return _set.Where(q => q.Text.Contains(text) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user