From d256d520e4b12c5c89d83502d7f5e10b186d241e Mon Sep 17 00:00:00 2001 From: Shikhir Arora Date: Sun, 2 Apr 2017 15:43:02 -0400 Subject: [PATCH] Add quote ID search --- .../Modules/Utility/Commands/QuoteCommands.cs | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index ea4bc674..37fdbf07 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -1,4 +1,4 @@ -using Discord; +using Discord; using Discord.Commands; using NadekoBot.Attributes; using NadekoBot.Extensions; @@ -100,7 +100,43 @@ namespace NadekoBot.Modules.Utility await Context.Channel.SendMessageAsync($"`#{keywordquote.Id}` 💬 " + keyword.ToLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions()); } - + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task QuoteId(int id) + { + if (id < 0 || id > Int32.MaxValue) + return; + + using (var uow = DbHandler.UnitOfWork()) + { + var qfromid = uow.Quotes.Get(id); + CREmbed crembed; + + if (qfromid == null) + { + await Context.Channel.SendErrorAsync(GetText("quotes_notfound")); + } + else if (CREmbed.TryParse(qfromid.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; + } + + else { await Context.Channel.SendMessageAsync($"`#{qfromid.Id}` 🗯️ " + qfromid.Keyword.ToLowerInvariant() + ": " + + qfromid.Text.SanitizeMentions()); } + } + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task AddQuote(string keyword, [Remainder] string text) @@ -130,8 +166,8 @@ namespace NadekoBot.Modules.Utility public async Task DeleteQuote(int id) { var isAdmin = ((IGuildUser) Context.Message.Author).GuildPermissions.Administrator; - - var sucess = false; + + var success = false; string response; using (var uow = DbHandler.UnitOfWork()) { @@ -145,11 +181,11 @@ namespace NadekoBot.Modules.Utility { uow.Quotes.Remove(q); await uow.CompleteAsync().ConfigureAwait(false); - sucess = true; + success = true; response = GetText("quote_deleted", id); } } - if (sucess) + if (success) await Context.Channel.SendConfirmAsync(response); else await Context.Channel.SendErrorAsync(response);