A bot framework for Reddit to manage threads, wiki pages, widgets, menus and more.

Overview

Sub Manager

PyPI Python version Framework Tests Pytest Pre-Commit Code style wemake Code style Black

License Maintainer PyPI status GitHub version PyPI version PyPI wheel Subreddit subscribers

Tests status Lint status Mega-Linter Semgrep scan CodeQL analysis Checked with MyPy Awesome badges

Sub Manager is a bot framework for Reddit to automate a variety of tasks on one or more subreddits, and can be configured and run without writing any code. Its initial application was to automatically generate, create, pin and update threads, as well as related tasks. Additionally, it can be used to automatically sync and reformat content between wiki pages, widgets and threads, as well as marked sections of the same (including the sub's sidebar and other content). It includes support for automatically installing a Systemd service unit for real-time operation on modern Linux distributions, which is used in production for the r/SpaceX subreddit, and it can also be run by any other means you choose on your system.

Legal Disclaimer: For the avoidance of doubt, Sub Manager and the r/SpaceX Github org and subreddit are unofficial fan creations, and have no affiliation with nor endorsement by Reddit or SpaceX, which are trademarks of their respective companies.

Installation

Note: You may need to substitute python3 for python in the commands below on some Linux distros where python isn't mapped to python3 (yet).

Create and activate fresh virtual environment

While Sub Manager can be installed in your system Python, we highly recommend you create and activate a virtual environment to avoid any conflicts with other packages on your system or causing any other issues. Using the standard tool venv, you can create an environment as follows:

python -m venv your-env-name

You can then activate it with the following on Linux and macOS,

source your-env-name/bin/activate

or on Windows (cmd),

.\your-env-name\Scripts\activate.bat

Of course, you're free to use any environment management tool of your choice (conda, virtualenvwrapper, pyenv, etc); these steps are just an example.

Download and install

To download and install the package from the Python Package Index (PyPI), simply activate your environment and run

python -m pip install submanager

Alternatively, if you want to use the exact pinned dependencies we do, you can clone this repo and install from the requirements.txt file:

git clone https://github.com/r-spacex/submanager.git
cd submanager
python -m pip install -r requirements.txt
python -m pip install .

Usage

To use Sub Manager, you'll need to activate the appropriate environment you created previously, and then execute its main entrypoint. For example, with venv under bash,

source your-env-name/bin/activate
submanager <command>

To see the various commands and options available, pass it the --help flag.

Contributing

For information on how to contribute to Sub Manager, including reporting issues, setting up a development environment and contributing code, see the Contributing Guide.

Configuration

First, you'll want to generate the primary Sub Manager user config file, in order to tell it what you want it to do. To do so, simply run submanager generate-config to generate it at the default path, and a stock config file with some starting examples will be output (formatted as TOML for humans). The static config file, which stores user configuration as human-friendly TOML, is located in the submanager subdirectory OS-appropriate user config directory, and the dynamic config file, which stores persistent internal state (e.g. current threads being managed) as machine-friendly JSON, is located in submanager subdirectory OS-appropriate user state directory. To view the full paths to and status of these files on your system, simply run submanager get-config-info. You can specify an alternate config file for one or both with the respective --config-path and --dynamic-config-path options, allowing you to run multiple instances of the bot simultaneously on the same machine (for example, to avoid cramming everything into one big configuration file, or use multiple cores).

To improve robustness and enforce safe maintenance practices, Sub Manager must now be stopped and restarted to read-in updated config. Individual modules, such as sync_manager and thread_manager, can be enabled and disabled via their corresponding enabled options, and can be further configured as described below. To perform a variety of checks that your configuration is valid and will result in a successful run, without actually executing any state-changing Reddit actions, run submanager validate-config; if an error occurs, informative output will explain the problem and, often, how to fix it.

Configuring credentials

Starting with Sub Manager v0.5.0 and later, the Reddit account to use for a given action can be specified per module (sync_manager, thread_manager), per task (sync item, thread) and even per source and target, as well as globally. You'll need to configure and register the account(s) involved for Reddit app access with the Reddit API. We recommend you configure your credentials in praw.ini and simply refer to them via the PRAW site_name argument in the config subtable of the respective account listed under the accounts table, which will avoid any secrets leaking if you accidentally or deliberately store your config.toml somewhere public. However, if you prefer, the various arguments that praw.Reddit() can accept, e.g. username, password, client id, client secret, refresh token etc) can be also all be included as subkeys under the config subtable of the named account in the accounts table. Sub Manager v0.5.0 supported the new token manager refresh token handling Reddit announced in early 2021, while v0.6.0 dropped that support along with PRAW due to Reddit reverting that change. While this occurred before to the first wide public release of Sub Manager (v0.6.0), this change is nevertheless transparent to users, as Sub Manager handles this for you.

Posting intervals

If posting new threads is enabled for a configured thread item, it can be set to either post daily, monthly, yearly etc. as soon as the period ticks over (e.g. first of the month), or at an interval of every N periods after the previous thread was posted.

new_thread_interval is specified as a string, either in the form "UNIT" (e.g. "daily", "month", etc) to trigger the first behavior, or "N UNIT" (e.g. "10 weeks", "1 year", etc) to invoke the second, where N is a positive integer and UNIT is a supported period unit. Supported period units for both include years, months, days, hours, minutes and seconds; weeks are currently supported for the latter, but not the former (since there is no unambiguously agreed-upon, locale-independent start of a week, and they don't divide evenly into months or years). For either form, the units can be given with or without s or ly as suffices.

There's currently a minor limitation with this as currently implemented: getting it to create a new thread "on-demand" rather than on a schedule (or not at all) is not completely obvious. There is a relatively simple workaround, however—just set the new_thread_interval to false, and then whenever you want a new thread, set it to e.g. 1 day, wait repeat_interval_s seconds for it to create the new thread (or manually restart it, if you're impatient), and then set it back to false.

We will soon add a proper feature for this, likely in the form of a new CLI command, e.g. submanager create-thread <thread_name>, to programmatically tell the running Sub Manager instance to create a new post on-demand.

Syncing sections

The patterns of text specified in source and targets are searched for in pseudo-Markdown "comments", i.e. empty links that don't appear in the rendered text, like so:

[](#/ <PATTERN><PATTERN_START>)

Example section content

[](#/ <PATTERN><PATTERN_END>)

This allows easily syncing just specific sections between sources and targets.

If any variable (e.g. pattern) is not specified for a target, the value is recursively inherited from the respective defaults table in the sync pair, and then sync config section, including the context sub-table in each as well as the default_context in the config. Conversely, any replace_patterns for a specific target are applied after (and in addition) to those specified in source for all targets; note the source section is not actually modified unless it is specified as a target.

Running as a service

To install a Systemd user service that will run Sub Manager automatically, activate your Sub Manager environment and simply run the submanager install-service command. By default, this will install a user-level service named submanager.service which will run Sub Manager with the primary configuration. If you'd like to install another service with a different config, specify the config file path as usual with --config-path, and (if you don't want the service to overwrite the default one, so you can run as many as you want at once), a custom suffix; the resulting service will be named submanager-<suffix>.service.

The installed service can be enabled and started in the typical way,

systemctl --user daemon-reload
systemctl --user enable submanager
systemctl --user start submanager

and you can check its status and log, respectively, with the usual

systemctl --user status submanager
journalctl --user -xe -u submanager

Note that there are a few considerations to keep in mind when running as a user instance of Systemd, most notably to get it to autostart on boot rather than login and persist after the user is logged out (e.g. on a server, VPS or other unattended box).

Comments
  • Complete final pre-release prep

    Complete final pre-release prep

    • [x] Update Readme badges and add PyPI
    • [x] Resolve issues running online workflows from forks
    • [ ] Update release instructions
    • [ ] Run pre-commit autoupdate
    • [ ] Pip compile dependencies into requirements.txt
    opened by CAM-Gerlach 2
  • Release Sub Manager version 0.6.0

    Release Sub Manager version 0.6.0

    • [x] Complete preliminaries
    • [x] Update pinned deps
    • [x] Update pre-commit hooks
    • [x] Build and test on RPi
    • [x] Transition new version to production on RPi
    • [x] Update documentation and finish release PR
    • [x] Rebuild and upload to PyPI on RPi
    • [x] Re-install production release on Pi
    • [x] Finalize release
    • [x] Cleanup on the RPi
    • [x] Cleanup locally
    • [x] Announce on Slack, etc.
    opened by CAM-Gerlach 1
  • Fix unimport linter repo URL.

    Fix unimport linter repo URL.

    Thank you for using Unimport, there was a slight change in the URL, the old URL works because it is redirected to the new one, but I changed it to the new one just in case.

    opened by hakancelikdev 0
  • Execute pre-release cleanup and preparation for CIs and ancillaries

    Execute pre-release cleanup and preparation for CIs and ancillaries

    A number of pre-release tasks:

    • [x] Split CI into lint and test workflows
    • [x] Add security policy
    • [x] Adopt Keep a Changelog format
    • [x] Add README badges
    opened by CAM-Gerlach 0
  • Add semgrep workflow to CI pipeline, for real this time

    Add semgrep workflow to CI pipeline, for real this time

    Semgrep didn't actually run over the whole repo in the previous are, so the outstanding issues went unreported, per returntocorp/semgrep-action#352 . This PR is a redo of #3 to commit both adding semgrep and fixing its issues in one clean, passing-build, atomic commit.

    opened by CAM-Gerlach 0
  • Update CIs following v0.6.0 release and test changes in new Mega-Linter preview release

    Update CIs following v0.6.0 release and test changes in new Mega-Linter preview release

    • [x] Remove link check disables for PyPI links that didn't work yet
    • [x] Re-enable Bandit and Black on Mega-Linter following fixing blocking Mega-Linter issues with those linters
    • [ ] Bump pre-commit and dep versions
    • [ ] Port improvements from spyder-docs
    • [ ] Add support for Python 3.10 to matrix and setup.cfg
    • [ ] Consider re-basing to 0.6.x?
    • [ ] (Fixup to switch back to production Mega-Linter once CIs pass and the new build is live)

    Mega linter blocking issues reference: Bandit nvuillam/mega-linter#679 and Black nvuillam/mega-linter#681 , both in nvuillam/mega-linter#682

    Task 
    opened by CAM-Gerlach 2
Releases(v0.6.0)
  • v0.6.0(Aug 25, 2021)

    Major release of Sub Manager, with a complete rewrite and numerous new features, enhancements and fixes.

    Added

    • Full command-based CLI with many more options, including separate start and run commands
    • Command get-config-info to print information about the config and list endpoints
    • Command install-service to automatically install a systemd service to run the bot
    • Command generate-config to generate a user config file with example defaults
    • Command validate-config to validate the current config file, offline or online
    • Command cycle-threads to post new versions of the indicated threads
    • --debug flag, to control whether user-friendly error messages or full tracebacks are printed
    • Config option approve_new to control if new posted threads are automatically approved (default)
    • "auto" option for pin_mode (default) will unpin the old thread and pin the new if currently pinned
    • truncate_lines option for source and target endpoints, to truncate to a specified number of lines
    • More fillable/replaceable variables in thread titles
    • Comprehensive offline and online functional tests exercising the options of every supported command
    • Exhaustive suite of pre-commit checks to validate correctness, best-practices, conventions and style
    • Tests, linting and analysis all run across a matrix of platforms/versions in CIs via Github Actions

    Changed

    • Reorganize much of user and dynamic config for consistency and future extensibility
    • Use Platformdirs to install config and state files into platform-appropriate locations
    • Validate config and resync all sources for the first run, to handle any config changes
    • Use Pydantic for config, allowing robust access and user-friendly validation
    • Vastly improved error handing of almost all areas, with much more helpful, user friendly messages
    • Safety run multiple instances via locking, to enable new commands and avoid strange bugs
    • Enable thread redirect in OP and sticky by default (configurable)
    • Inject start and end comments into thread targets, to allow easily adding extra content
    • Formally rename everything to Sub Manager, with consistent naming everywhere
    • Refactor from a monolithic script into a modular package, greatly improving organization
    • Make a Python package for installing from Github or from PyPI and add lint and test extras
    • Package is now fully statically typed, improving correctness, robustness and documentation
    • Add/greatly improve docs including Readme, Contributing Guide, security policy and more
    • Auto-generate pinned requirements files for reproducible dev and production installation

    Fixed

    • Issues with hierarchical config defaults not getting inherited correctly
    • Not syncing new targets until a change is made in the source
    • Not injecting appropriate line breaks in targets for some sources, causing formatting issues
    • Many other edge-case bugs and issues

    Removed

    • Config file no longer generated automatically if its not present, use generate-config instead
    • Drop previous support for token managers, in line with Reddit and PRAW changes
    Source code(tar.gz)
    Source code(zip)
Owner
r/SpaceX
A central location for information and collaboration on all of the awesome projects coming out of r/SpaceX
r/SpaceX
This is a cryptocurrency trading bot that analyses Reddit sentiment and places trades on Binance based on reddit post and comment sentiment. If you like this project please consider donating via brave. Thanks.

This is a cryptocurrency trading bot that analyses Reddit sentiment and places trades on Binance based on reddit post and comment sentiment. The bot f

Andrei 157 Dec 15, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
Discord bot for the IOTA Wiki

IOTA Wiki Bot Discord bot for the IOTA Wiki Report Bug · Request Feature About The Project This is a Discord bot for the IOTA Wiki. It's currently use

IOTA Community 2 Nov 14, 2021
A mass creator for Discord's new channel threads.

discord-thread-flooder A mass creator for Discord's new channel threads. (obv created by https://github.com/imvast) Warning: this may lag ur pc if u h

Vast 6 Nov 4, 2022
Unofficial Meteor Client wiki

Welcome to the Unofficial Meteor Client wiki! Meteor FAQs | A rewritten and better FAQ page. Installation Guide | A guide on how to install Meteor Cli

Anti Cope 0 Feb 21, 2022
Twitter bot that turns comment chains into ace attorney scenes. Inspired by and using https://github.com/micah5/ace-attorney-reddit-bot

Ace Attorney twitter Bot Twitter bot that turns comment chains into ace attorney scenes. Inspired by and using https://github.com/micah5/ace-attorney-

Luis Mayo Valbuena 542 Dec 17, 2022
Automate TikTok follower bot, like bot, share bot, view bot and more using selenium

Zefoy TikTok Automator Automate TikTok follower bot, like bot, share bot, view bot and more using selenium. Click here to report bugs. Usage Download

null 555 Dec 30, 2022
A small bot to interact with the reddit API. Get top viewers and update the sidebar widget.

LiveStream_Reddit_Bot Get top twitch and facebook stream viewers for a game and update the sidebar widget and old reddit sidebar to show your communit

Tristan Wise 1 Nov 21, 2021
Telegram bot to scrape images from the reddit universe

Telegram bot to scrape images from the reddit universe

XD22 3 Sep 30, 2022
Reddit bot that uses sentiment analysis

Reddit Bot Project 2: Neural Network Boogaloo Reddit bot that uses sentiment analysis from NLTK.VADER WIP_WIP_WIP_WIP_WIP_WIP Link to test subreddit:

TpK 1 Oct 24, 2021
Reddit comment bot emulating Telugu actor N. Bala Krishna.

Balayya-Bot Reddit comment bot emulating Telugu actor N. Bala Krishna. Project structure config.py contains Bot's higher level configuration. generate

Kari Lorince 2 Nov 5, 2021
Simple Reddit bot that replies to comments containing a certain word.

reddit-replier-bot Small comment reply bot based on PRAW. This script will scan the comments of a subreddit as they come in and look for a trigger wor

Kefendy 0 Jun 4, 2022
Reddit bot for r/khiphop

khiphop-bot Description This project is a collection of scripts that better the state of the r/khiphop subreddit, which represents Korean Hip-Hop and

null 1 Dec 21, 2021
A telegram bot that sends a meme a day, from reddit's top meme of the day

MemeBot A telegram bot that sends a meme a day, from reddit's top meme of the day You can use the bot either with an external scheduler (ex: pythonany

Michele Vitulli 1 Dec 13, 2021
A reddit.com bot that will return reference links from official python documentation site for the standard library.

Python Docs Bot A reddit.com bot that will return documentation links for the library and language reference sections of the python docs website. The

Trevor Miller 2 Sep 14, 2021
A Python bot that uses the Reddit API to send users inspiring messages.

AnonBot By Edric Antoine A Python bot that uses the Reddit API to send users inspiring messages. When a message includes 'What would Anon do?', the bo

null 1 Jan 5, 2022
Bot that embeds a random hysterical meme from Reddit into your text channel as an embedded message, using an API call.

Discord_Meme_Bot ?? Bot that embeds a random hysterical meme from Reddit into your text channel as an embedded message, using an API call. Add the bot

null 2 Jan 16, 2022
Simple bot to receive feedback,same as livegram bot but with more features & full control over bot

Kontak Simple bot to receive feedback,same as livegram bot but with more features & full control over bot Deploy to VPS

Mahin Ahmed 2 Dec 16, 2021