From 011b951a29d7a1754ad8e058bc2c092c78c281e3 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 03:29:27 -0500 Subject: [PATCH 01/13] Update QuoteRepository.cs --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index 898f0efd..3de5853c 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -26,7 +26,8 @@ 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(); + lowertext = text.toLowerInvariant(); + return _set.Where(q => q.Text.Contains(text) || q.Text.Contains(lowertext) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } } From 9344c1b498462dc9378a879df9617bcae16e12ac Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 03:41:33 -0500 Subject: [PATCH 02/13] Support for embeds in .qsearch output - Support for embeds in .qsearch output results - Search can be case insensitive (changes made 011b951a29d7a1754ad8e058bc2c092c78c281e3) - Output shows keyword in lowercase as it's easier to read (line 104) - Minor syntax cleanups --- .../Modules/Utility/Commands/QuoteCommands.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index 5a7fc983..2b5a927d 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,25 @@ 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()); + + CREmbed crembed; + if (CREmbed.TryParse(keywordquote.Text, out crembed)) + { + try { await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); } + catch (Exception ex) + { + _log.Warn("Sending CREmbed failed"); + _log.Warn(ex); + } + return; + } + await Context.Channel.SendMessageAsync("πŸ’¬ " + keyword.toLowerInvariant(); + ": " + keywordquote.Text.SanitizeMentions()); } [NadekoCommand, Usage, Description, Aliases] From e2f855a72904c299ff48dc565bdb5d66bf45b364 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 03:46:10 -0500 Subject: [PATCH 03/13] Support for embeds in .qsearch output + case - Support for embeds in .qsearch output results - Search can be case insensitive (changes made 011b951a29d7a1754ad8e058bc2c092c78c281e3) - Output shows keyword in lowercase as it's easier to read (line 104) - Minor syntax cleanups --- src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index 2b5a927d..654f6853 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -101,7 +101,7 @@ namespace NadekoBot.Modules.Utility } return; } - await Context.Channel.SendMessageAsync("πŸ’¬ " + keyword.toLowerInvariant(); + ": " + keywordquote.Text.SanitizeMentions()); + await Context.Channel.SendMessageAsync("πŸ’¬ " + keyword.toLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions()); } [NadekoCommand, Usage, Description, Aliases] From b3080f193fe48312c84f245fce669838fa83f4c0 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 03:49:34 -0500 Subject: [PATCH 04/13] Update QuoteRepository.cs --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index 3de5853c..fe41b6d2 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -26,7 +26,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl public Task SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text) { var rngk = new NadekoRandom(); - lowertext = text.toLowerInvariant(); + lowertext = text.ToLowerInvariant(); return _set.Where(q => q.Text.Contains(text) || q.Text.Contains(lowertext) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } From 6773d1e86d17feccb78244c5f2d29fd0a18afde8 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 03:49:53 -0500 Subject: [PATCH 05/13] See 9344c1b498462dc9378a879df9617bcae16e12ac --- src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index 654f6853..e0445e0c 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -101,7 +101,7 @@ namespace NadekoBot.Modules.Utility } return; } - await Context.Channel.SendMessageAsync("πŸ’¬ " + keyword.toLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions()); + await Context.Channel.SendMessageAsync("πŸ’¬ " + keyword.ToLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions()); } [NadekoCommand, Usage, Description, Aliases] From 72de465c34ea710b383c5d959397a50b1c6ee5ac Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 03:57:39 -0500 Subject: [PATCH 06/13] Update QuoteRepository.cs handle all standard cases (matches text that contains the exact, upper, or lowercase forms of the input text to search) --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index fe41b6d2..fff61d22 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -27,7 +27,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl { var rngk = new NadekoRandom(); lowertext = text.ToLowerInvariant(); - return _set.Where(q => q.Text.Contains(text) || q.Text.Contains(lowertext) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); + uppertext = text.ToUpperInvariant(); + return _set.Where(q => q.Text.Contains(text) || q.Text.Contains(lowertext) || q.Text.Contains(uppertext) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } } From 0a55c6f09c05b0f152684b4d33368a3572b0b0ed Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 04:09:12 -0500 Subject: [PATCH 07/13] Update QuoteRepository.cs syntax cleanup --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index fff61d22..26639165 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl var rngk = new NadekoRandom(); lowertext = text.ToLowerInvariant(); uppertext = text.ToUpperInvariant(); - return _set.Where(q => q.Text.Contains(text) || q.Text.Contains(lowertext) || q.Text.Contains(uppertext) && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); + return _set.Where(q => q.GuildId == guildId && q.Keyword == keyword && (q.Text.Contains(text) || q.Text.Contains(lowertext) || q.Text.Contains(uppertext))).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } } From 97b314d61155e5dfa192f1cbf639638a8a112e70 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 04:44:49 -0500 Subject: [PATCH 08/13] Update QuoteRepository.cs whoops xD --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index 26639165..591c3dde 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -26,8 +26,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl public Task SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text) { var rngk = new NadekoRandom(); - lowertext = text.ToLowerInvariant(); - uppertext = text.ToUpperInvariant(); + string lowertext = text.ToLowerInvariant(); + string uppertext = text.ToUpperInvariant(); return _set.Where(q => q.GuildId == guildId && q.Keyword == keyword && (q.Text.Contains(text) || q.Text.Contains(lowertext) || q.Text.Contains(uppertext))).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } From 1418297958047ecd6b5a821dfecab8f22a2767ca Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 05:20:12 -0500 Subject: [PATCH 09/13] Update QuoteRepository.cs --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index 591c3dde..be9db36d 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl var rngk = new NadekoRandom(); string lowertext = text.ToLowerInvariant(); string uppertext = text.ToUpperInvariant(); - return _set.Where(q => q.GuildId == guildId && q.Keyword == keyword && (q.Text.Contains(text) || q.Text.Contains(lowertext) || q.Text.Contains(uppertext))).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); + return _set.Where(q => (q.Text.Contains(text) | q.Text.Contains(lowertext) | q.Text.Contains(uppertext)) & (q.GuildId == guildId && q.Keyword == keyword)).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } } From f4870c4678112638b693e59872ae936dc2989ae7 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 11:22:07 -0500 Subject: [PATCH 10/13] Update QuoteRepository.cs --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index be9db36d..a7036dff 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -1,4 +1,5 @@ -ο»Ώusing NadekoBot.Services.Database.Models; +using NadekoBot.Services.Database.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -26,9 +27,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl public Task SearchQuoteKeywordTextAsync(ulong guildId, string keyword, string text) { var rngk = new NadekoRandom(); - string lowertext = text.ToLowerInvariant(); - string uppertext = text.ToUpperInvariant(); - return _set.Where(q => (q.Text.Contains(text) | q.Text.Contains(lowertext) | q.Text.Contains(uppertext)) & (q.GuildId == guildId && q.Keyword == keyword)).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); + return _set.Where(q => q.Text.IndexOf(text, StringComparison.OrdinalIgnoreCase) >=0 && q.GuildId == guildId && q.Keyword == keyword).OrderBy(q => rngk.Next()).FirstOrDefaultAsync(); } } } From c7e694fc1d01fe07d9e1b0fd92b769ef1ff81678 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 11:24:37 -0500 Subject: [PATCH 11/13] Update QuoteCommands.cs --- .../Modules/Utility/Commands/QuoteCommands.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index e0445e0c..d811f565 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -89,18 +89,7 @@ namespace NadekoBot.Modules.Utility if (keywordquote == null) return; - - CREmbed crembed; - if (CREmbed.TryParse(keywordquote.Text, out crembed)) - { - try { await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); } - catch (Exception ex) - { - _log.Warn("Sending CREmbed failed"); - _log.Warn(ex); - } - return; - } + await Context.Channel.SendMessageAsync("πŸ’¬ " + keyword.ToLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions()); } From 33faec9649ad47f64ea47af55925e8e3f85006d3 Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 17:21:03 -0500 Subject: [PATCH 12/13] ContainsNoCase Extension for Contains() used extensively, here as `ContainsNoCase` for indexOf() with StringComparison type options: CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase The extension here implements the String.IndexOf Method (String,StringComparison) method: https://msdn.microsoft.com/en-us/library/ms224425(v=vs.110).aspx Allows clean access to this method as `ContainsNoCase(string, StringComparison.TYPE)` --- src/NadekoBot/_Extensions/Extensions.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 +} From f023251170fd98f683433993165643b9bae6884e Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Thu, 2 Mar 2017 17:26:40 -0500 Subject: [PATCH 13/13] Update QuoteRepository.cs updated with syntax from added extensions --- .../Services/Database/Repositories/Impl/QuoteRepository.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs index a7036dff..c2963c2b 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/QuoteRepository.cs @@ -1,4 +1,5 @@ using NadekoBot.Services.Database.Models; +using NadekoBot.Extensions; using System; using System.Collections.Generic; using System.Linq; @@ -27,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.IndexOf(text, StringComparison.OrdinalIgnoreCase) >=0 && 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(); } } }