From 2b65793903c110c389cee871f39c43606c576343 Mon Sep 17 00:00:00 2001 From: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:26:50 -0400 Subject: [PATCH] Disable logging on md5 404's --- src/events/handle-message.ts | 4 ++-- src/utils/e621-utils.ts | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/events/handle-message.ts b/src/events/handle-message.ts index 92cb60c..546bed0 100644 --- a/src/events/handle-message.ts +++ b/src/events/handle-message.ts @@ -98,7 +98,7 @@ export async function handleMessageCreate(message: Message) { if (md5s.length == 0) continue; for (const md5 of md5s) { - const post = await getE621PostByMd5(md5); + const post = await getE621PostByMd5(md5, false); if (post) { if (await blacklistIfNecessary(message, [post])) return; @@ -377,7 +377,7 @@ async function imageHandler(message: Message, matchedGroups: RegExpExecArray[]): for (const match of matchedGroups) { try { - const post = await getE621PostByMd5(match[1]); + const post = await getE621PostByMd5(match[1], false); if (post) posts.push(post); } catch (e) { console.error(e); diff --git a/src/utils/e621-utils.ts b/src/utils/e621-utils.ts index 8899da3..f5502b0 100644 --- a/src/utils/e621-utils.ts +++ b/src/utils/e621-utils.ts @@ -28,7 +28,7 @@ if (secure && existsSync('./certs/cert.pem') && existsSync('./certs/cert.pem')) }); } -async function request(path: string, query?: { [name: string]: string }): Promise { +async function request(path: string, query?: { [name: string]: string }, logErrors = true): Promise { const url = new URL(config.E621_BASE_URL!); url.pathname = path + '.json'; @@ -47,7 +47,7 @@ async function request(path: string, query?: { [name: string]: string }): Promis } }, (res) => { if (res.statusCode! < 200 || res.statusCode! >= 300) { - console.error(`[E621 Requester] Received status code ${res.statusCode} while requesting: ${url}`); + if (logErrors) console.error(`[E621 Requester] Received status code ${res.statusCode} while requesting: ${url}`); res.resume(); return resolve(null); } @@ -64,14 +64,18 @@ async function request(path: string, query?: { [name: string]: string }): Promis try { resolve(JSON.parse(data)); } catch (e) { - console.error('[E621 Requester] Error parsing JSON from:'); - console.error(data); + if (logErrors) { + console.error('[E621 Requester] Error parsing JSON from:'); + console.error(data); + } resolve(null); } }); }).on('error', (e) => { - console.error('[E621 Requester] Error fetching:'); - console.error(e); + if (logErrors) { + console.error('[E621 Requester] Error fetching:'); + console.error(e); + } resolve(null); }); }); @@ -89,8 +93,8 @@ export async function getManyE621Posts(ids: string[] | number[]): Promise { - return (await request('/posts', { md5, v2: 'true' })) as E621Post ?? null; +export async function getE621PostByMd5(md5: string, logErrors = true): Promise { + return (await request('/posts', { md5, v2: 'true' }, logErrors)) as E621Post ?? null; } export async function getE621PostFlag(id: number): Promise {