From 85e23d56c4f2e074ae8a5903381ab6dc0f4a9f65 Mon Sep 17 00:00:00 2001 From: Tom Casavant Date: Sun, 13 Nov 2022 20:52:00 -0500 Subject: [PATCH 1/3] Updated License Year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index e6d06e9..3bbbcfa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Tom Casavant +Copyright (c) 2022 Tom Casavant Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 97cdd62861c051d84fbd43eba144d6eb7e412f2b Mon Sep 17 00:00:00 2001 From: Tom Casavant Date: Sun, 13 Nov 2022 20:52:22 -0500 Subject: [PATCH 2/3] Initial setup for reddit url --- base-config.yaml | 2 ++ maubot.yaml | 2 +- reddit.py | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 base-config.yaml diff --git a/base-config.yaml b/base-config.yaml new file mode 100644 index 0000000..19fee94 --- /dev/null +++ b/base-config.yaml @@ -0,0 +1,2 @@ +# Reddit URL, set to old.reddit.com, etc. +reddit_base: reddit.com # https://{reddit_base}/r/... diff --git a/maubot.yaml b/maubot.yaml index 31809bc..dc8aa6d 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -9,7 +9,7 @@ maubot: 0.1.0 id: casavant.tom.reddit # A PEP 440 compliant version string. -version: 1.4.0 +version: 1.5.0 # The SPDX license identifier for the plugin. https://spdx.org/licenses/ # Optional, assumes all rights reserved if omitted. diff --git a/reddit.py b/reddit.py index 1824eac..475b57b 100644 --- a/reddit.py +++ b/reddit.py @@ -3,15 +3,29 @@ import urllib.parse from maubot import Plugin, MessageEvent from maubot.handlers import command +from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper +# Setup config file +class Config(BaseProxyConfig): + def do_update(self, helper: ConfigUpdateHelper) -> None: + helper.copy("reddit_base") class RedditPlugin(Plugin): + async def start(self) -> None: + await super().start() + self.config.load_and_update() + + @classmethod + def get_config_class(cls) -> Type[BaseProxyConfig]: + return Config + @command.passive("((^| )r\/)([^\s^,^.]+)", multiple=True) async def handler(self, evt: MessageEvent, subs: List[Tuple[str, str]]) -> None: await evt.mark_read() subreddits = [] # List of all subreddits given by user for _, r_slash, __, sub_str in subs: - link = "https://reddit.com/r/{}".format(urllib.parse.quote(sub_str.lower())) + base_url = self.config["reddit_base"] + link = "https://{}/r/{}".format(base_url, urllib.parse.quote(sub_str.lower())) async with self.http.head( link, headers={"User-agent": "redditmaubot"}, allow_redirects=True From e6f1bd72b5cbfb10d6bfd91ab87b4e648976a964 Mon Sep 17 00:00:00 2001 From: Tom Casavant Date: Sun, 13 Nov 2022 22:09:59 -0500 Subject: [PATCH 3/3] Updated Reddit to handle other urls, closes #4 --- maubot.yaml | 4 ++-- reddit.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maubot.yaml b/maubot.yaml index dc8aa6d..b81b00b 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -32,8 +32,8 @@ main_class: RedditPlugin database: false # Extra files that the upcoming build tool should include in the mbp file. -#extra_files: -#- base-config.yaml +extra_files: + - base-config.yaml #- LICENSE # List of dependencies diff --git a/reddit.py b/reddit.py index 475b57b..2b6d2df 100644 --- a/reddit.py +++ b/reddit.py @@ -1,5 +1,5 @@ from random import choice -from typing import List, Tuple +from typing import List, Tuple, Type import urllib.parse from maubot import Plugin, MessageEvent from maubot.handlers import command