Skip to content

Commit

Permalink
Small fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Feb 13, 2024
1 parent be76088 commit 5e3fcc5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ModCore/Listeners/EmbedMessageLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static async Task ReactionAddedAsync(MessageCreateEventArgs eventargs, Da

var embeds = new List<DiscordEmbed>();

foreach(Match match in matches)
foreach(Match match in matches.Take(10))
{
var guildId = ulong.Parse(match.Groups[1].Value);
var channelId = ulong.Parse(match.Groups[2].Value);
Expand All @@ -60,23 +60,30 @@ public static async Task ReactionAddedAsync(MessageCreateEventArgs eventargs, Da
var truncatedText = message.Content.Length > 250 ? message.Content.Truncate(250) + "..." : message.Content;
var embed = new DiscordEmbedBuilder()
.WithDescription($"{truncatedText}\n")
.WithAuthor(message.Author.GetDisplayUsername(), iconUrl: message.Author.GetAvatarUrl(ImageFormat.Png));
.WithAuthor(message.Author.GetDisplayUsername(), iconUrl: message.Author.GetAvatarUrl(ImageFormat.Gif));

var count = message.Attachments.Count();

var imageFiles = message.Attachments.Where(x =>
{
var uri = new Uri(x.Url);
return StarboardListeners.validFileExts.Contains(Path.GetExtension(uri.AbsolutePath));
});

var more = "";

if (imageFiles.Any())
{
embed.WithThumbnail(imageFiles.First().Url);
var count = imageFiles.Count();
if (count > 1)
{
embed.WithDescription(embed.Description + $"\n_Contains ({count - 1}) more attachments._");
}
count--;
more = " more";
}

if (count > 0)
{
embed.WithDescription(embed.Description + $"\n_Contains ({count}){more} attachments._");
}

embed.WithDescription(embed.Description + $"\n[Jump to message]({match.Value.Replace("!", "")})");

embeds.Add(embed.Build());
Expand Down

0 comments on commit 5e3fcc5

Please sign in to comment.