3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

Automod: add include_words/exclude_words and include_regex/exclude_regex to match_links trigger

This commit is contained in:
Dragory 2020-04-11 16:56:55 +03:00
parent e67816ec7b
commit b30df3f8d4
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 57 additions and 13 deletions

View file

@ -390,18 +390,21 @@ export async function findRelevantAuditLogEntry(
const urlRegex = /(\S+\.\S+)/g;
const protocolRegex = /^[a-z]+:\/\//;
export function getUrlsInString(str: string, unique = false): url.URL[] {
interface MatchedURL extends url.URL {
input: string;
}
export function getUrlsInString(str: string, unique = false): MatchedURL[] {
let matches = str.match(urlRegex) || [];
if (unique) matches = Array.from(new Set(matches));
return matches.reduce((urls, match) => {
if (!protocolRegex.test(match)) {
match = `https://${match}`;
}
const withProtocol = protocolRegex.test(match) ? match : `https://${match}`;
let matchUrl: url.URL;
let matchUrl: MatchedURL;
try {
matchUrl = new url.URL(match);
matchUrl = new url.URL(withProtocol) as MatchedURL;
matchUrl.input = match;
} catch (e) {
return urls;
}