Add regex for finding image links

This commit is contained in:
Zeva Rose 2022-06-24 16:58:04 -06:00
parent 6439a015c9
commit 10f331765f

View file

@ -30,6 +30,7 @@ from jarvis.utils.permissions import admin_or_permissions
DEFAULT_USER_AGENT = f"python:JARVIS:{const.__version__} (by u/zevaryx)"
sub_name = re.compile(r"\A[A-Za-z0-9][A-Za-z0-9_]{2,20}\Z")
image_link = re.compile(r"(.*preview\.redd\.it\/)(.*\..*)\?")
class RedditCog(Extension):
@ -89,6 +90,7 @@ class RedditCog(Extension):
if post.spoiler:
content += "||"
content += f"\n\n[View this post]({url})"
content = image_link.sub(content, "https://i.redd.it/\2")
if not images and not content:
self.logger.debug(f"Post {post.id} had neither content nor images?")