From 5073d4b01dddd191acf5ca278a7c260ce008b756 Mon Sep 17 00:00:00 2001 From: Khafra Date: Wed, 3 May 2023 01:11:51 -0400 Subject: [PATCH] fix(badmeme): set user-agent header --- src/functions/reddit/BadMeme.mts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/functions/reddit/BadMeme.mts b/src/functions/reddit/BadMeme.mts index 02cacebe..069e2ab5 100644 --- a/src/functions/reddit/BadMeme.mts +++ b/src/functions/reddit/BadMeme.mts @@ -4,6 +4,7 @@ import { decodeXML } from 'entities' import { setInterval } from 'node:timers' import { URLSearchParams } from 'node:url' import { request } from 'undici' +import { platform } from 'node:os' export { type Reddit, apiSchema } @@ -63,8 +64,16 @@ export const badmeme = async ( o.set('t', timeframe) } + // https://github.com/reddit-archive/reddit/wiki/API#rules // https://www.reddit.com/dev/api#GET_new - const { body, statusCode } = await request(`https://www.reddit.com/r/${subreddit}/${modifier}.json?${o}`) + const { body, statusCode } = await request( + `https://www.reddit.com/r/${subreddit}/${modifier}.json?${o}`, + { + headers: { + 'user-agent': `${platform()}:KhafraBot:v1.0.0 (by /u/worthy, https://github.com/KhafraDev/Khafra-Bot)` + } + } + ) // When a subreddit doesn't exist, reddit automatically redirects to a search API URL. if (statusCode !== 200) {