From c90a5b4d0c8202fb1c9ba01715f75760d4f66951 Mon Sep 17 00:00:00 2001 From: Ryan de Jonge Date: Wed, 18 Oct 2023 23:33:06 +0200 Subject: [PATCH] Starboard fix fix fix fix fix --- ModCore/Listeners/StarboardListeners.cs | 37 ++++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/ModCore/Listeners/StarboardListeners.cs b/ModCore/Listeners/StarboardListeners.cs index 6ccb3aa..08ef1c6 100644 --- a/ModCore/Listeners/StarboardListeners.cs +++ b/ModCore/Listeners/StarboardListeners.cs @@ -514,7 +514,18 @@ private static DiscordMessageBuilder buildStarboardMessage(DiscordMessage source .WithFooter($"ID: {sourceMessage.Id}") .WithTimestamp(sourceMessage.Id); - var imageEmbeds = new List(); + var emotename = emoji.GetDiscordName().Replace(":", ""); + emotename = emotename.EndsWith('s') ? emotename : count > 1 ? emotename + "s" : emotename; + + if (sourceMessage.ReferencedMessage != null) + { + var refContent = sourceMessage.ReferencedMessage.Content.Truncate(200, "...").Replace(")[", "​)[") + " "; + + embed.Description += $"\n\n**➥** {sourceMessage.ReferencedMessage.Author.Mention}: " + + $"{refContent} {(sourceMessage.ReferencedMessage.Attachments.Count() > 0 ? $"_<{sourceMessage.ReferencedMessage.Attachments.Count()} file(s)>_" : "")}"; + } + + var embeds = new List(); var imageFiles = sourceMessage.Attachments.Where(x => { @@ -522,37 +533,23 @@ private static DiscordMessageBuilder buildStarboardMessage(DiscordMessage source return uri.IsFile && validFileExts.Contains(Path.GetExtension(uri.AbsolutePath)); }); - if(imageFiles.Any()) + if (imageFiles.Any()) { - embed = embed.WithUrl("https://github.com/Naamloos/ModCore").WithImageUrl(imageFiles.First().Url); - - foreach (var img in imageFiles.Skip(1)) + foreach (var img in imageFiles) { - imageEmbeds.Add(new DiscordEmbedBuilder(embed).WithUrl("https://github.com/Naamloos/ModCore").WithImageUrl(img.Url)); + embeds.Add(new DiscordEmbedBuilder(embed).WithUrl("https://github.com/Naamloos/ModCore").WithImageUrl(img.Url)); } } - - var emotename = emoji.GetDiscordName().Replace(":", ""); - emotename = emotename.EndsWith('s') ? emotename : count > 1 ? emotename + "s" : emotename; - - if (sourceMessage.ReferencedMessage != null) + else { - var refContent = sourceMessage.ReferencedMessage.Content.Truncate(200, "...").Replace(")[", "​)[") + " "; - - embed.Description += $"\n\n**➥** {sourceMessage.ReferencedMessage.Author.Mention}: " + - $"{refContent} {(sourceMessage.ReferencedMessage.Attachments.Count() > 0 ? $"_<{sourceMessage.ReferencedMessage.Attachments.Count()} file(s)>_" : "")}"; + embeds.Add(embed); } - var embeds = new List(); - embeds.Add(embed.Build()); - embeds.AddRange(imageEmbeds.Select(x => x.Build())); - var messageBuilder = new DiscordMessageBuilder() .AddEmbeds(embeds) .WithContent($"{emoji} {count} {emotename} in {sourceMessage.Channel.Mention}"); messageBuilder.AddComponents(new DiscordLinkButtonComponent(sourceMessage.JumpLink.ToString(), "Go to message")); - return messageBuilder; } }