Merge pull request #1061 from shikhir-arora/dev

Add search by keyword and portion of quote command
This commit is contained in:
Master Kwoth 2017-02-17 23:18:27 +01:00 committed by GitHub
commit 8af17195fb
6 changed files with 66 additions and 3 deletions

@ -1 +1 @@
Subproject commit d2229228b92117899d65cd549a1f2853057b255b Subproject commit 9ce5c4757efc6cb6bb8959e851abcdcbe03217be

View File

@ -70,6 +70,27 @@ namespace NadekoBot.Modules.Utility
} }
await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions()); 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
@ -155,4 +176,4 @@ namespace NadekoBot.Modules.Utility
} }
} }
} }
} }

View File

@ -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> /// <summary>
/// Looks up a localized string similar to delmsgoncmd. /// Looks up a localized string similar to delmsgoncmd.
/// </summary> /// </summary>

View File

@ -1143,6 +1143,15 @@
<data name="showquote_usage" xml:space="preserve"> <data name="showquote_usage" xml:space="preserve">
<value>`{0}.. abc`</value> <value>`{0}.. abc`</value>
</data> </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"> <data name="deletequote_cmd" xml:space="preserve">
<value>deletequote delq</value> <value>deletequote delq</value>
</data> </data>
@ -3132,4 +3141,4 @@
<data name="languageslist_usage" xml:space="preserve"> <data name="languageslist_usage" xml:space="preserve">
<value>`{0}langli`</value> <value>`{0}langli`</value>
</data> </data>
</root> </root>

View File

@ -8,6 +8,7 @@ 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);
Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text);
IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take); IEnumerable<Quote> GetGroup(ulong guildId, int skip, int take);
} }
} }

View File

@ -23,5 +23,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl
var rng = new NadekoRandom(); var rng = new NadekoRandom();
return _set.Where(q => q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rng.Next()).FirstOrDefaultAsync(); 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();
}
} }
} }