mirror of
https://github.com/nikdoof/dropbot.git
synced 2025-12-18 20:29:28 +00:00
Instead of picking a random invalid page, pull the first 10 pages of top items.
This commit is contained in:
@@ -248,12 +248,12 @@ class DropBot(ClientXMPP):
|
||||
if len(args) == 0:
|
||||
return "Usage: !redditimg <subreddit>"
|
||||
imgs = []
|
||||
page = choice(xrange(0, 100))
|
||||
for img in requests.get("http://imgur.com/r/%s/top/all/page/%s.json" % (args[0], page)).json()['data']:
|
||||
resp = "%s - http://i.imgur.com/%s%s" % (img['title'], img['hash'], img['ext'])
|
||||
if img['nsfw']:
|
||||
resp = resp + " :nsfw:"
|
||||
imgs.append(resp)
|
||||
for page in range(1, 11):
|
||||
for img in requests.get("http://imgur.com/r/%s/top/all/page/%s.json" % (args[0], page)).json()['data']:
|
||||
resp = "%s - http://i.imgur.com/%s%s" % (img['title'], img['hash'], img['ext'])
|
||||
if img['nsfw']:
|
||||
resp = resp + " :nsfw:"
|
||||
imgs.append(resp)
|
||||
if len(imgs):
|
||||
return choice(imgs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user