sopel-irc / sopel-reddit

A reddit plugin for Sopel IRC bots.
Other
0 stars 1 forks source link

Figure out how to handle shortened share links #8

Open dgw opened 1 year ago

dgw commented 1 year ago

Reddit's gone full dumb with shareable links that look like https://reddit.com/r/comics/s/95j2GYWoSR.

This format seems to come only from their mobile apps, but it's damned useless for parsing in a chat bot. There's no obvious relationship between (any part of) the short "keyword" and the submission/comment ID it links to.

It's possible to handle these by using a Host: www.reddit.com header to skip an unnecessary redirect and then parse the Location header returned by https://www.reddit.com/r/comics/s/95j2GYWoSR for the actual submission/comment ID, but that's pretty obnoxious.

dgw commented 1 year ago

praw-dev/praw#1994 added this, though there'll be some control-flow issues to solve in this plugin whenever that feature is available in a new praw release.

The implementation depends on passing a share link to either reddit.submission or reddit.comment, but if the share link points to the wrong type of item, praw.exceptions.ClientException is raised. There is no way to tell in advance what type of item one of these share links points to (thanks, Reddit).