mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix(bot): remove absurdly long links from reply embeds
This commit is contained in:
parent
46777c2e4d
commit
97e7df5e4d
1 changed files with 10 additions and 4 deletions
|
|
@ -35,6 +35,8 @@ public class ProxyService
|
|||
private readonly WebhookExecutorService _webhookExecutor;
|
||||
private readonly NodaTime.IClock _clock;
|
||||
|
||||
private static readonly string URL_REGEX = @"(http|https)(:\/\/)?(www\.)?([-a-zA-Z0-9@:%._\+~#=]{1,256})?\.?([a-zA-Z0-9()]{1,6})?\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$";
|
||||
|
||||
public ProxyService(LogChannelService logChannel, ILogger logger, WebhookExecutorService webhookExecutor,
|
||||
DispatchService dispatch, IDatabase db, RedisService redis, ProxyMatcher matcher, IMetrics metrics, ModelRepository repo,
|
||||
NodaTime.IClock clock, IDiscordCache cache, DiscordApiClient rest, LastMessageCacheService lastMessage)
|
||||
|
|
@ -384,12 +386,16 @@ public class ProxyService
|
|||
msg += mentionTail + ">";
|
||||
}
|
||||
|
||||
var endsWithUrl = Regex.IsMatch(msg,
|
||||
@"(http|https)(:\/\/)?(www\.)?([-a-zA-Z0-9@:%._\+~#=]{1,256})?\.?([a-zA-Z0-9()]{1,6})?\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$");
|
||||
var endsWithUrl = Regex.IsMatch(msg, URL_REGEX);
|
||||
if (endsWithUrl)
|
||||
{
|
||||
var urlTail = repliedTo.Content.Substring(100).Split(" ")[0];
|
||||
msg += urlTail + " ";
|
||||
msg += repliedTo.Content.Substring(100).Split(" ")[0];
|
||||
|
||||
// replace the entire URL with a placeholder if it's *too* long
|
||||
if (msg.Length > 300)
|
||||
msg = Regex.Replace(msg, URL_REGEX, $"*[(very long link removed, click to see original message)]({jumpLink})*");
|
||||
|
||||
msg += " ";
|
||||
}
|
||||
|
||||
var spoilersInOriginalString = Regex.Matches(repliedTo.Content, @"\|\|").Count;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue