Quote system improved. Quotes now show ids, and .delq is taking an ID
This commit is contained in:
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
var startPos = 20 * (page - 1);
|
||||
var toSend = Format.Bold(GetText("page", page)) + "\n\n" + string.Join("\n",
|
||||
perms.Reverse()
|
||||
.Skip((page - 1) * 20)
|
||||
.Skip(startPos)
|
||||
.Take(20)
|
||||
.Select(p =>
|
||||
{
|
||||
|
@@ -33,9 +33,9 @@ namespace NadekoBot.Modules.Utility
|
||||
}
|
||||
|
||||
if (quotes.Any())
|
||||
await Context.Channel.SendConfirmAsync(GetText("quotes_page", page + 1),
|
||||
string.Join("\n", quotes.Select(q => $"{q.Keyword,-20} by {q.AuthorName}")))
|
||||
.ConfigureAwait(false);
|
||||
await Context.Channel.SendConfirmAsync(GetText("quotes_page", page + 1),
|
||||
string.Join("\n", quotes.Select(q => $"`#{q.Id}` {Format.Bold(q.Keyword),-20} by {q.AuthorName}")))
|
||||
.ConfigureAwait(false);
|
||||
else
|
||||
await ReplyErrorLocalized("quotes_page_none").ConfigureAwait(false);
|
||||
}
|
||||
@@ -52,7 +52,8 @@ namespace NadekoBot.Modules.Utility
|
||||
Quote quote;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(Context.Guild.Id, keyword).ConfigureAwait(false);
|
||||
quote =
|
||||
await uow.Quotes.GetRandomQuoteByKeywordAsync(Context.Guild.Id, keyword).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (quote == null)
|
||||
@@ -61,7 +62,11 @@ namespace NadekoBot.Modules.Utility
|
||||
CREmbed crembed;
|
||||
if (CREmbed.TryParse(quote.Text, out crembed))
|
||||
{
|
||||
try { await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); }
|
||||
try
|
||||
{
|
||||
await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "")
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn("Sending CREmbed failed");
|
||||
@@ -69,28 +74,31 @@ namespace NadekoBot.Modules.Utility
|
||||
}
|
||||
return;
|
||||
}
|
||||
await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions());
|
||||
await Context.Channel.SendMessageAsync($"`#{quote.Id}` 📣 " + quote.Text.SanitizeMentions());
|
||||
}
|
||||
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task SearchQuote(string keyword, [Remainder] string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text))
|
||||
return;
|
||||
if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text))
|
||||
return;
|
||||
|
||||
keyword = keyword.ToUpperInvariant();
|
||||
|
||||
Quote keywordquote;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(Context.Guild.Id, keyword, text).ConfigureAwait(false);
|
||||
keywordquote =
|
||||
await uow.Quotes.SearchQuoteKeywordTextAsync(Context.Guild.Id, keyword, text)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (keywordquote == null)
|
||||
return;
|
||||
|
||||
await Context.Channel.SendMessageAsync("💬 " + keyword.ToLowerInvariant() + ": " + keywordquote.Text.SanitizeMentions());
|
||||
await Context.Channel.SendMessageAsync("💬 " + keyword.ToLowerInvariant() + ": " +
|
||||
keywordquote.Text.SanitizeMentions());
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -119,36 +127,29 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task DeleteQuote([Remainder] string keyword)
|
||||
public async Task DeleteQuote(int id)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
return;
|
||||
var isAdmin = ((IGuildUser) Context.Message.Author).GuildPermissions.Administrator;
|
||||
|
||||
var isAdmin = ((IGuildUser)Context.Message.Author).GuildPermissions.Administrator;
|
||||
|
||||
keyword = keyword.ToUpperInvariant();
|
||||
var sucess = false;
|
||||
string response;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var qs = uow.Quotes.GetAllQuotesByKeyword(Context.Guild.Id, keyword)?.Where(elem => isAdmin || elem.AuthorId == Context.Message.Author.Id).ToArray();
|
||||
var q = uow.Quotes.Get(id);
|
||||
|
||||
if (qs == null || !qs.Any())
|
||||
if (q == null || (!isAdmin && q.AuthorId != Context.Message.Author.Id))
|
||||
{
|
||||
sucess = false;
|
||||
response = GetText("quotes_remove_none");
|
||||
}
|
||||
else
|
||||
{
|
||||
var q = qs[new NadekoRandom().Next(0, qs.Length)];
|
||||
|
||||
uow.Quotes.Remove(q);
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
sucess = true;
|
||||
response = GetText("quote_deleted");
|
||||
response = GetText("quote_deleted", id);
|
||||
}
|
||||
}
|
||||
if(sucess)
|
||||
if (sucess)
|
||||
await Context.Channel.SendConfirmAsync(response);
|
||||
else
|
||||
await Context.Channel.SendErrorAsync(response);
|
||||
@@ -166,9 +167,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var quotes = uow.Quotes.GetAllQuotesByKeyword(Context.Guild.Id, keyword);
|
||||
//todo kwoth please don't be complete retard
|
||||
uow.Quotes.RemoveRange(quotes.ToArray());//wtf?!
|
||||
uow.Quotes.RemoveAllByKeyword(Context.Guild.Id, keyword.ToUpperInvariant());
|
||||
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
@@ -177,4 +176,4 @@ namespace NadekoBot.Modules.Utility
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user