Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reddit: handle image preview links #2245

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sopel/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
short_post_url = r'https?://(redd\.it|reddit\.com)/(?P<submission>[\w-]+)/?$'
user_url = r'%s/u(?:ser)?/([\w-]+)' % domain
image_url = r'https?://i\.redd\.it/\S+'
image_url = r'https?://(?P<subdomain>i|preview)\.redd\.it/(?P<image>[^?\s]+)'
video_url = r'https?://v\.redd\.it/([\w-]+)'
gallery_url = r'https?://(?:www\.)?reddit\.com/gallery/([\w-]+)'

Expand Down Expand Up @@ -88,6 +88,9 @@ def get_is_cakeday(entrytime):
@plugin.output_prefix(PLUGIN_OUTPUT_PREFIX)
def image_info(bot, trigger, match):
url = match.group(0)
preview = match.group("subdomain") == "preview"
if preview:
url = "https://i.redd.it/{}".format(match.group("image"))
results = list(
bot.memory['reddit_praw']
.subreddit('all')
Expand All @@ -98,7 +101,7 @@ def image_info(bot, trigger, match):
except IndexError:
# Fail silently if the image link can't be mapped to a submission
return plugin.NOLIMIT
return say_post_info(bot, trigger, oldest.id, False, True)
return say_post_info(bot, trigger, oldest.id, preview, True)


@plugin.url(video_url)
Expand Down