Merge pull request #1100 from shikhir-arora/dev
Added support in .qsearch output, support for all cases, add ContainsNoCase Extension
This commit is contained in:
commit
a22e8cafb4
@ -72,8 +72,8 @@ namespace NadekoBot.Modules.Utility
|
|||||||
await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions());
|
await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions());
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task SearchQuote(string keyword, [Remainder] string text)
|
public async Task SearchQuote(string keyword, [Remainder] string text)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text))
|
if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text))
|
||||||
@ -83,14 +83,14 @@ namespace NadekoBot.Modules.Utility
|
|||||||
|
|
||||||
Quote keywordquote;
|
Quote keywordquote;
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(Context.Guild.Id, keyword, text).ConfigureAwait(false);
|
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(Context.Guild.Id, keyword, text).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keywordquote == null)
|
if (keywordquote == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Context.Channel.SendMessageAsync("💬 " + keyword + ": " + keywordquote.Text.SanitizeMentions());
|
await Context.Channel.SendMessageAsync("💬 " + keyword.ToLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions());
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using NadekoBot.Extensions;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -26,7 +28,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
public Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text)
|
public Task<Quote> SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text)
|
||||||
{
|
{
|
||||||
var rngk = new NadekoRandom();
|
var rngk = new NadekoRandom();
|
||||||
return _set.Where(q => q.Text.Contains(text) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync();
|
return _set.Where(q => q.Text.ContainsNoCase(text, StringComparison.OrdinalIgnoreCase) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,6 +279,15 @@ namespace NadekoBot.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Easy use of fast, efficient case-insensitive Contains check with StringComparison Member Types
|
||||||
|
/// CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase
|
||||||
|
/// </summary>
|
||||||
|
public static bool ContainsNoCase(this string str, string contains, StringComparison compare)
|
||||||
|
{
|
||||||
|
return str.IndexOf(contains, compare) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static string TrimTo(this string str, int maxLength, bool hideDots = false)
|
public static string TrimTo(this string str, int maxLength, bool hideDots = false)
|
||||||
{
|
{
|
||||||
if (maxLength < 0)
|
if (maxLength < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user