Skip to content

Commit

Permalink
fix(badmeme): set user-agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed May 3, 2023
1 parent 4c1c637 commit 5073d4b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/functions/reddit/BadMeme.mts
Expand Up @@ -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 }

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5073d4b

Please sign in to comment.