Disable logging on md5 404's

This commit is contained in:
Tarrgon
2026-07-20 16:26:50 -04:00
parent cc447a15be
commit 2b65793903
2 changed files with 14 additions and 10 deletions
+2 -2
View File
@@ -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);
+12 -8
View File
@@ -28,7 +28,7 @@ if (secure && existsSync('./certs/cert.pem') && existsSync('./certs/cert.pem'))
});
}
async function request(path: string, query?: { [name: string]: string }): Promise<any> {
async function request(path: string, query?: { [name: string]: string }, logErrors = true): Promise<any> {
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<E621Po
return (await request('/posts', { v2: 'true', tags: `id:${ids.join(',')}` })) as E621Post[] ?? [];
}
export async function getE621PostByMd5(md5: string): Promise<E621Post | null> {
return (await request('/posts', { md5, v2: 'true' })) as E621Post ?? null;
export async function getE621PostByMd5(md5: string, logErrors = true): Promise<E621Post | null> {
return (await request('/posts', { md5, v2: 'true' }, logErrors)) as E621Post ?? null;
}
export async function getE621PostFlag(id: number): Promise<PostFlag | null> {