diff --git a/base-config.yaml b/base-config.yaml index 1fb1bb2..bc057f6 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -15,4 +15,5 @@ youtube: thumbnail: True tiktok: enabled: True - video: True \ No newline at end of file + video: True +respond_to_notice: False diff --git a/socialmediadownload.py b/socialmediadownload.py index 5d91f3f..7c17505 100644 --- a/socialmediadownload.py +++ b/socialmediadownload.py @@ -23,6 +23,8 @@ def do_update(self, helper: ConfigUpdateHelper) -> None: for suffix in ["enabled", "info", "image", "video", "thumbnail"]: helper.copy(f"{prefix}.{suffix}") + helper.copy("respond_to_notice") + reddit_pattern = re.compile(r"((?:https?:)?\/\/)?((?:www|m|old|nm)\.)?((?:reddit\.com|redd\.it))(\/r\/[^/]+\/(?:comments|s)\/[a-zA-Z0-9_\-]+)") instagram_pattern = re.compile(r"(?:https?:\/\/)?(?:www\.)?instagram\.com\/?([a-zA-Z0-9\.\_\-]+)?\/([p]+)?([reel]+)?([tv]+)?([stories]+)?\/([a-zA-Z0-9\-\_\.]+)\/?([0-9]+)?") youtube_pattern = re.compile(r"((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu\.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?") @@ -39,9 +41,12 @@ def get_config_class(cls) -> Type[BaseProxyConfig]: @event.on(EventType.ROOM_MESSAGE) async def on_message(self, evt: MessageEvent) -> None: - if evt.content.msgtype != MessageType.TEXT or evt.content.body.startswith("!"): + if (evt.content.msgtype != MessageType.TEXT and + not (self.config["respond_to_notice"] and evt.content.msgtype == MessageType.NOTICE) or + evt.content.body.startswith("!")): return + for url_tup in youtube_pattern.findall(evt.content.body): await evt.mark_read() if self.config["youtube.enabled"]: