WHEW. Added placeholders in embeds and quotes, added docs about it to explained features. Wrote a placeholder system and fixed some bugs

This commit is contained in:
Master Kwoth
2017-06-28 02:44:30 +02:00
parent aa5b7f96c7
commit 942f15cf05
14 changed files with 328 additions and 210 deletions

View File

@ -33,11 +33,11 @@ namespace NadekoBot.Modules.Administration
{
var config = uow.BotConfig.GetOrCreate();
_service.RotatingStatuses = config.RotatingStatuses = !config.RotatingStatuses;
config.RotatingStatuses = !config.RotatingStatuses;
uow.Complete();
}
}
if (_service.RotatingStatuses)
if (_service.BotConfig.RotatingStatuses)
await ReplyConfirmLocalized("ropl_enabled").ConfigureAwait(false);
else
await ReplyConfirmLocalized("ropl_disabled").ConfigureAwait(false);
@ -52,7 +52,6 @@ namespace NadekoBot.Modules.Administration
var config = uow.BotConfig.GetOrCreate();
var toAdd = new PlayingStatus { Status = status };
config.RotatingStatusMessages.Add(toAdd);
_service.RotatingStatusMessages.Add(toAdd);
await uow.CompleteAsync();
}
@ -63,13 +62,13 @@ namespace NadekoBot.Modules.Administration
[OwnerOnly]
public async Task ListPlaying()
{
if (!_service.RotatingStatusMessages.Any())
if (!_service.BotConfig.RotatingStatusMessages.Any())
await ReplyErrorLocalized("ropl_not_set").ConfigureAwait(false);
else
{
var i = 1;
await ReplyConfirmLocalized("ropl_list",
string.Join("\n\t", _service.RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}")))
string.Join("\n\t", _service.BotConfig.RotatingStatusMessages.Select(rs => $"`{i++}.` {rs.Status}")))
.ConfigureAwait(false);
}
@ -90,7 +89,6 @@ namespace NadekoBot.Modules.Administration
return;
msg = config.RotatingStatusMessages[index].Status;
config.RotatingStatusMessages.RemoveAt(index);
_service.RotatingStatusMessages.RemoveAt(index);
await uow.CompleteAsync();
}
await ReplyConfirmLocalized("reprm", msg).ConfigureAwait(false);

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NadekoBot.DataStructures;
using NadekoBot.DataStructures.Replacements;
namespace NadekoBot.Modules.Utility
{
@ -66,19 +67,14 @@ namespace NadekoBot.Modules.Utility
if (quote == null)
return;
CREmbed crembed;
if (CREmbed.TryParse(quote.Text, out crembed))
if (CREmbed.TryParse(quote.Text, out var crembed))
{
try
{
await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "")
.ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn("Sending CREmbed failed");
_log.Warn(ex);
}
new ReplacementBuilder()
.WithDefault(Context)
.Build()
.Replace(crembed);
await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText?.SanitizeMentions() ?? "")
.ConfigureAwait(false);
return;
}
await Context.Channel.SendMessageAsync($"`#{quote.Id}` 📣 " + quote.Text.SanitizeMentions());
@ -118,29 +114,27 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.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))
else if (CREmbed.TryParse(qfromid.Text, out var crembed))
{
try
{
await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "")
.ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn("Sending CREmbed failed");
_log.Warn(ex);
}
return;
new ReplacementBuilder()
.WithDefault(Context)
.Build()
.Replace(crembed);
await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText?.SanitizeMentions() ?? "")
.ConfigureAwait(false);
}
else { await Context.Channel.SendMessageAsync($"`#{qfromid.Id}` 🗯️ " + qfromid.Keyword.ToLowerInvariant().SanitizeMentions() + ": " +
qfromid.Text.SanitizeMentions()); }
else
{
await Context.Channel.SendMessageAsync($"`#{qfromid.Id}` 🗯️ " + qfromid.Keyword.ToLowerInvariant().SanitizeMentions() + ": " +
qfromid.Text.SanitizeMentions());
}
}
}