Skip to content

Commit

Permalink
Configurable m.notice support (#5)
Browse files Browse the repository at this point in the history
* Horrible POC of optionally replying to m.notice

* refactor notice support

* use config respond_to_notice

* on_message correct logic

---------

Co-authored-by: Kim Brose <kim@clavius.discovery>
Co-authored-by: Gerrit Gogel <gerrit@gogel.me>
  • Loading branch information
3 people authored Feb 17, 2024
1 parent 3639597 commit 012b107
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion base-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ youtube:
thumbnail: True
tiktok:
enabled: True
video: True
video: True
respond_to_notice: False
7 changes: 6 additions & 1 deletion socialmediadownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?")
Expand All @@ -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"]:
Expand Down

0 comments on commit 012b107

Please sign in to comment.