summaryrefslogtreecommitdiff
path: root/src/reddit.js
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-07 01:55:42 -0700
committerFuwn <[email protected]>2025-09-07 01:55:42 -0700
commitc896ab4607654a8b3ea3192919ee10dd7d62286f (patch)
treed9698ed6f35d17842e02262d1fe9b81826893cba /src/reddit.js
parentchore: Fix package description (diff)
downloadumabotdiscord-c896ab4607654a8b3ea3192919ee10dd7d62286f.tar.xz
umabotdiscord-c896ab4607654a8b3ea3192919ee10dd7d62286f.zip
feat: Add top command
Diffstat (limited to 'src/reddit.js')
-rw-r--r--src/reddit.js18
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);
+}