diff --git a/ModCore/Extensions/AsyncListenerExtension.cs b/ModCore/Extensions/AsyncListenerExtension.cs index 5b7f33e..678a12d 100644 --- a/ModCore/Extensions/AsyncListenerExtension.cs +++ b/ModCore/Extensions/AsyncListenerExtension.cs @@ -33,6 +33,11 @@ public void RegisterListeners(Assembly assembly) listener.Attribute.Register(this.client, listener.Method, this.services); } } + + public override void Dispose() + { + + } } class ListenerMethod diff --git a/ModCore/Listeners/StarboardListeners.cs b/ModCore/Listeners/StarboardListeners.cs index 106c260..0f09258 100644 --- a/ModCore/Listeners/StarboardListeners.cs +++ b/ModCore/Listeners/StarboardListeners.cs @@ -16,6 +16,9 @@ using ModCore.Extensions.Enums; using ModCore.Database.DatabaseEntities; using ModCore.Entities; +using System.IO; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; namespace ModCore.Listeners { @@ -500,6 +503,7 @@ private static async Task updateStarboardMessage(DatabaseContext database, Disco } } + private static readonly string[] validFileExts = { ".jpg", ".gif", ".png", ".jpeg", ".webp" }; private static DiscordMessageBuilder buildStarboardMessage(DiscordMessage sourceMessage, long count, DiscordEmoji emoji) { // TODO cleanup @@ -510,11 +514,18 @@ private static DiscordMessageBuilder buildStarboardMessage(DiscordMessage source .WithFooter($"ID: {sourceMessage.Id}") .WithTimestamp(sourceMessage.Id); - // This is shit code kek - if (sourceMessage.Attachments.Any(x => x.Url.ToLower().EndsWith(".jpg") || x.Url.ToLower().EndsWith(".png") - || x.Url.ToLower().EndsWith(".jpeg") || x.Url.ToLower().EndsWith(".gif"))) - embed.WithImageUrl(sourceMessage.Attachments.First(x => x.Url.ToLower().EndsWith(".jpg") || x.Url.ToLower().EndsWith(".png") - || x.Url.ToLower().EndsWith(".jpeg") || x.Url.ToLower().EndsWith(".gif")).Url); + var imageEmbeds = new List(); + + var imageFiles = sourceMessage.Attachments.Where(x => + { + var uri = new Uri(x.Url); + return uri.IsFile && validFileExts.Contains(Path.GetExtension(uri.AbsolutePath)); + }); + + foreach(var img in imageFiles) + { + imageEmbeds.Add(new DiscordEmbedBuilder().WithUrl(img.Url).WithImageUrl(img.Url)); + } var emotename = emoji.GetDiscordName().Replace(":", ""); emotename = emotename.EndsWith('s') ? emotename : count > 1 ? emotename + "s" : emotename; @@ -527,8 +538,9 @@ private static DiscordMessageBuilder buildStarboardMessage(DiscordMessage source $"{refContent} {(sourceMessage.ReferencedMessage.Attachments.Count() > 0 ? $"_<{sourceMessage.ReferencedMessage.Attachments.Count()} file(s)>_" : "")}"; } + imageEmbeds.Add(embed); var messageBuilder = new DiscordMessageBuilder() - .AddEmbed(embed) + .AddEmbeds(imageEmbeds.Select(x => x.Build())) .WithContent($"{emoji} {count} {emotename} in {sourceMessage.Channel.Mention}"); messageBuilder.AddComponents(new DiscordLinkButtonComponent(sourceMessage.JumpLink.ToString(), "Go to message")); diff --git a/ModCore/ModCore.csproj b/ModCore/ModCore.csproj index 2b2aa0b..b1a2e9c 100644 --- a/ModCore/ModCore.csproj +++ b/ModCore/ModCore.csproj @@ -14,11 +14,11 @@ - - - - - + + + + +