This commit is contained in:
Kwoth 2017-04-03 14:39:49 +02:00
commit aa6f700d0b
5 changed files with 92 additions and 8 deletions

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

View File

@ -5756,6 +5756,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> /// <summary>
/// Looks up a localized string similar to race. /// Looks up a localized string similar to race.
/// </summary> /// </summary>

View File

@ -1151,6 +1151,15 @@
</data> </data>
<data name="searchquote_usage" xml:space="preserve"> <data name="searchquote_usage" xml:space="preserve">
<value>`{0}qsearch keyword text`</value> <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>
<data name="deletequote_cmd" xml:space="preserve"> <data name="deletequote_cmd" xml:space="preserve">
<value>deletequote delq</value> <value>deletequote delq</value>
@ -3348,4 +3357,4 @@
<data name="slowmodewhitelist_usage" xml:space="preserve"> <data name="slowmodewhitelist_usage" xml:space="preserve">
<value>`{0}slowmodewl SomeRole` or `{0}slowmodewl AdminDude`</value> <value>`{0}slowmodewl SomeRole` or `{0}slowmodewl AdminDude`</value>
</data> </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> /// <summary>
/// Looks up a localized string similar to No quotes found which you can remove.. /// Looks up a localized string similar to No quotes found which you can remove..
/// </summary> /// </summary>

View File

@ -2083,6 +2083,9 @@ Owner ID: {2}</value>
</data> </data>
<data name="utility_quotes_page_none" xml:space="preserve"> <data name="utility_quotes_page_none" xml:space="preserve">
<value>No quotes on this page.</value> <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>
<data name="utility_quotes_remove_none" xml:space="preserve"> <data name="utility_quotes_remove_none" xml:space="preserve">
<value>No quotes found which you can remove.</value> <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"> <data name="utility_clpa_too_early" xml:space="preserve">
<value>Rewards can be claimed on or after 5th of each month.</value> <value>Rewards can be claimed on or after 5th of each month.</value>
</data> </data>
</root> </root>