Merge pull request #1161 from shikhir-arora/delete

Added: View/search quotes by quote ID (.qid [id] / .quoteid [id])
This commit is contained in:
Master Kwoth 2017-04-02 23:51:33 +02:00 committed by GitHub
commit d62eda2ecc
5 changed files with 92 additions and 8 deletions

View File

@ -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)
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);

View File

@ -5729,6 +5729,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar quoteid qid.
/// </summary>
public static string quoteid_cmd {
get {
return ResourceManager.GetString("quoteid_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Displays the quote with the specified ID number. Quote ID numbers can be found by typing `.liqu [num]` where `[num]` is a number of a page which contains 15 quotes..
/// </summary>
public static string quoteid_desc {
get {
return ResourceManager.GetString("quoteid_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}qid 123456`.
/// </summary>
public static string quoteid_usage {
get {
return ResourceManager.GetString("quoteid_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to race.
/// </summary>

View File

@ -1151,6 +1151,15 @@
</data>
<data name="searchquote_usage" xml:space="preserve">
<value>`{0}qsearch keyword text`</value>
</data>
<data name="quoteid_cmd" xml:space="preserve">
<value>quoteid qid</value>
</data>
<data name="quoteid_desc" xml:space="preserve">
<value>Displays the quote with the specified ID number. Quote ID numbers can be found by typing `.liqu [num]` where `[num]` is a number of a page which contains 15 quotes.</value>
</data>
<data name="quoteid_usage" xml:space="preserve">
<value>`{0}qid 123456`</value>
</data>
<data name="deletequote_cmd" xml:space="preserve">
<value>deletequote delq</value>
@ -3339,4 +3348,4 @@
<data name="slowmodewhitelist_usage" xml:space="preserve">
<value>`{0}slowmodewl SomeRole` or `{0}slowmodewl AdminDude`</value>
</data>
</root>
</root>

View File

@ -6506,6 +6506,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No quotes found matching the quote ID specified..
/// </summary>
public static string utility_quotes_notfound {
get {
return ResourceManager.GetString("utility_quotes_notfound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No quotes found which you can remove..
/// </summary>

View File

@ -2083,6 +2083,9 @@ Owner ID: {2}</value>
</data>
<data name="utility_quotes_page_none" xml:space="preserve">
<value>No quotes on this page.</value>
<data name="utility_quotes_notfound" xml:space="preserve">
<value>No quotes found matching the quote ID specified.</value>
</data>
</data>
<data name="utility_quotes_remove_none" xml:space="preserve">
<value>No quotes found which you can remove.</value>
@ -2402,4 +2405,4 @@ Owner ID: {2}</value>
<data name="utility_clpa_too_early" xml:space="preserve">
<value>Rewards can be claimed on or after 5th of each month.</value>
</data>
</root>
</root>