Elimina la lógica de validación de URLs en la función 'extractValidLinks' para simplificar el manejo de enlaces y optimizar el rendimiento.
This commit is contained in:
@@ -74,48 +74,9 @@ export async function alliance(message: Message) {
|
|||||||
|
|
||||||
function extractValidLinks(content: string): string[] {
|
function extractValidLinks(content: string): string[] {
|
||||||
const matches = content.match(URL_REGEX);
|
const matches = content.match(URL_REGEX);
|
||||||
if (!matches) return [];
|
return matches || [];
|
||||||
|
|
||||||
const results: string[] = [];
|
|
||||||
for (const raw of matches) {
|
|
||||||
try {
|
|
||||||
const url = new URL(raw);
|
|
||||||
|
|
||||||
// Sólo http/https
|
|
||||||
if (url.protocol !== "http:" && url.protocol !== "https:") continue;
|
|
||||||
|
|
||||||
// Rechazar URLs con query string o fragment (ej: ?event=...)
|
|
||||||
if (url.search || url.hash) continue;
|
|
||||||
|
|
||||||
// Normalizar hostname y pathname
|
|
||||||
const host = url.hostname.toLowerCase();
|
|
||||||
const pathname = url.pathname.replace(/\/+/g, "/");
|
|
||||||
|
|
||||||
// Validar formatos de invitación de Discord estrictos
|
|
||||||
if (host === "discord.gg") {
|
|
||||||
// debe ser /<codigo>
|
|
||||||
if (!/^\/[A-Za-z0-9]+$/.test(pathname)) continue;
|
|
||||||
} else if (
|
|
||||||
host === "discord.com" ||
|
|
||||||
host === "www.discord.com" ||
|
|
||||||
host === "discordapp.com" ||
|
|
||||||
host === "www.discordapp.com"
|
|
||||||
) {
|
|
||||||
// debe ser /invite/<codigo>
|
|
||||||
if (!/^\/invite\/[A-Za-z0-9]+$/.test(pathname)) continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si llegó hasta aquí, es aceptable
|
|
||||||
results.push(url.toString());
|
|
||||||
} catch {
|
|
||||||
// ignorar coincidencias inválidas
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
// ...existing code...
|
|
||||||
function validateDiscordLinks(links: string[]): string[] {
|
function validateDiscordLinks(links: string[]): string[] {
|
||||||
return links.filter((link) => {
|
return links.filter((link) => {
|
||||||
return DISCORD_DOMAINS.some((domain) => link.includes(domain));
|
return DISCORD_DOMAINS.some((domain) => link.includes(domain));
|
||||||
@@ -600,7 +561,7 @@ async function processConfigVariables(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(config)) {
|
if (Array.isArray(config)) {
|
||||||
const processedArray: any[] = [];
|
const processedArray = [];
|
||||||
for (const item of config) {
|
for (const item of config) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
processedArray.push(
|
processedArray.push(
|
||||||
|
|||||||
Reference in New Issue
Block a user