From 982e16f8d94f74b5ec7dbbdf62fbdbc106530941 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 9 Sep 2025 18:07:32 -0700 Subject: refactor(src): Use arrow functions everywhere --- src/reddit.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/reddit.ts') 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 { +): Promise => { 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 { +): Promise => { 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 { +export const getCutePost = async (): Promise => { const posts = await fetchRedditPosts('hot'); const filteredPosts = filterPostsByFlair(posts, ['roleplay', 'announcement']); return getRandomPost(filteredPosts); -} +}; -export async function getRoleplayPost(): Promise { +export const getRoleplayPost = async (): Promise => { const posts = await fetchRedditPosts('hot'); const filteredPosts = filterPostsByFlair(posts, [], ['roleplay']); return getRandomPost(filteredPosts); -} +}; -export async function getNSFWPost(): Promise { +export const getNSFWPost = async (): Promise => { 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 { +): Promise => { const posts = await fetchRedditPosts('top', time); const filteredPosts = filterPostsByFlair(posts, ['roleplay', 'announcement']); return getRandomPost(filteredPosts); -} +}; -- cgit v1.2.3