D3vd / Meme_Api

Summon a random meme at will
https://meme-api.com/gimme
MIT License
795 stars 110 forks source link

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

Open MdKaif2782 opened 2 years ago

MdKaif2782 commented 2 years ago

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..

ezzcodeezzlife commented 2 years ago

would be a a great feature!

geraldzm commented 2 years ago

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) 
 }