diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 968ddea59..5a723b516 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -261,6 +261,7 @@ public sealed class Bot Client.JoinedGuild += Client_JoinedGuild; Client.LeftGuild += Client_LeftGuild; + // _ = Client.SetStatusAsync(UserStatus.Online); Log.Information("Shard {ShardId} logged in", Client.ShardId); } diff --git a/src/NadekoBot/Db/Extensions/QuoteExtensions.cs b/src/NadekoBot/Db/Extensions/QuoteExtensions.cs index d679fd202..fce0ed76d 100644 --- a/src/NadekoBot/Db/Extensions/QuoteExtensions.cs +++ b/src/NadekoBot/Db/Extensions/QuoteExtensions.cs @@ -44,12 +44,12 @@ public static class QuoteExtensions var rngk = new NadekoRandom(); return (await quotes.AsQueryable() .Where(q => q.GuildId == guildId - && q.Keyword == keyword - && EF.Functions.Like(q.Text.ToUpper(), $"%{text.ToUpper()}%") - // && q.Text.Contains(text, StringComparison.OrdinalIgnoreCase) - ) - .ToListAsync()).OrderBy(_ => rngk.Next()) - .FirstOrDefault(); + && (keyword == null || q.Keyword == keyword) + && (EF.Functions.Like(q.Text.ToUpper(), $"%{text.ToUpper()}%") + || EF.Functions.Like(q.AuthorName, text))) + .ToListAsync()) + .OrderBy(_ => rngk.Next()) + .FirstOrDefault(); } public static void RemoveAllByKeyword(this DbSet quotes, ulong guildId, string keyword) diff --git a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs index e7ca30dd0..a80f950c7 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs @@ -335,6 +335,7 @@ public partial class Administration { try { + await _client.SetStatusAsync(UserStatus.DoNotDisturb); await ReplyConfirmLocalizedAsync(strs.shutting_down); } catch diff --git a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs index ebca3c24e..d5c066094 100644 --- a/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Quote/QuoteCommands.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable warnings using NadekoBot.Common.Yml; using NadekoBot.Db; using NadekoBot.Services.Database.Models; @@ -134,30 +134,40 @@ public partial class Utility .WithFooter( GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})")))); - [Cmd] - [RequireContext(ContextType.Guild)] - public async partial Task QuoteSearch(string keyword, [Leftover] string text) + private async Task QuoteSearchinternalAsync(string? keyword, string textOrAuthor) { - if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text)) + if (string.IsNullOrWhiteSpace(textOrAuthor)) return; - keyword = keyword.ToUpperInvariant(); + keyword = keyword?.ToUpperInvariant(); - Quote keywordquote; + Quote quote; await using (var uow = _db.GetDbContext()) { - keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text); + quote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, textOrAuthor); } - if (keywordquote is null) + if (quote is null) return; - await ctx.Channel.SendMessageAsync($"`#{keywordquote.Id}` 💬 " - + keyword.ToLowerInvariant() + await ctx.Channel.SendMessageAsync($"`#{quote.Id}` 💬 " + + quote.Keyword.ToLowerInvariant() + ": " - + keywordquote.Text.SanitizeAllMentions()); + + quote.Text.SanitizeAllMentions()); } + [Cmd] + [RequireContext(ContextType.Guild)] + [Priority(0)] + public partial Task QuoteSearch(string textOrAuthor) + => QuoteSearchinternalAsync(null, textOrAuthor); + + [Cmd] + [RequireContext(ContextType.Guild)] + [Priority(1)] + public partial Task QuoteSearch(string keyword, [Leftover] string textOrAuthor) + => QuoteSearchinternalAsync(keyword, textOrAuthor); + [Cmd] [RequireContext(ContextType.Guild)] public async partial Task QuoteId(int id) diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 0f5238ddf..09873a369 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -601,9 +601,12 @@ quoteshow: args: - "123" quotesearch: - desc: "Shows a random quote for a keyword that contains any text specified in the search." + desc: "Shows a random quote given a search query. Partially matches in several ways: 1) Only content of any quote, 2) only by author, 3) keyword and content, 3) or keyword and author" args: - - "keyword text" + - """find this long text""" + - "AuthorName" + - "keyword some text" + - "keyword AuthorName" quoteid: desc: "Displays the quote with the specified ID number. Quote ID numbers can be found by typing `{0}liqu [num]` where `[num]` is a number of a page which contains 15 quotes." args: