Part2 of the response system rework

This commit is contained in:
Kwoth
2024-04-29 01:13:45 +00:00
parent 4bab94b329
commit d28c7b500d
128 changed files with 2723 additions and 2289 deletions

View File

@@ -1,12 +1,12 @@
#nullable disable
using NadekoBot.Common.Configs;
// todo remove
namespace NadekoBot.Services;
public interface IEmbedBuilderService
{
IEmbedBuilder Create(ICommandContext ctx = null);
IEmbedBuilder Create(EmbedBuilder eb);
EmbedBuilder Create(ICommandContext ctx = null);
}
public class EmbedBuilderService : IEmbedBuilderService, INService
@@ -16,11 +16,9 @@ public class EmbedBuilderService : IEmbedBuilderService, INService
public EmbedBuilderService(BotConfigService botConfigService)
=> _botConfigService = botConfigService;
public IEmbedBuilder Create(ICommandContext ctx = null)
=> new DiscordEmbedBuilderWrapper(_botConfigService.Data);
public EmbedBuilder Create(ICommandContext ctx = null)
=> new EmbedBuilder();
public IEmbedBuilder Create(EmbedBuilder embed)
=> new DiscordEmbedBuilderWrapper(_botConfigService.Data, embed);
}
public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder
@@ -34,31 +32,31 @@ public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder
this.embed = embed ?? new EmbedBuilder();
}
public IEmbedBuilder WithDescription(string desc)
public EmbedBuilder WithDescription(string desc)
=> Wrap(embed.WithDescription(desc));
public IEmbedBuilder WithTitle(string title)
public EmbedBuilder WithTitle(string title)
=> Wrap(embed.WithTitle(title));
public IEmbedBuilder AddField(string title, object value, bool isInline = false)
public EmbedBuilder AddField(string title, object value, bool isInline = false)
=> Wrap(embed.AddField(title, value, isInline));
public IEmbedBuilder WithFooter(string text, string iconUrl = null)
public EmbedBuilder WithFooter(string text, string iconUrl = null)
=> Wrap(embed.WithFooter(text, iconUrl));
public IEmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null)
public EmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null)
=> Wrap(embed.WithAuthor(name, iconUrl, url));
public IEmbedBuilder WithUrl(string url)
public EmbedBuilder WithUrl(string url)
=> Wrap(embed.WithUrl(url));
public IEmbedBuilder WithImageUrl(string url)
public EmbedBuilder WithImageUrl(string url)
=> Wrap(embed.WithImageUrl(url));
public IEmbedBuilder WithThumbnailUrl(string url)
public EmbedBuilder WithThumbnailUrl(string url)
=> Wrap(embed.WithThumbnailUrl(url));
public IEmbedBuilder WithColor(EmbedColor color)
public EmbedBuilder WithColor(EmbedColor color)
=> color switch
{
EmbedColor.Ok => Wrap(embed.WithColor(_botConfig.Color.Ok.ToDiscordColor())),
@@ -67,15 +65,15 @@ public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder
_ => throw new ArgumentOutOfRangeException(nameof(color), "Unsupported EmbedColor type")
};
public IEmbedBuilder WithDiscordColor(Color color)
public EmbedBuilder WithDiscordColor(Color color)
=> Wrap(embed.WithColor(color));
public Embed Build()
=> embed.Build();
private IEmbedBuilder Wrap(EmbedBuilder eb)
private EmbedBuilder Wrap(EmbedBuilder eb)
{
embed = eb;
return this;
return eb;
}
}