Fixing the reddit functionality. used to barf if you linked a reddit that didnt exist, now it just chceks for actual posts
This commit is contained in:
parent
a242ae99ed
commit
82fddef8a0
@ -105,15 +105,14 @@ async def on_message(message):
|
||||
|
||||
# Read messages and look for mentions of subreddits
|
||||
for word in message.content.split():
|
||||
if message.author != client.user:
|
||||
if '/r/' in word or 'r/' in word:
|
||||
try:
|
||||
subreddit = word.split('/')[-1]
|
||||
# Try and request the page to check that it actually exists
|
||||
get_from_reddit.get_image(boards=subreddit, nsfw=True)
|
||||
if (message.author != client.user) and '/r/' in word:
|
||||
try:
|
||||
subreddit = word.split('/')[-1]
|
||||
# check if that subreddit exists by querying the length of this json blob
|
||||
if len(requests.get("https://reddit.com/r/{}.json".format(subreddit), headers={'User-agent':'dragon-bot'}).json()['data']['children']):
|
||||
await client.send_message(message.channel, "https://reddit.com/r/{}".format(subreddit))
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
if message.content.startswith('!8ball'):
|
||||
await client.send_message(
|
||||
|
Loading…
x
Reference in New Issue
Block a user