Skip to content

Commit

Permalink
reddit: fetch posts by submission_id
Browse files Browse the repository at this point in the history
Previously, the reddit module fetched posts by the full URL of the post.
This led to RedirectExceptions in some cases, for example when someone
links a naked reddit.com URL instead of www.reddit.com.  Instead, match
only the post ID and pass it to get_submission.
  • Loading branch information
calzoneman committed Jan 31, 2016
1 parent e6d3a2c commit f6aafb0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sopel/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


domain = r'https?://(?:www\.|np\.)?reddit\.com'
post_url = '(%s/r/.*?/comments/[\w-]+)' % domain
post_url = '%s/r/.*?/comments/([\w-]+)' % domain
user_url = '%s/u(ser)?/([\w-]+)' % domain
post_regex = re.compile(post_url)
user_regex = re.compile(user_url)
Expand All @@ -45,7 +45,7 @@ def shutdown(bot):
def rpost_info(bot, trigger, match=None):
r = praw.Reddit(user_agent=USER_AGENT)
match = match or trigger
s = r.get_submission(url=match.group(1))
s = r.get_submission(submission_id=match.group(1))

message = ('[REDDIT] {title} {link}{nsfw} | {points} points ({percent}) | '
'{comments} comments | Posted by {author} | '
Expand Down

0 comments on commit f6aafb0

Please sign in to comment.