Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit 0ecca67

Browse files
Merge pull request #81 from InfinityGhost/bugfix/discord-api/embed-character-limit
Add character limit to GitHub embed description
2 parents 61828f4 + d9e0718 commit 0ecca67

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

TabletBot.Discord/Embeds/GitHubEmbeds.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Discord;
45
using Octokit;
@@ -15,7 +16,7 @@ public static EmbedBuilder GetEmbed(Issue? issue)
1516
{
1617
if (issue == null)
1718
{
18-
return new EmbedBuilder()
19+
return new EmbedBuilder
1920
{
2021
Color = CLOSED_COLOR,
2122
Description = "No issue or pull request was found."
@@ -26,7 +27,7 @@ public static EmbedBuilder GetEmbed(Issue? issue)
2627
{
2728
Title = $"{issue.Title} #{issue.Number}",
2829
Url = issue.HtmlUrl,
29-
Description = issue.Body ?? string.Empty,
30+
Description = LimitLength(issue.Body, 750),
3031
Color = GetColor(issue),
3132
Fields = GetFields(issue).ToList(),
3233
Author = new EmbedAuthorBuilder
@@ -71,5 +72,13 @@ private static IEnumerable<EmbedFieldBuilder> GetFields(Issue issue)
7172
};
7273
}
7374
}
75+
76+
private static string LimitLength(string? str, int characterLimit)
77+
{
78+
if (string.IsNullOrWhiteSpace(str))
79+
return string.Empty;
80+
81+
return str.Length > characterLimit ? str[..(characterLimit-3)] + "..." : str;
82+
}
7483
}
7584
}

0 commit comments

Comments
 (0)