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

reddit: media details (+ refactoring) #1734

Merged
merged 3 commits into from
Nov 20, 2019
Merged

reddit: media details (+ refactoring) #1734

merged 3 commits into from
Nov 20, 2019

Conversation

dgw
Copy link
Member

@dgw dgw commented Nov 3, 2019

Primary changes: The reddit plugin now understands how to detect links to images & videos hosted by Reddit itself (i.redd.it and v.redd.it URLs), and how to map those back to a submission. For images, it's the oldest submission with that link as the URL; for videos, Reddit itself redirects the short URL to a 'canonical' post (should be the first, excluding all crossposts).

Secondary changes: Enough with the praw.Reddit() setup being duplicated, and enough with constructing a new instance every time the plugin wants to do something. Now, it constructs just one PRAW instance at load time, and stores it in Sopel's memory for reuse.

Tertiary changes: rpost_info() is now Just Another URL Detector™, like the newly added media link handlers. All of them now pass just the desired submission ID to a new say_post_info() function, leaving only the route to getting the desired ID for the triggerable functions.

Concerns: Potential conflicts with the changes #1722. We'll figure that out later, if necessary.

@dgw dgw added this to the 7.0.0 milestone Nov 3, 2019
@dgw dgw requested a review from a team November 3, 2019 23:54
Fetches the canonical post for videos by asking Reddit for a redirect
(cheeky hack) and shows normal post details for that.

Fetches the oldest post for a linked image via searching r/all and shows
the usual info about that submission.

Cheeky hack for getting a video's canonical URL designed by committee on
Sopel's IRC channel. (See co-authors.)

Co-Authored-By: deathbybandaid <sam@deathbybandaid.net>
Co-Authored-By: Exirel <florian.strzelecki@gmail.com>
Co-Authored-By: kwaaak <kwaaak@users.noreply.github.com>
@dgw dgw force-pushed the reddit-media-details branch from 590c894 to f6d79ae Compare November 20, 2019 01:14
dgw added 2 commits November 19, 2019 19:17
This is *much* better than repeating the construction call everywhere,
& more efficient than making a new instance every time we're triggered.
Instead of forcing every handler that might want to trigger output of
information about a post (submission) to twist its variables around so
they'll work for a function designed to act on links posted in the chat,
it's much better to have a separate output function that takes just the
ID of a submission, and fetches/displays the details on its own. This
way, no matter what another function is trying to match (Reddit-hosted
images, video links, etc.), all it has to do is pass along the
submission ID -- however it gets that.
@dgw dgw force-pushed the reddit-media-details branch from f6d79ae to d6f26b7 Compare November 20, 2019 01:17
@dgw dgw merged commit 0e826bf into master Nov 20, 2019
@dgw dgw deleted the reddit-media-details branch November 20, 2019 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants