bot: move log channel embed to embed service

This commit is contained in:
Ske 2019-04-22 17:10:18 +02:00
parent 467719283f
commit 21b16667df
2 changed files with 15 additions and 8 deletions

View File

@ -13,7 +13,7 @@ namespace PluralKit.Bot {
this._client = client;
}
public async Task<Embed> CreateEmbed(PKSystem system) {
public async Task<Embed> CreateSystemEmbed(PKSystem system) {
var accounts = await _systems.GetLinkedAccountIds(system);
// Fetch/render info for all accounts simultaneously
@ -31,5 +31,15 @@ namespace PluralKit.Bot {
// TODO: fronter
return eb.Build();
}
public Embed CreateLoggedMessageEmbed(PKSystem system, PKMember member, IMessage message, IUser sender) {
// TODO: pronouns in ?-reacted response using this card
return new EmbedBuilder()
.WithAuthor($"#{message.Channel.Name}: {member.Name}", member.AvatarUrl)
.WithDescription(message.Content)
.WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Sender: ${sender.Username}#{sender.Discriminator} ({sender.Id}) | Message ID: ${message.Id}")
.WithTimestamp(message.Timestamp)
.Build();
}
}
}

View File

@ -12,23 +12,20 @@ namespace PluralKit.Bot {
class LogChannelService {
private IDiscordClient _client;
private IDbConnection _connection;
private EmbedService _embed;
public LogChannelService(IDiscordClient client, IDbConnection connection)
public LogChannelService(IDiscordClient client, IDbConnection connection, EmbedService embed)
{
this._client = client;
this._connection = connection;
this._embed = embed;
}
public async Task LogMessage(PKSystem system, PKMember member, IMessage message, IUser sender) {
var channel = await GetLogChannel((message.Channel as IGuildChannel).Guild);
if (channel == null) return;
var embed = new EmbedBuilder()
.WithAuthor($"#{message.Channel.Name}: {member.Name}", member.AvatarUrl)
.WithDescription(message.Content)
.WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Sender: ${sender.Username}#{sender.Discriminator} ({sender.Id}) | Message ID: ${message.Id}")
.WithTimestamp(message.Timestamp)
.Build();
var embed = _embed.CreateLoggedMessageEmbed(system, member, message, sender);
await channel.SendMessageAsync(text: message.GetJumpUrl(), embed: embed);
}