-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reddit: handle subreddits, and u/
& r/
references
#1722
Conversation
I mainly wanted to introduce some of this layer in this PR and possibly consider using a separate PR to add a subcommand layer for subreddits. The other layer would be the basics of this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice little feature. My requested changes are mostly cosmetic or minor.
9d9d3c8
to
330d364
Compare
I have another tweak that I want to add to this, sometimes a subreddit being banned/locked throws a 403 locked 404 banned |
330d364
to
bfab822
Compare
here's the new tweak:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me!
2b39647
to
430dac8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to test this, but the concept is 👍! There are some issues, though. Not sure if they were present before or were introduced in the rebase you just had to do on account of other reddit
stuff getting merged.
430dac8
to
892c807
Compare
All the requested stuff is changed, and pushed,,, I even managed to find a bug that I was able to kill. |
892c807
to
da0c7b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the specific regex suggestion below, we talked a bit on IRC about whether to specifically handle r/all
, which "exists" but isn't a normal subreddit, and therefore the code here will incorrectly report it as "banned". I think we'd never falsely report that state in a perfect world, but here in reality we have to decide if it's worth the potential code smell to handle that special case.
Keeping this as just a neutral "Comment" review, because it's only suggestions and not merge-blockers.
sopel/modules/reddit.py
Outdated
@@ -328,3 +378,37 @@ def get_channel_spoiler_free(bot, trigger): | |||
bot.say('%s is flagged as spoiler-free' % channel) | |||
else: | |||
bot.say('%s is flagged as spoilers-allowed' % channel) | |||
|
|||
|
|||
@rule(r'^(?P<prefix>r|u)/(?P<id>[a-zA-Z0-9-_]+)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played with some stuff and came up with (what I think is) an even better pattern.
@rule(r'^(?P<prefix>r|u)/(?P<id>[a-zA-Z0-9-_]+)') | |
@rule(r'.*\b(?P<prefix>r|u)/(?P<id>[a-zA-Z0-9-_]+)\b.*') |
This will match a user or subreddit reference anywhere in the line, instead of only at the beginning, and properly handles things like r/sopel's moderators
or u/deathbybandaid'll get ya!
.
It only handles the last reference in the line, though. That's a known issue with the rule
decorator, which we'll probably work on for 7.1 (see #1757).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would, though like suggestions for regex that will help me accomplish my second comment on this PR (for my next PR), which would allow users to type "r/plex hot" and get the first item in the sorting "hot"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed more in #1722 (comment) but here's an improved pattern I came up with for this:
(?i)(?<!\S)\/?(?P<prefix>r|u)\/(?P<id>[a-zA-Z0-9-_]+)\b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Sopel itself, we don't need the flag ((?i)
), but we do need to wrap the whole pattern in .*
for it to work.
@rule(r'.*(?<!\S)/?(?P<prefix>r|u)/(?P<id>[a-zA-Z0-9-_]+)\b.*')
u/
& r/
references
Right, so it's not just The only thing (I think) we should worry about in this PR before then is the regex to match the in-text
This pattern:
I think that's everything! Bunch of test cases at https://regexr.com/4p8dh. One last thing: I retitled the PR to more accurately reflect what it's doing. If you could update your commit message to match, that'd be 💯% awesome! |
aaf2424
to
da0c7b4
Compare
I'm stashing what I had for "all" and "popular" for a later PR as per @dgw If I get hit by a bus,, the below is what i had planned.
|
Somehow, processing links appears to be broken in the current version of this PR (all I changed locally was the regex for slash-refs). Ran out of time to debug it right now, so I'm leaving the note as a reminder for one of us to continue that. |
da0c7b4
to
eeceea9
Compare
I made the suggestions,, and I now see what you mean about links not working too |
@deathbybandaid See #1760 about the link-handling problem. It's not related to this. Please try out this PR with my fixup (just pushed), and squash + reword the commit message to match the PR title if you're happy with it. (I'd appreciate a co-author credit, if you would add one for me during the squash. I've spent so much time on this this week! 😹) |
1ed7d45
to
282ebe7
Compare
Co-authored-by: dgw <dgw@technobabbl.es>
282ebe7
to
71178ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At long last, we've managed to coerce this PR into doing exactly what we want (mostly by playing with regex a lot). Some more tweaks and a regression fix or two (unrelated to these changes) will come from #1760 after this is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't check the regex. It looks good, but I haven't checked the rules for reddit's URLs. So, I'd say I trust you. :)
LGTM!
This PR adds to the functionality of
reddit.py
by adding:r/
andu/
matching.