diff options
| author | Fuwn <[email protected]> | 2025-09-07 01:55:42 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-07 01:55:42 -0700 |
| commit | c896ab4607654a8b3ea3192919ee10dd7d62286f (patch) | |
| tree | d9698ed6f35d17842e02262d1fe9b81826893cba /src/reddit.js | |
| parent | chore: Fix package description (diff) | |
| download | umabotdiscord-c896ab4607654a8b3ea3192919ee10dd7d62286f.tar.xz umabotdiscord-c896ab4607654a8b3ea3192919ee10dd7d62286f.zip | |
feat: Add top command
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); +} |