Add quote ID search

This commit is contained in:
Shikhir Arora 2017-04-02 15:43:02 -04:00 committed by GitHub
parent 78a3f1dc85
commit d256d520e4

View File

@ -1,4 +1,4 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
@ -100,7 +100,43 @@ namespace NadekoBot.Modules.Utility
await Context.Channel.SendMessageAsync($"`#{keywordquote.Id}` 💬 " + keyword.ToLowerInvariant() + ": " + await Context.Channel.SendMessageAsync($"`#{keywordquote.Id}` 💬 " + keyword.ToLowerInvariant() + ": " +
keywordquote.Text.SanitizeMentions()); 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task AddQuote(string keyword, [Remainder] string text) public async Task AddQuote(string keyword, [Remainder] string text)
@ -130,8 +166,8 @@ namespace NadekoBot.Modules.Utility
public async Task DeleteQuote(int id) public async Task DeleteQuote(int id)
{ {
var isAdmin = ((IGuildUser) Context.Message.Author).GuildPermissions.Administrator; var isAdmin = ((IGuildUser) Context.Message.Author).GuildPermissions.Administrator;
var sucess = false; var success = false;
string response; string response;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -145,11 +181,11 @@ namespace NadekoBot.Modules.Utility
{ {
uow.Quotes.Remove(q); uow.Quotes.Remove(q);
await uow.CompleteAsync().ConfigureAwait(false); await uow.CompleteAsync().ConfigureAwait(false);
sucess = true; success = true;
response = GetText("quote_deleted", id); response = GetText("quote_deleted", id);
} }
} }
if (sucess) if (success)
await Context.Channel.SendConfirmAsync(response); await Context.Channel.SendConfirmAsync(response);
else else
await Context.Channel.SendErrorAsync(response); await Context.Channel.SendErrorAsync(response);