1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

Redesign embeds (#123)

TODO before merging:

- [x] /about
- [x] /ban
- [x] /unban
- [x] /kick
- [x] /mute
- [x] /unmute
- [x] /remind
- [x] /listremind
- [x] MessageEditedResponder
- [x] MessageDeletedResponder

---------

Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
Macintxsh 2023-09-29 18:36:16 +03:00 committed by GitHub
parent d5c4340210
commit 04897cab20
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 1054 additions and 1010 deletions

View file

@ -47,9 +47,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root" xmlns="">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
@ -102,14 +100,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </value>
</resheader>
<data name="Ready" xml:space="preserve">
<value>I'm ready!</value>
@ -461,9 +455,6 @@
</data>
<data name="MissingReminderText" xml:space="preserve">
<value>You need to specify reminder text!</value>
</data>
<data name="DescriptionReminderCreated" xml:space="preserve">
<value>OK, I'll mention you on {0}</value>
</data>
<data name="InvalidRemindIn" xml:space="preserve">
<value>You need to specify when I should send you the reminder!</value>
@ -528,14 +519,14 @@
<data name="AboutTitleDevelopers" xml:space="preserve">
<value>Developers:</value>
</data>
<data name="AboutTitleWiki" xml:space="preserve">
<value>Boyfriend's Wiki Page:</value>
<data name="AboutTitleRepository" xml:space="preserve">
<value>Boyfriend's source code</value>
</data>
<data name="AboutBot" xml:space="preserve">
<value>About Boyfriend</value>
</data>
<data name="AboutDeveloper@mctaylors" xml:space="preserve">
<value>logo and embed designer, Boyfriend's Wiki creator</value>
<value>developer &amp; designer, Boyfriend's Wiki creator</value>
</data>
<data name="AboutDeveloper@Octol1ttle" xml:space="preserve">
<value>main developer</value>
@ -600,6 +591,21 @@
<data name="AllSettingsReset" xml:space="preserve">
<value>All settings have been reset</value>
</data>
<data name="DescriptionActionJumpToMessage" xml:space="preserve">
<value>Jump to message: {0}</value>
</data>
<data name="DescriptionActionJumpToChannel" xml:space="preserve">
<value>Jump to channel: {0}</value>
</data>
<data name="ReminderIndex" xml:space="preserve">
<value>Index: {0}</value>
</data>
<data name="ReminderWillBeSentOn" xml:space="preserve">
<value>The reminder will be sent on: {0}</value>
</data>
<data name="ReminderText" xml:space="preserve">
<value>Reminder text: {0}</value>
</data>
<data name="ShowInfoDisplayName" xml:space="preserve">
<value>Display name</value>
</data>

View file

@ -47,9 +47,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root" xmlns="">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
@ -102,14 +100,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </value>
</resheader>
<data name="Ready" xml:space="preserve">
<value>Я запустился!</value>
@ -458,9 +452,6 @@
</data>
<data name="MissingReminderText" xml:space="preserve">
<value>Тебе нужно указать текст напоминания!</value>
</data>
<data name="DescriptionReminderCreated" xml:space="preserve">
<value>Хорошо, я упомяну тебя {0}</value>
</data>
<data name="InvalidRemindIn" xml:space="preserve">
<value>Нужно указать время, через которое придёт напоминание!</value>
@ -528,20 +519,20 @@
<data name="AboutTitleDevelopers" xml:space="preserve">
<value>Разработчики:</value>
</data>
<data name="AboutTitleWiki" xml:space="preserve">
<value>Страница Boyfriend's Wiki:</value>
<data name="AboutTitleRepository" xml:space="preserve">
<value>Исходный код Boyfriend</value>
</data>
<data name="AboutBot" xml:space="preserve">
<value>О Boyfriend</value>
</data>
<data name="AboutDeveloper@neroduckale" xml:space="preserve">
<value>разрабочик</value>
<value>разработчик</value>
</data>
<data name="AboutDeveloper@Octol1ttle" xml:space="preserve">
<value>основной разработчик</value>
</data>
<data name="AboutDeveloper@mctaylors" xml:space="preserve">
<value>дизайнер лого и эмбедов, создатель Boyfriend's Wiki</value>
<value>разработчик и дизайнер, создатель Boyfriend's Wiki</value>
</data>
<data name="ReminderCreated" xml:space="preserve">
<value>Напоминание для {0} создано</value>
@ -600,6 +591,21 @@
<data name="AllSettingsReset" xml:space="preserve">
<value>Все настройки были сброшены</value>
</data>
<data name="DescriptionActionJumpToMessage" xml:space="preserve">
<value>Перейти к сообщению: {0}</value>
</data>
<data name="DescriptionActionJumpToChannel" xml:space="preserve">
<value>Перейти к каналу: {0}</value>
</data>
<data name="ReminderIndex" xml:space="preserve">
<value>Индекс: {0}</value>
</data>
<data name="ReminderWillBeSentOn" xml:space="preserve">
<value>Напоминание будет отправлено: {0}</value>
</data>
<data name="ReminderText" xml:space="preserve">
<value>Текст напоминалки: {0}</value>
</data>
<data name="ShowInfoDisplayName" xml:space="preserve">
<value>Отображаемое имя</value>
</data>

View file

@ -47,9 +47,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root" xmlns="">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
@ -102,14 +100,10 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 </value>
</resheader>
<data name="Ready" xml:space="preserve">
<value>я родился!</value>
@ -461,9 +455,6 @@
</data>
<data name="MissingReminderText" xml:space="preserve">
<value>для крафта напоминалки нужен текст</value>
</data>
<data name="DescriptionReminderCreated" xml:space="preserve">
<value>вас понял, упоминание будет {0}</value>
</data>
<data name="InvalidRemindIn" xml:space="preserve">
<value>шизоид у меня на часах такого нету</value>
@ -528,14 +519,14 @@
<data name="AboutTitleDevelopers" xml:space="preserve">
<value>девелоперы:</value>
</data>
<data name="AboutTitleWiki" xml:space="preserve">
<value>страничка Boyfriend's Wiki:</value>
<data name="AboutTitleRepository" xml:space="preserve">
<value>репа Boyfriend (тык)</value>
</data>
<data name="AboutBot" xml:space="preserve">
<value>немного о Boyfriend</value>
</data>
<data name="AboutDeveloper@mctaylors" xml:space="preserve">
<value>скучный лого/эмбед дизайнер создавший Boyfriend's Wiki</value>
<value>скучный девелопер + дизайнер создавший Boyfriend's Wiki</value>
</data>
<data name="AboutDeveloper@neroduckale" xml:space="preserve">
<value>ВАЖНЫЙ соучастник кодинг-стримов @Octol1ttle</value>
@ -600,6 +591,21 @@
<data name="AllSettingsReset" xml:space="preserve">
<value>откатываемся к заводским...</value>
</data>
<data name="DescriptionActionJumpToMessage" xml:space="preserve">
<value>чекнуть сообщение: {0}</value>
</data>
<data name="DescriptionActionJumpToChannel" xml:space="preserve">
<value>чекнуть канал: {0}</value>
</data>
<data name="ReminderIndex" xml:space="preserve">
<value>индекс: {0}</value>
</data>
<data name="ReminderWillBeSentOn" xml:space="preserve">
<value>я пну тебе это: {0}</value>
</data>
<data name="ReminderText" xml:space="preserve">
<value>че там в напоминалке: {0}</value>
</data>
<data name="ShowInfoDisplayName" xml:space="preserve">
<value>дисплейнейм</value>
</data>

View file

@ -12,7 +12,7 @@ using Remora.Discord.Commands.Conditions;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Extensions.Embeds;
using Remora.Discord.Extensions.Formatting;
using Remora.Rest.Core;
using Remora.Results;
namespace Boyfriend.Commands;
@ -23,20 +23,29 @@ namespace Boyfriend.Commands;
[UsedImplicitly]
public class AboutCommandGroup : CommandGroup
{
private static readonly string[] Developers = { "Octol1ttle", "mctaylors", "neroduckale" };
private static readonly (string Username, Snowflake Id)[] Developers =
{
("Octol1ttle", new Snowflake(504343489664909322)),
("mctaylors", new Snowflake(326642240229474304)),
("neroduckale", new Snowflake(474943797063843851))
};
private readonly ICommandContext _context;
private readonly FeedbackService _feedback;
private readonly GuildDataService _guildData;
private readonly IDiscordRestUserAPI _userApi;
private readonly IDiscordRestGuildAPI _guildApi;
public AboutCommandGroup(
ICommandContext context, GuildDataService guildData,
FeedbackService feedback, IDiscordRestUserAPI userApi)
FeedbackService feedback, IDiscordRestUserAPI userApi,
IDiscordRestGuildAPI guildApi)
{
_context = context;
_guildData = guildData;
_feedback = feedback;
_userApi = userApi;
_guildApi = guildApi;
}
/// <summary>
@ -66,20 +75,22 @@ public class AboutCommandGroup : CommandGroup
var cfg = await _guildData.GetSettings(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(cfg);
return await SendAboutBotAsync(currentUser, CancellationToken);
return await SendAboutBotAsync(currentUser, guildId, CancellationToken);
}
private async Task<Result> SendAboutBotAsync(IUser currentUser, CancellationToken ct = default)
private async Task<Result> SendAboutBotAsync(IUser currentUser, Snowflake guildId, CancellationToken ct = default)
{
var builder = new StringBuilder().AppendLine(Markdown.Bold(Messages.AboutTitleDevelopers));
var builder = new StringBuilder().Append("### ").AppendLine(Messages.AboutTitleDevelopers);
foreach (var dev in Developers)
{
builder.AppendLine($"@{dev} — {$"AboutDeveloper@{dev}".Localized()}");
var guildMemberResult = await _guildApi.GetGuildMemberAsync(
guildId, dev.Id, ct);
var tag = guildMemberResult.IsSuccess ? $"<@{dev.Id}>" : $"@{dev.Username}";
builder.AppendLine($"- {tag} — {$"AboutDeveloper@{dev.Username}".Localized()}");
}
builder.AppendLine()
.AppendLine(Markdown.Bold(Messages.AboutTitleWiki))
.AppendLine("https://github.com/LabsDevelopment/Boyfriend/wiki");
builder.Append($"### [{Messages.AboutTitleRepository}](https://github.com/LabsDevelopment/Boyfriend)");
var embed = new EmbedBuilder().WithSmallTitle(Messages.AboutBot, currentUser)
.WithDescription(builder.ToString())

View file

@ -133,10 +133,11 @@ public class BanCommandGroup : CommandGroup
return await _feedback.SendContextualEmbedResultAsync(errorEmbed, ct);
}
var builder = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason));
var builder = new StringBuilder().Append("- ")
.AppendLine(string.Format(Messages.DescriptionActionReason, reason));
if (duration is not null)
{
builder.Append(
builder.Append("- ").Append(
string.Format(
Messages.DescriptionActionExpiresAt,
Markdown.Timestamp(DateTimeOffset.UtcNow.Add(duration.Value))));
@ -271,9 +272,10 @@ public class BanCommandGroup : CommandGroup
.WithColour(ColorsList.Green).Build();
var title = string.Format(Messages.UserUnbanned, target.GetTag());
var description = string.Format(Messages.DescriptionActionReason, reason);
var description = new StringBuilder().Append("- ")
.Append(string.Format(Messages.DescriptionActionReason, reason));
var logResult = _utility.LogActionAsync(
data.Settings, channelId, user, title, description, target, ColorsList.Green, ct: ct);
data.Settings, channelId, user, title, description.ToString(), target, ColorsList.Green, ct: ct);
if (!logResult.IsSuccess)
{
return Result.FromError(logResult.Error);

View file

@ -131,7 +131,7 @@ public class KickCommandGroup : CommandGroup
{
var dmEmbed = new EmbedBuilder().WithGuildTitle(guild)
.WithTitle(Messages.YouWereKicked)
.WithDescription(string.Format(Messages.DescriptionActionReason, reason))
.WithDescription($"- {string.Format(Messages.DescriptionActionReason, reason)}")
.WithActionFooter(user)
.WithCurrentTimestamp()
.WithColour(ColorsList.Red)
@ -156,7 +156,7 @@ public class KickCommandGroup : CommandGroup
data.GetOrCreateMemberData(target.ID).Roles.Clear();
var title = string.Format(Messages.UserKicked, target.GetTag());
var description = string.Format(Messages.DescriptionActionReason, reason);
var description = $"- {string.Format(Messages.DescriptionActionReason, reason)}";
var logResult = _utility.LogActionAsync(
data.Settings, channelId, user, title, description, target, ColorsList.Red, ct: ct);
if (!logResult.IsSuccess)

View file

@ -152,9 +152,8 @@ public class MuteCommandGroup : CommandGroup
}
var title = string.Format(Messages.UserMuted, target.GetTag());
var description = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason))
.Append(
string.Format(
var description = new StringBuilder().Append("- ").AppendLine(string.Format(Messages.DescriptionActionReason, reason))
.Append("- ").Append(string.Format(
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until))).ToString();
var logResult = _utility.LogActionAsync(
@ -211,9 +210,8 @@ public class MuteCommandGroup : CommandGroup
}
var title = string.Format(Messages.UserMuted, target.GetTag());
var description = new StringBuilder().AppendLine(string.Format(Messages.DescriptionActionReason, reason))
.Append(
string.Format(
var description = new StringBuilder().Append("- ").AppendLine(string.Format(Messages.DescriptionActionReason, reason))
.Append("- ").Append(string.Format(
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until))).ToString();
var logResult = _utility.LogActionAsync(
@ -328,7 +326,7 @@ public class MuteCommandGroup : CommandGroup
}
var title = string.Format(Messages.UserUnmuted, target.GetTag());
var description = string.Format(Messages.DescriptionActionReason, reason);
var description = $"- {string.Format(Messages.DescriptionActionReason, reason)}";
var logResult = _utility.LogActionAsync(
data.Settings, channelId, user, title, description, target, ColorsList.Green, ct: ct);
if (!logResult.IsSuccess)
@ -372,7 +370,7 @@ public class MuteCommandGroup : CommandGroup
}
var title = string.Format(Messages.UserUnmuted, target.GetTag());
var description = string.Format(Messages.DescriptionActionReason, reason);
var description = $"- {string.Format(Messages.DescriptionActionReason, reason)}";
var logResult = _utility.LogActionAsync(
data.Settings, channelId, user, title, description, target, ColorsList.Green, ct: ct);
if (!logResult.IsSuccess)

View file

@ -19,7 +19,7 @@ using Remora.Results;
namespace Boyfriend.Commands;
/// <summary>
/// Handles the command to manage reminders: /remind
/// Handles commands to manage reminders: /remind, /listremind, /delremind
/// </summary>
[UsedImplicitly]
public class RemindCommandGroup : CommandGroup
@ -88,8 +88,9 @@ public class RemindCommandGroup : CommandGroup
for (var i = data.Reminders.Count - 1; i >= 0; i--)
{
var reminder = data.Reminders[i];
builder.AppendLine(
$"- {Markdown.InlineCode(i.ToString())} - {Markdown.InlineCode(reminder.Text)} - {Markdown.Timestamp(reminder.At)}");
builder.Append("- ").AppendLine(string.Format(Messages.ReminderIndex, Markdown.InlineCode(i.ToString())))
.Append(" - ").AppendLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text)))
.Append(" - ").AppendLine(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(reminder.At)));
}
var embed = new EmbedBuilder().WithSmallTitle(
@ -149,8 +150,13 @@ public class RemindCommandGroup : CommandGroup
Text = message
});
var embed = new EmbedBuilder().WithSmallTitle(string.Format(Messages.ReminderCreated, user.GetTag()), user)
.WithDescription(string.Format(Messages.DescriptionReminderCreated, Markdown.Timestamp(remindAt)))
var builder = new StringBuilder().Append("- ").AppendLine(string.Format(
Messages.ReminderText, Markdown.InlineCode(message)))
.Append("- ").Append(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(remindAt)));
var embed = new EmbedBuilder().WithSmallTitle(
string.Format(Messages.ReminderCreated, user.GetTag()), user)
.WithDescription(builder.ToString())
.WithColour(ColorsList.Green)
.Build();

View file

@ -17,22 +17,6 @@ namespace Boyfriend;
public static class Extensions
{
/// <summary>
/// Adds a footer with the <paramref name="user" />'s avatar and tag (@username or username#0000).
/// </summary>
/// <param name="builder">The builder to add the footer to.</param>
/// <param name="user">The user whose tag and avatar to add.</param>
/// <returns>The builder with the added footer.</returns>
public static EmbedBuilder WithUserFooter(this EmbedBuilder builder, IUser user)
{
var avatarUrlResult = CDN.GetUserAvatarUrl(user, imageSize: 256);
var avatarUrl = avatarUrlResult.IsSuccess
? avatarUrlResult.Entity.AbsoluteUri
: CDN.GetDefaultUserAvatarUrl(user, imageSize: 256).Entity.AbsoluteUri;
return builder.WithFooter(new EmbedFooter(user.GetTag(), avatarUrl));
}
/// <summary>
/// Adds a footer representing that an action was performed by a <paramref name="user" />.
/// </summary>

View file

@ -744,12 +744,6 @@ namespace Boyfriend {
}
}
internal static string DescriptionReminderCreated {
get {
return ResourceManager.GetString("DescriptionReminderCreated", resourceCulture);
}
}
internal static string InvalidRemindIn {
get {
return ResourceManager.GetString("InvalidRemindIn", resourceCulture);
@ -876,9 +870,9 @@ namespace Boyfriend {
}
}
internal static string AboutTitleWiki {
internal static string AboutTitleRepository {
get {
return ResourceManager.GetString("AboutTitleWiki", resourceCulture);
return ResourceManager.GetString("AboutTitleRepository", resourceCulture);
}
}
@ -1014,6 +1008,36 @@ namespace Boyfriend {
}
}
internal static string DescriptionActionJumpToMessage {
get {
return ResourceManager.GetString("DescriptionActionJumpToMessage", resourceCulture);
}
}
internal static string DescriptionActionJumpToChannel {
get {
return ResourceManager.GetString("DescriptionActionJumpToChannel", resourceCulture);
}
}
internal static string ReminderIndex {
get {
return ResourceManager.GetString("ReminderIndex", resourceCulture);
}
}
internal static string ReminderWillBeSentOn {
get {
return ResourceManager.GetString("ReminderWillBeSentOn", resourceCulture);
}
}
internal static string ReminderText {
get {
return ResourceManager.GetString("ReminderText", resourceCulture);
}
}
internal static string ShowInfoTitle {
get {
return ResourceManager.GetString("ShowInfoTitle", resourceCulture);

View file

@ -1,3 +1,4 @@
using System.Text;
using Boyfriend.Data;
using Boyfriend.Services;
using JetBrains.Annotations;
@ -81,13 +82,17 @@ public class MessageDeletedResponder : IResponder<IMessageDelete>
Messages.Culture = GuildSettings.Language.Get(cfg);
var builder = new StringBuilder().AppendLine(
string.Format(Messages.DescriptionActionJumpToChannel,
Mention.Channel(gatewayEvent.ChannelID)))
.AppendLine(message.Content.InBlockCode());
var embed = new EmbedBuilder()
.WithSmallTitle(
string.Format(
Messages.CachedMessageDeleted,
message.Author.GetTag()), message.Author)
.WithDescription(
$"{Mention.Channel(gatewayEvent.ChannelID)}\n{message.Content.InBlockCode()}")
.WithDescription(builder.ToString())
.WithActionFooter(user)
.WithTimestamp(message.Timestamp)
.WithColour(ColorsList.Red)

View file

@ -1,3 +1,4 @@
using System.Text;
using Boyfriend.Data;
using Boyfriend.Services;
using DiffPlex.DiffBuilder;
@ -23,16 +24,13 @@ public class MessageEditedResponder : IResponder<IMessageUpdate>
private readonly CacheService _cacheService;
private readonly IDiscordRestChannelAPI _channelApi;
private readonly GuildDataService _guildData;
private readonly IDiscordRestUserAPI _userApi;
public MessageEditedResponder(
CacheService cacheService, IDiscordRestChannelAPI channelApi, GuildDataService guildData,
IDiscordRestUserAPI userApi)
CacheService cacheService, IDiscordRestChannelAPI channelApi, GuildDataService guildData)
{
_cacheService = cacheService;
_channelApi = channelApi;
_guildData = guildData;
_userApi = userApi;
}
public async Task<Result> RespondAsync(IMessageUpdate gatewayEvent, CancellationToken ct = default)
@ -92,20 +90,18 @@ public class MessageEditedResponder : IResponder<IMessageUpdate>
// NOTE: Awaiting this might not even solve this if the same responder is called asynchronously
_ = _channelApi.GetChannelMessageAsync(channelId, messageId, ct);
var currentUserResult = await _userApi.GetCurrentUserAsync(ct);
if (!currentUserResult.IsDefined(out var currentUser))
{
return Result.FromError(currentUserResult);
}
var diff = InlineDiffBuilder.Diff(message.Content, newContent);
Messages.Culture = GuildSettings.Language.Get(cfg);
var builder = new StringBuilder().AppendLine(
string.Format(Messages.DescriptionActionJumpToMessage,
$"https://discord.com/channels/{guildId}/{channelId}/{messageId}"))
.AppendLine(diff.AsMarkdown());
var embed = new EmbedBuilder()
.WithSmallTitle(string.Format(Messages.CachedMessageEdited, message.Author.GetTag()), message.Author)
.WithDescription($"https://discord.com/channels/{guildId}/{channelId}/{messageId}\n{diff.AsMarkdown()}")
.WithUserFooter(currentUser)
.WithDescription(builder.ToString())
.WithTimestamp(timestamp.Value)
.WithColour(ColorsList.Yellow)
.Build();