summaryrefslogtreecommitdiff
path: root/src/reddit.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-09 18:07:32 -0700
committerFuwn <[email protected]>2025-09-09 18:07:32 -0700
commit982e16f8d94f74b5ec7dbbdf62fbdbc106530941 (patch)
tree1c4163564305fb45cd9f105462cc2cd783399364 /src/reddit.ts
parentrefactor: Move Discord APIs to Discord module (diff)
downloadumabotdiscord-982e16f8d94f74b5ec7dbbdf62fbdbc106530941.tar.xz
umabotdiscord-982e16f8d94f74b5ec7dbbdf62fbdbc106530941.zip
refactor(src): Use arrow functions everywhere
Diffstat (limited to 'src/reddit.ts')
-rw-r--r--src/reddit.ts40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/reddit.ts b/src/reddit.ts
index 0c12739..f57cf75 100644
--- a/src/reddit.ts
+++ b/src/reddit.ts
@@ -51,10 +51,10 @@ export interface RedditResponse {
type SortType = 'hot' | 'top';
-async function fetchWithRetry(
+const fetchWithRetry = async (
url: string,
maxRetries: number = 3,
-): Promise<Response> {
+): Promise<Response> => {
for (let attempt = 0; attempt < maxRetries; attempt++)
try {
await new Promise((resolve) =>
@@ -87,12 +87,12 @@ async function fetchWithRetry(
}
throw new Error('Max retries exceeded');
-}
+};
-export async function fetchRedditPosts(
+export const fetchRedditPosts = async (
sort: SortType = 'hot',
time: TimePeriod = 'day',
-): Promise<RedditPost[]> {
+): Promise<RedditPost[]> => {
const url = `https://www.reddit.com/r/okbuddyumamusume/${sort}.json${sort === 'top' ? `?t=${time}` : ''}`;
const response = await fetchWithRetry(url);
@@ -125,13 +125,13 @@ export async function fetchRedditPosts(
const data: RedditResponse = await response.json();
return data.data.children.map((post) => post.data);
-}
+};
-export function filterPostsByFlair(
+export const filterPostsByFlair = (
posts: RedditPost[],
excludedFlairs: string[] = [],
includedFlairs: string[] = [],
-): RedditPost[] {
+): RedditPost[] => {
return posts.filter((post) => {
if (post.is_gallery) return false;
@@ -166,43 +166,43 @@ export function filterPostsByFlair(
return true;
});
-}
+};
-function getRandomPost(posts: RedditPost[]): RedditPost {
+const getRandomPost = (posts: RedditPost[]): RedditPost => {
if (posts.length === 0)
throw new Error('No posts found matching the criteria');
const randomIndex = Math.floor(Math.random() * posts.length);
return posts[randomIndex];
-}
+};
-export async function getCutePost(): Promise<RedditPost> {
+export const getCutePost = async (): Promise<RedditPost> => {
const posts = await fetchRedditPosts('hot');
const filteredPosts = filterPostsByFlair(posts, ['roleplay', 'announcement']);
return getRandomPost(filteredPosts);
-}
+};
-export async function getRoleplayPost(): Promise<RedditPost> {
+export const getRoleplayPost = async (): Promise<RedditPost> => {
const posts = await fetchRedditPosts('hot');
const filteredPosts = filterPostsByFlair(posts, [], ['roleplay']);
return getRandomPost(filteredPosts);
-}
+};
-export async function getNSFWPost(): Promise<RedditPost> {
+export const getNSFWPost = async (): Promise<RedditPost> => {
const posts = await fetchRedditPosts('hot');
const filteredPosts = filterPostsByFlair(posts, [], ['nsfw']);
return getRandomPost(filteredPosts);
-}
+};
-export async function getTopPost(
+export const getTopPost = async (
time: TimePeriod = 'day',
-): Promise<RedditPost> {
+): Promise<RedditPost> => {
const posts = await fetchRedditPosts('top', time);
const filteredPosts = filterPostsByFlair(posts, ['roleplay', 'announcement']);
return getRandomPost(filteredPosts);
-}
+};