Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix: link checker
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Jun 20, 2024
1 parent bd70f4f commit e4e891c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/links/checkLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExtendedClient } from '../interfaces/ExtendedClient';
import { errorHandler } from '../utils/errorHandler';

const allowedLinks = ['github.com', 'eddiejaoude.io', 'gitlab.com'];
const urlPattern = /(http|https):\/\/([\w-]+(\.[\w-]+)+)(\/[\w-./?%&=]*)?/;
const urlPattern = /(http|https):\/\/([\w-]+(\.[\w-]+)+)(\/[\w-./?%&=]*)?/g;

export const checkLinks = async (
bot: ExtendedClient,
Expand All @@ -18,13 +18,17 @@ export const checkLinks = async (
}

try {
const urlMatch = content?.match(urlPattern);
if (!urlMatch) {
const foundUrls = content?.match(urlPattern);
if (!foundUrls) {
return null;
}

if (urlMatch) {
if (allowedLinks.some((link) => urlMatch[0].includes(link))) {
if (foundUrls) {
if (
foundUrls.every((found) =>
allowedLinks.some((allowed) => found.includes(allowed)),
)
) {
return null;
}
}
Expand Down

0 comments on commit e4e891c

Please sign in to comment.