Skip to content
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

Handle share links #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

half-duplex
Copy link
Member

@half-duplex half-duplex commented Sep 26, 2024

Fixes #8

Test links (from the praw commit, I'm not touching the reddit app):
https://www.reddit.com/r/redditdev/s/WNauetbiNG (submission)
https://www.reddit.com/r/redditdev/s/nGnQE1QkLC (comment)

Example output:

me> https://www.reddit.com/r/redditdev/s/WNauetbiNG
Sopel> [reddit] [PRAW] HTTPS enabled PRAW testing needed ('PRAW' flair) (self.redditdev) | 11 points (84.0%) | 2 comments | Posted by bboe | Created at 2014-09-17 - 06:34:31 UTC | https://redd.it/2gmzqe
me> https://www.reddit.com/r/redditdev/s/nGnQE1QkLC
Sopel> [reddit] Comment by bboe | 1 point | Posted at 2014-09-18 - 03:13:54 UTC | https://reddit.com/comments/2gmzqe/c/cklhv0f | Yes it does. That fix is also in the master branch, we just haven't made a release for it (and we probably won't until 3.0).

sopel_reddit/__init__.py Outdated Show resolved Hide resolved
@dgw
Copy link
Member

dgw commented Dec 18, 2024

I mentioned this on IRC already, but it belongs in the PR:

Reddit sometimes blocks the request this performs with an HTTP 403 Forbidden status. The code works for me locally on a residential connection, and I presume @half-duplex is also on one. Testing in "production" on our main bot (running on a DigitalOcean server) did NOT work, however. As currently written it will simply fail silently.

praw finally released support for these stupid URLs in October with version 7.8.0. It'd require reworking the plugin logic a bit, but using their method (passing the share link in Reddit.comment(url='link') or Reddit.submission(url='link') works on the server, where this PR's current code receives a 403.

Do you feel like experimenting with praw 7.8.x and its built-in share link resolution feature?

@dgw
Copy link
Member

dgw commented Dec 18, 2024

It's easier to show my pseudocode idea here than on IRC, because line breaks:

url = trigger.match.group(0)
comment = submission = None

try:
    comment = bot.memory['reddit_praw'].comment(url=url)
except praw.exceptions.InvalidURL:
    submission = bot.memory['reddit_praw'].submission(url=url)

if comment:
    show_comment_info()  # needs a little reworking to optionally take the comment object instead of an ID
else:
    show_post_info()  # ditto for submission object instead of ID

Do I love this? Absolutely not. I just think it's less fragile to use PRAW's built-in handling, because that seems to work on the server where directly resolving the redirect gets rejected with a 403.

Yes, I wish PRAW had a saner API for this. The whole reason we hate the /s/ links is because they obfuscate what type of item is being linked to, so requiring the client to know which type it's expecting is silly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Figure out how to handle shortened share links
2 participants