diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index 5a7fc983..d811f565 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -72,8 +72,8 @@ namespace NadekoBot.Modules.Utility await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions()); } - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] public async Task SearchQuote(string keyword, [Remainder] string text) { if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text)) @@ -83,14 +83,14 @@ namespace NadekoBot.Modules.Utility 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()); + await Context.Channel.SendMessageAsync("💬 " + keyword.ToLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions()); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index 898f0efd..c2963c2b 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -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.Linq; using System.Threading.Tasks; @@ -26,7 +28,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl public Task 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(); + return _set.Where(q => q.Text.ContainsNoCase(text, StringComparison.OrdinalIgnoreCase) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } } diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 8dbdf02b..f95e6fbb 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -278,6 +278,15 @@ namespace NadekoBot.Extensions return list; } } + + /// + /// Easy use of fast, efficient case-insensitive Contains check with StringComparison Member Types + /// CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase + /// + 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) { @@ -436,4 +445,4 @@ namespace NadekoBot.Extensions : usr.AvatarUrl; } } -} \ No newline at end of file +}