Meme_Api icon indicating copy to clipboard operation
Meme_Api copied to clipboard

Pls Add a feature to get a random post from Top/hot/rising/new sorting

Open MdKaif2782 opened this issue 3 years ago • 2 comments

Using your Butter Smooth API for my discord bot.. Really a big help! But the problem is its showing same posts for 2-3 times (specially for specified subreddit). It would be really good if it can be specified that by which sorting method a random meme will be generated like sort by Hot/new/Rising/Top/Gilded etc..

MdKaif2782 avatar Jan 15 '22 08:01 MdKaif2782

would be a a great feature!

ezzcodeezzlife avatar Apr 21 '22 14:04 ezzcodeezzlife

I think you can achieve this by passing the category ( top/hot/rising/new ) to the URL

https://github.com/D3vd/Meme_Api/blob/f5233692907d23042422d2a805a0121f3244d308/libraries/reddit/utils.go#L55-L58

like:

func GetSubredditAPIURL(subreddit string, limit int, category string) (url string) { 
 	url = "https://oauth.reddit.com/r/" + subreddit + "/"+category+"?limit=" + strconv.Itoa(limit) 
 	return 
} 

and you also need to add this new information to the cache

https://github.com/D3vd/Meme_Api/blob/f5233692907d23042422d2a805a0121f3244d308/api/gimme/one_random_meme.go#L23

https://github.com/D3vd/Meme_Api/blob/f5233692907d23042422d2a805a0121f3244d308/api/gimme/one_random_meme.go#L41-L43

like:

memes := redis.GetPostsFromCache(sub+category)
 if err := redis.WritePostsToCache(sub+category, freshMemes); err != nil { 
 	sentry.CaptureException(err) 
 }

geraldzm avatar May 22 '22 19:05 geraldzm