matt4499
matt4499
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
👍
15 replies
DIAdiscord.js - Imagine an app
Created by lua on 9/30/2024 in #djs-questions
Node.js host process becomes "locked up" / "clogged" for simple bot
function containsSupportedLink(message: Message): boolean {
const pattern = /https?:\/\/([\w.]+)((?:\/[^\s/#?]*)+)(\?[^\s#]*)?(#\S*)?/;
let result;

while ((result = pattern.exec(message.content)) !== null) {
let [_, host, path, query, fragment] = result;
host = host.toLowerCase();

if (host.endsWith('x.com') || host.endsWith('twitter.com')) {
if (/^\/\w+\/status\/\d+/i.test(path)) return true;
}

for (const domain of supportedMediaDomains) {
if (host.endsWith(domain) && hasSupportedExtension(path)) return true;
}

for (const domain of supportedDomains) {
if (host.endsWith(domain) && !/^\/*$/.test(path)) return true;
}
}

return false;
}
function containsSupportedLink(message: Message): boolean {
const pattern = /https?:\/\/([\w.]+)((?:\/[^\s/#?]*)+)(\?[^\s#]*)?(#\S*)?/;
let result;

while ((result = pattern.exec(message.content)) !== null) {
let [_, host, path, query, fragment] = result;
host = host.toLowerCase();

if (host.endsWith('x.com') || host.endsWith('twitter.com')) {
if (/^\/\w+\/status\/\d+/i.test(path)) return true;
}

for (const domain of supportedMediaDomains) {
if (host.endsWith(domain) && hasSupportedExtension(path)) return true;
}

for (const domain of supportedDomains) {
if (host.endsWith(domain) && !/^\/*$/.test(path)) return true;
}
}

return false;
}
15 replies