diff --git a/maubot.yaml b/maubot.yaml index 179f2a7..a37873f 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.2.0 +version: 1.3.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 243a741..f34b6c1 100644 --- a/reddit.py +++ b/reddit.py @@ -4,12 +4,13 @@ from maubot import Plugin, MessageEvent from maubot.handlers import command + class RedditPlugin(Plugin): - @command.passive("(^r\/)([^\s]+)", multiple=True) + @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 _, rslash, sub_str in subs: + for _, r_slash, __, sub_str in subs: link = "https://reddit.com/r/{}".format(urllib.parse.quote(sub_str)) async with self.http.head( @@ -24,13 +25,14 @@ async def handler(self, evt: MessageEvent, subs: List[Tuple[str, str]]) -> None: subreddits.append(link) if subreddits: + all_subs = f"\n".join(subreddits) condescending = [ - "Don't you mean {} ?", - "Shouldn't this be {} ?", - "Are you sure it isn't {} ?", - "Isn't it {} ?", - "uh, {} right?", - "{} is probably what you're looking for", + f"Don't you mean {all_subs} ?", + f"Shouldn't this be {all_subs} ?", + f"Are you sure it isn't {all_subs} ?", + f"Isn't it {all_subs} ?", + f"uh, {all_subs} right?", + f"{all_subs} is probably what you're looking for", ] - response = choice(condescending).format("\n".join(subreddits)) - await evt.reply(url, html_in_markdown=True) # Reply to user + response = f"{choice(condescending)}" + await evt.reply(response, html_in_markdown=True) # Reply to user