diff options
Diffstat (limited to 'src/reddit.js')
| -rw-r--r-- | src/reddit.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/reddit.js b/src/reddit.js index 183faca..543e6ff 100644 --- a/src/reddit.js +++ b/src/reddit.js @@ -1,5 +1,6 @@ -async function fetchRedditPosts() { - const response = await fetch(redditURL, { +async function fetchRedditPosts(sort = 'hot', time = 'day') { + const url = `https://www.reddit.com/r/okbuddyumamusume/${sort}.json${sort === 'top' ? `?t=${time}` : ''}`; + const response = await fetch(url, { headers: { 'User-Agent': 'UmaBot/0.1.0', }, @@ -71,24 +72,29 @@ function getRandomPost(posts) { } export async function getCutePost() { - const posts = await fetchRedditPosts(); + const posts = await fetchRedditPosts('hot'); const filteredPosts = filterPostsByFlair(posts, ['roleplay', 'announcement']); return getRandomPost(filteredPosts); } export async function getRoleplayPost() { - const posts = await fetchRedditPosts(); + const posts = await fetchRedditPosts('hot'); const filteredPosts = filterPostsByFlair(posts, [], ['roleplay']); return getRandomPost(filteredPosts); } export async function getNSFWPost() { - const posts = await fetchRedditPosts(); + const posts = await fetchRedditPosts('hot'); const filteredPosts = filterPostsByFlair(posts, [], ['nsfw']); return getRandomPost(filteredPosts); } -export const redditURL = 'https://www.reddit.com/r/okbuddyumamusume/hot.json'; +export async function getTopPost(time = 'day') { + const posts = await fetchRedditPosts('top', time); + const filteredPosts = filterPostsByFlair(posts, ['roleplay', 'announcement']); + + return getRandomPost(filteredPosts); +} |