mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
Improve diff display for edited messages
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
63484ac353
commit
4595638cdb
2 changed files with 10 additions and 6 deletions
|
@ -1,6 +1,5 @@
|
||||||
using Boyfriend.Data;
|
using Boyfriend.Data;
|
||||||
using Boyfriend.Services.Data;
|
using Boyfriend.Services.Data;
|
||||||
using DiffPlex;
|
|
||||||
using DiffPlex.DiffBuilder;
|
using DiffPlex.DiffBuilder;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||||
|
@ -189,7 +188,7 @@ public class MessageEditedResponder : IResponder<IMessageUpdate> {
|
||||||
var currentUserResult = await _userApi.GetCurrentUserAsync(ct);
|
var currentUserResult = await _userApi.GetCurrentUserAsync(ct);
|
||||||
if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult);
|
if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult);
|
||||||
|
|
||||||
var diff = new SideBySideDiffBuilder(Differ.Instance).BuildDiffModel(message.Content, newContent, true, true);
|
var diff = InlineDiffBuilder.Diff(message.Content, newContent);
|
||||||
|
|
||||||
Messages.Culture = guildConfiguration.GetCulture();
|
Messages.Culture = guildConfiguration.GetCulture();
|
||||||
|
|
||||||
|
|
|
@ -122,11 +122,16 @@ public static class Extensions {
|
||||||
return WebUtility.UrlEncode(s).Replace('+', ' ');
|
return WebUtility.UrlEncode(s).Replace('+', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string AsMarkdown(this SideBySideDiffModel model) {
|
public static string AsMarkdown(this DiffPaneModel model) {
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
foreach (var line in model.OldText.Lines.Where(piece => !string.IsNullOrWhiteSpace(piece.Text)))
|
foreach (var line in model.Lines) {
|
||||||
builder.Append("-- ").AppendLine(line.Text);
|
if (line.Type is ChangeType.Deleted)
|
||||||
foreach (var line in model.NewText.Lines) builder.Append("++ ").AppendLine(line.Text);
|
builder.Append("-- ");
|
||||||
|
if (line.Type is ChangeType.Inserted)
|
||||||
|
builder.Append("++ ");
|
||||||
|
if (line.Type is not ChangeType.Imaginary)
|
||||||
|
builder.AppendLine(line.Text);
|
||||||
|
}
|
||||||
|
|
||||||
return Markdown.BlockCode(builder.ToString().SanitizeForBlockCode(), "diff");
|
return Markdown.BlockCode(builder.ToString().SanitizeForBlockCode(), "diff");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue