mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-02 03:59:53 +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:
parent
d5c4340210
commit
04897cab20
12 changed files with 1054 additions and 1010 deletions
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -152,10 +152,9 @@ 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(
|
||||
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until))).ToString();
|
||||
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(
|
||||
data.Settings, channelId, user, title, description, target, ColorsList.Red, ct: ct);
|
||||
|
@ -211,10 +210,9 @@ 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(
|
||||
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until))).ToString();
|
||||
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(
|
||||
data.Settings, channelId, user, title, description, target, ColorsList.Red, ct: ct);
|
||||
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
40
src/Messages.Designer.cs
generated
40
src/Messages.Designer.cs
generated
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue