From 3ffccf52aa74cb18922e3ae843605ca28e4e0f02 Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:45:47 +0200 Subject: [PATCH] added support for MEE6 notifications --- bot/extensions/youtube/tasks.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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"