diff --git a/bot/extensions/youtube/tasks.py b/bot/extensions/youtube/tasks.py index 7af40122..f016269f 100644 --- a/bot/extensions/youtube/tasks.py +++ b/bot/extensions/youtube/tasks.py @@ -1,4 +1,5 @@ import asyncio +import re import xml.etree.ElementTree as ET from datetime import datetime from io import BytesIO @@ -12,6 +13,8 @@ from bot import core from bot.config import settings +YOUTUBE_URL = re.compile(r"(?Phttps?://www\.youtube\.com/watch\?v=[\w-]+)") + class YoutubeTasks(commands.Cog): """Tasks for YouTube functions""" @@ -49,10 +52,13 @@ async def check_for_new_videos(self): if not self.videos: async for message in self.channel.history(limit=10): - try: + if message.embeds: self.videos.append(message.embeds[0].url) - except IndexError: - pass + else: + match = YOUTUBE_URL.search(message.content) + if match: + self.videos.append(match.group("url")) + self.videos.reverse() url = "https://www.youtube.com/feeds/videos.xml?channel_id=UC4JX40jDee_tINbkjycV4Sg"