Update link regex pattern

This commit is contained in:
Zeva Rose 2022-06-24 17:19:19 -06:00
parent 8f5e839ae9
commit acb5cc5c5e

View file

@ -26,7 +26,7 @@ config = TaskConfig.from_yaml()
config.reddit["user_agent"] = config.reddit.get("user_agent", DEFAULT_USER_AGENT)
running = []
logger = logging.getLogger(__name__)
image_link = re.compile(r"(.*preview\.redd\.it\/)(.*\..*)\?")
image_link = re.compile(r"https?://(?:www)?\.?preview\.redd\.it\/(.*\..*)\?.*")
async def post_embeds(sub: Sub, post: Submission, reddit: Reddit) -> Optional[List[Embed]]:
@ -76,7 +76,7 @@ async def post_embeds(sub: Sub, post: Submission, reddit: Reddit) -> Optional[Li
if post.spoiler:
content += "||"
content += f"\n\n[View this post]({url})"
content = image_link.sub(content, "https://i.redd.it/\2")
content = "\n".join(image_link.sub(r"https://i.redd.it/\1", x) for x in content.split("\n"))
if not images and not content:
logger.debug(f"Post {post.id} had neither content nor images?")