Skip to content

Commit 9279220

Browse files
authored
Merge pull request #2245 from half-duplex/reddit-preview-links
reddit: handle image preview links
2 parents c812145 + 81f3ca4 commit 9279220

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sopel/modules/reddit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
)
3535
short_post_url = r'https?://(redd\.it|reddit\.com)/(?P<submission>[\w-]+)/?$'
3636
user_url = r'%s/u(?:ser)?/([\w-]+)' % domain
37-
image_url = r'https?://i\.redd\.it/\S+'
37+
image_url = r'https?://(?P<subdomain>i|preview)\.redd\.it/(?P<image>[^?\s]+)'
3838
video_url = r'https?://v\.redd\.it/([\w-]+)'
3939
gallery_url = r'https?://(?:www\.)?reddit\.com/gallery/([\w-]+)'
4040

@@ -88,6 +88,9 @@ def get_is_cakeday(entrytime):
8888
@plugin.output_prefix(PLUGIN_OUTPUT_PREFIX)
8989
def image_info(bot, trigger, match):
9090
url = match.group(0)
91+
preview = match.group("subdomain") == "preview"
92+
if preview:
93+
url = "https://i.redd.it/{}".format(match.group("image"))
9194
results = list(
9295
bot.memory['reddit_praw']
9396
.subreddit('all')
@@ -98,7 +101,7 @@ def image_info(bot, trigger, match):
98101
except IndexError:
99102
# Fail silently if the image link can't be mapped to a submission
100103
return plugin.NOLIMIT
101-
return say_post_info(bot, trigger, oldest.id, False, True)
104+
return say_post_info(bot, trigger, oldest.id, preview, True)
102105

103106

104107
@plugin.url(video_url)

0 commit comments

Comments
 (0)