mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-02-07 19:06:24 +00:00
basic handling of github image links
This commit is contained in:
parent
96cee79f03
commit
835478d019
@ -14,6 +14,7 @@ namespace CompatBot.EventHandlers
|
||||
{
|
||||
private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture;
|
||||
public static readonly Regex IssueMention = new Regex(@"(?<issue_mention>\b(issue|pr|pull[ \-]request|bug)\s*#?\s*(?<number>\d+)|(?=\W|^)#(?<also_number>\d{4})|(https?://)github.com/RPCS3/rpcs3/(issues|pull)/(?<another_number>\d+))\b", DefaultOptions);
|
||||
public static readonly Regex ImageMarkup = new Regex(@"(?<img_markup>!\[(?<img_caption>[^\]]+)\]\((?<img_link>\w+://[^\)]+)\))", DefaultOptions);
|
||||
private static readonly Regex IssueLink = new Regex(@"github.com/RPCS3/rpcs3/issues/(?<number>\d+)", DefaultOptions);
|
||||
private static readonly GithubClient.Client Client = new GithubClient.Client();
|
||||
|
||||
|
@ -83,6 +83,25 @@ namespace CompatBot.Utils.ResultFormatters
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(desc)
|
||||
&& GithubLinksHandler.ImageMarkup.Matches(desc) is MatchCollection imgMatches
|
||||
&& imgMatches.Any())
|
||||
{
|
||||
var uniqueLinks = new HashSet<string>(10);
|
||||
foreach (Match m in imgMatches)
|
||||
{
|
||||
if (m.Groups["img_markup"]?.Value is string str
|
||||
&& !string.IsNullOrEmpty(str)
|
||||
&& uniqueLinks.Add(str))
|
||||
{
|
||||
var caption = m.Groups["img_caption"].Value;
|
||||
var link = m.Groups["img_link"].Value;
|
||||
if (!string.IsNullOrEmpty(caption))
|
||||
caption = " " + caption;
|
||||
desc = desc.Replace(str, $"[🖼{caption}]({link})");
|
||||
}
|
||||
}
|
||||
}
|
||||
desc = desc.Trim(EmbedPager.MaxDescriptionLength);
|
||||
builder ??= new DiscordEmbedBuilder {Title = prDesc, Url = url, Description = desc, Color = Config.Colors.DownloadLinks};
|
||||
var currentCommit = currentPrInfo?.MergeCommitSha;
|
||||
|
Loading…
x
Reference in New Issue
Block a user