This repository has been archived on 2024-12-22. You can view files and clone it, but cannot push or open issues or pull requests.
elliebot/src/EllieBot/_common/Sender/MessageSenderService.cs

65 lines
2 KiB
C#
Raw Normal View History

2024-09-20 23:23:21 +12:00
namespace EllieBot.Extensions;
public sealed class MessageSenderService : IMessageSenderService, IEService
{
private readonly IBotStrings _bs;
private readonly BotConfigService _bcs;
private readonly DiscordSocketClient _client;
2024-11-28 01:06:01 +13:00
private readonly IGuildColorsService _gcs;
2024-09-20 23:23:21 +12:00
2024-11-28 01:06:01 +13:00
public MessageSenderService(
IBotStrings bs,
DiscordSocketClient client,
IGuildColorsService gcs,
BotConfigService bcs)
2024-09-20 23:23:21 +12:00
{
_bs = bs;
_client = client;
2024-11-28 01:06:01 +13:00
_gcs = gcs;
_bcs = bcs;
2024-09-20 23:23:21 +12:00
}
public ResponseBuilder Response(IMessageChannel channel)
=> new ResponseBuilder(_bs, this, _client)
2024-09-20 23:23:21 +12:00
.Channel(channel);
public ResponseBuilder Response(ICommandContext ctx)
=> new ResponseBuilder(_bs, this, _client)
2024-09-20 23:23:21 +12:00
.Context(ctx);
public ResponseBuilder Response(IUser user)
=> new ResponseBuilder(_bs, this, _client)
2024-09-20 23:23:21 +12:00
.User(user);
public ResponseBuilder Response(SocketMessageComponent smc)
=> new ResponseBuilder(_bs, this, _client)
2024-09-20 23:23:21 +12:00
.Channel(smc.Channel);
2024-11-28 01:06:01 +13:00
public EllieEmbedBuilder CreateEmbed(ulong? guildId = null)
=> new EllieEmbedBuilder(_bcs, guildId is { } gid ? _gcs.GetColors(gid) : null);
2024-09-20 23:23:21 +12:00
}
public class EllieEmbedBuilder : EmbedBuilder
{
2024-11-28 01:06:01 +13:00
private readonly Color _okColor;
private readonly Color _errorColor;
private readonly Color _pendingColor;
2024-09-20 23:23:21 +12:00
2024-11-28 01:06:01 +13:00
public EllieEmbedBuilder(BotConfigService bcsData, Colors? guildColors = null)
2024-09-20 23:23:21 +12:00
{
2024-11-28 01:06:01 +13:00
var bcColors = bcsData.Data.Color;
_okColor = guildColors?.Ok ?? bcColors.Ok.ToDiscordColor();
_errorColor = guildColors?.Error ?? bcColors.Error.ToDiscordColor();
_pendingColor = guildColors?.Warn ?? bcColors.Pending.ToDiscordColor();
2024-09-20 23:23:21 +12:00
}
public EmbedBuilder WithOkColor()
2024-11-28 01:06:01 +13:00
=> WithColor(_okColor);
2024-09-20 23:23:21 +12:00
public EmbedBuilder WithErrorColor()
2024-11-28 01:06:01 +13:00
=> WithColor(_errorColor);
2024-09-20 23:23:21 +12:00
public EmbedBuilder WithPendingColor()
2024-11-28 01:06:01 +13:00
=> WithColor(_pendingColor);
2024-09-20 23:23:21 +12:00
}