Giter VIP home page Giter VIP logo

sopel-reddit's Introduction

sopel-reddit

A reddit plugin for Sopel IRC bots.

Installation

Stable version:

pip install sopel-reddit

From source

pip install -e path/to/sopel-reddit

# optional: for development
pip install -r dev-requirements.txt

Note: Running the test suite with pytest -v tests/ requires both sopel-reddit and sopel itself to be installed in the same venv.

Configuration

[reddit]
slash_info = True
# Allow expansion of inline references like `u/RandomRedditor` or `r/eyebleach`
# (links are always expanded)

app_id = abcdef0123456789
# Optional custom app ID for the reddit API

The app_id setting is provided mostly for future-proofing after API policy changes announced by Reddit Inc. in April 2023. It exists so possible future API limitations can be worked around by users without requiring a package update. As of the time this package version was published, the app_id setting does not need to have a value.

Special thanks

All contributors to the original reddit plugin for Sopel.

sopel-reddit's People

Contributors

dgw avatar

Watchers

 avatar  avatar

sopel-reddit's Issues

Figure out how to handle shortened share links

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.

Inconsistent/broken URL output for subs/users

Example 1: Link is repeated unnecessarily for subreddit URLs.

<dgw> https://reddit.com/r/IdiotsInCars
<Sopel> [reddit] https://reddit.com/r/IdiotsInCars | 4,132,014 subscribers | Created at 2015-10-27 - 02:13:45UTC | When idiots get behind the wheel of a vehicle, shit gets funny.

Example 2: Link isn't given for a user slash-reference.

<dgw> u/keklux
<Sopel> [reddit] keklux | Link: 9 | Comment: 1

Plugin should allow overriding default user agent

Reddit prefers that applications specify a user agent of the format <platform>:<app ID>:<version string> (by u/<Reddit username>).

This plugin uses the default USER_AGENT from sopel.tools.web, which isn't exactly designed for this use case. (It's generally based on some kind of consumer web browser, not an API client. In fact, Reddit's old, now-archived API wiki page says they heavily discourage spoofing popular browsers and might even ban clients for lying about their user agent string.)

Best approach for this plugin is probably to use something like python:sopel-reddit:<plugin_version>, and append (by u/<Reddit username>) conditionally based on an optional config setting.

Should probably remove the default key, eventually, and make both the app ID and username required.

Packaging modernization needed

This plugin already allows sopel>=8.0.0.dev0<9, so the current release is Good Enough™ and it's not urgent to make a new version. Eventually™ though, we should repackage everything using pyproject.toml metadata.

Different `i.redd.it` link format for anonymous users

Reddit apparently (as of writing; who knows what'll happen in a month or a year) uses a different submission-page layout for anonymous page viewers—neither the classic "old" design nor the oft-maligned redesign they've been working on for the last 5+ years, though the browse views (frontpage, subreddits, etc.) still use the redesign for anon clients.

This logged-out layout comes with alternate clickthrough image URLs for Reddit-hosted images, of the format:
https://i.redd.it/post-slug-with-hyphens-instead-of-underscores-v0-imageID.jpg?s=hexadecimalsignature

Linking one of these images (e.g. https://i.redd.it/my-neighbor-keeps-parking-in-front-of-my-garage-v0-u41q9gy0f5ya1.jpg?s=a902227dd3ec0952a91d214a2d4c086cd283319f) in view of the reddit plugin will (silently) fail to fetch the source post, because the current pattern captures more than just the image ID in the image group:

image_url = r'https?://(?P<subdomain>i|preview)\.redd\.it/(?P<image>[^?\s]+)'

Presumably the v0 element could be nonzero; maybe they are working on letting people edit/replace images uploaded directly.

While preview.redd.it links from galleries are also affected by this (the s param is added to the other format, resolution, etc. GET args), looking up the source gallery based on the URL of one image from it isn't currently supported, so that isn't (yet) an issue in itself.

Consider `new` subdomain handling

If someone who's opted out of the redesign needs to force it for some reason, they can use new.reddit.com to bypass the account preference that makes www.reddit.com use the old site.

Surely the percentage of cases where this would help is vanishingly small, but I very occasionally have to do this since enabling the "use old reddit" preference on my own account, and if the plugin can catch links that are copied under such circumstances, that's probably a good thing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.