Skip to content

Commit

Permalink
Fixed missing condescension, and linking urls when user already has link
Browse files Browse the repository at this point in the history
  • Loading branch information
TomCasavant committed Apr 23, 2019
1 parent c3fb1d6 commit f8e601b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion maubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 12 additions & 10 deletions reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

0 comments on commit f8e601b

Please sign in to comment.